I want to do serial communication from an emulator running on the PC to a
real device connected via a serial port. I have taken the code from Jens
Kühner and finally got some response from the port.
I have extended the Emulator with the following code:
public override void SetupComponent()
{
base.SetupComponent();
ComPortToPhysicalPcSerialPort comPort = new
ComPortToPhysicalPcSerialPort();
comPort.ComPortHandle = new ComPortHandle(TransportType.Usart, 2);
comPort.Baudrate = 115200;
comPort.PhysicalPortName = "COM1";
comPort.Handshake = System.IO.Ports.Handshake.RequestToSend;
RegisterComponent(comPort);
}
Here ComPortToPhysicalSerialPort is Jens Kühner's Code.
"COM1" is the physical port of the PC.
And I need "new ComPortHandle(TransportType.Usart, 2);"
because my app uses the "COM2" port.
The code of the app is:
serialPort = new SerialPort("COM2", 115200, Parity.None);
serialPort.Handshake = Handshake.RequestToSend;
try
{
serialPort.Open();
}
catch (Exception ex)
{
Debug.Print(ex.Message);
Debug.Print(ex.StackTrace);
}
When doing this I get the following output:
Exception was thrown: System.ArgumentException
System.IO.Ports.SerialPort::HandlePinReservations
System.IO.Ports.SerialPort::Open
But I don't find anything about HandlePinReservations.
And it doesn't seem to be a problem of the app as it already is running on
real hardware.
Has anyone experienced this too?
And what can I do to get more specific information about this behaviour?
And finally solve the problem?
Martin