So here's the thing I have this program that does stuff for CAN, now the CAN messages are being sent to the end Application via the Serial Port, sometimes however it gets stuck when trying to detect the Com Port.
The application operates as follows, First Detect the Com Port( this is where it gets stuck ), then do the actual connection and the process the Data.
To solve the problem, I usually have to pull out the usb to serial cable then restart the App, this is not ideal as this software is going Live soon.
One of the reasons it could be going haywire is that the CAN codes are being blasted into the serial port (This cannot be Stopped). Is it for that brief moment that the serial port is open for, the data cannot be processed and it just freezes, do I need to delay a bit or discard data??
So here's the code :
for (int COM_Attempt = 1; COM_Attempt <= 50; COM_Attempt++)
{
string str_COM_Attempt = Convert.ToString(COM_Attempt);
SP.PortName = "COM" + str_COM_Attempt;
SP.BaudRate = 9600;
try
{
SP.Open();
SP.Close();
PortList.Items.Add("COM" + str_COM_Attempt);
}
catch
{
}
}
PortList.Text = PortList.Items[0].ToString();
}