Hi All,
I am using C# to read from a USB comm port emulation, Most of the time it reads fine, using the below interrupt handler
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Reply_Status = (int)REPLY.YES_REPLY;
Pause.Stop();
//add try catch
try
{
InputData = myComPort.ReadExisting();
if (InputData != String.Empty)
{
this.BeginInvoke(new SetTextCallback(SetText), new object[] { InputData });
}
else if (InputData == String.Empty)
{
return;
}
}
catch(UnauthorizedAccessException ex)
{
MessageBox.Show("Error Caught!! "+ex.ToString());
}
}
But I have noticed in testing that some times this method doesn't always work some times the data is short (missing a few characters) and some times a stray character causes a blank line in the data (which the get caught by the save routine as the end of file). Is ReadExisting() reliable or would another method be better such as
InputData = ReadTo(">")?
-=-=-=-
UpDate
=-=-=-=
InputData = ReadTo(">")? seems to be causing alot of problems anyone recommend a better one Read method? As ReadExisting() appears to occasionally throw an exception that can't be caught....
Glenn