Here is the code from the dll:
public static bool SendCommand(string command)
{
KillTeraTerm();
try
{
SerialPort portToUse = new SerialPort("COM2");
portToUse.Open();
portToUse.WriteLine(command);
portToUse.Close();
StartTeraTerm();
return true;
}
catch
{
return false;
}
}
Here is the code I am using to reference the dll:
Assembly loadedDLL = Assembly.LoadFile(@"G:\PRODUCT VALIDATION GROUP\SOFTWARE VALIDATION\Ranorex Support Files\RTSInterface.dll");
Type rtsObj = loadedDLL.GetType("Oe.RTS.RTSInterface");
Object obj = Activator.CreateInstance(rtsObj);
try
{
rtsObj.InvokeMember("SendCommand", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, obj, new object[] { "startbutton" });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
I know i am not using the return value yet... just want to know why this isnt working.
EDIT!!!!
First exception: Message = "Exception has been thrown by the target of an invocation."
Inner Exception Message = "Request failed." '
DeclaringMethod = 'rtsObj.DeclaringMethod' threw an exception of type 'System.InvalidOperationException'
Thanks for your help. First time using reflection so sorry for the choppy code.
EDIT #2!!!
Stack Trace from VS: Saftey Door Simulator.exe!Safety_Door_Simulator.Form1.btnInit_Click(object sender = {Text = "Initialize"}, System.EventArgs e = {X = 56 Y = 10 Button = Left}) Line 46 C# [External Code] Saftey Door Simulator.exe!Safety_Door_Simulator.Program.Main() Line 17 + 0x1d bytes C# [External Code]
EDIT #3
Inner stack trace:
StackTrace = " at Oe.RTS.RTSInterface.KillTeraTerm()\r\n at Oe.RTS.RTSInterface.SendCommand(String command)"
Code for KillTeraTerm:
public static void KillTeraTerm()
{
if (Process.GetProcessesByName("ttermpro").Length != 0)
{
Process[] teraTermProcess = Process.GetProcessesByName("ttermpro");
foreach (Process p in teraTermProcess)
{
p.Kill();
Thread.Sleep(1000);
}
}
}