I am using this windows library: System.IO.ports I have a class called ServerObject and it has a public member: sPort of type SerialPort.
ServerObject.sPort.PortName = "COM4";
ServerObject.sPort.BaudRate = 460800;
ServerObject.sPort.Parity = 0;
ServerObject.sPort.DataBits = 8;
ServerObject.sPort.Open();
ServerObject.sPort.DataReceived += new SerialDataReceivedEventHandler(ServerObject.sPort_DataReceived);
The above code runs once in the main. I am thinking that the last line here is the culprit.
The below code is the public method for the ServerObject class that that last line is calling.
public void sPort_DataReceived(object sender, SerialDataReceivedEventArgs e) //event for data appearing on the serial port.
{
try
{
string payload = null;
payload = sPort.ReadLine(); //extract incoming message
this.DebugMessageQueue.Enqueue(payload);
}
catch (Exception ex)
{
}
}
Whenever something gets onto that queue, it gets printed. I tested that. However, nothing is happening. Any ideas? I think that I am not understanding this event handler. Is it suppose to be in a loop? I thought that the event handler would call sPort_DataRecieved whenever data appears on the port. Does it only run once?