J
jayderk
I am writing an application that communicates over COM0: with the openCFNet
Serial.IO class. my problem is I do not know how best to go about collecting
the data that comes in from the port not knowing exactly how many bytes are
coming in ( if I knew that I would just set the threashhold to that
amount ). My first best guess is not working out so well. I am using a data
received function like so.
private void port_DataReceived()
{
byte[] data = port.Input;
this.RxMESSAGE += Encoding.ASCII.GetString(data,0,data.Length);
}
and I have another function that cycles a certain period of time searching
RxMESSAGE for data comming in as so.
private bool searchRxForMessage(string message, int secondsToSearch)
{
DateTime finish = new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,DateTime.Now.
Hour,DateTime.Now.Minute,DateTime.Now.Second + secondsToSearch);
DateTime current = DateTime.Now;
while( (((TimeSpan)(finish - current)).TotalSeconds >= 0) )
{
if(this.RxMESSAGE.Length >= message.Length)
{
if(this.RxMESSAGE.IndexOf(message) > 0)
return true;
}
current = DateTime.Now;
}
return false;
}
I have port.RThreashhold = 1 so every byte that comes in is added to
RxMESSAGE.
to me it seems like it is not behaving correctly because I am in a while
loop on the same form that is running the port_DataReceived delagate?
Serial.IO class. my problem is I do not know how best to go about collecting
the data that comes in from the port not knowing exactly how many bytes are
coming in ( if I knew that I would just set the threashhold to that
amount ). My first best guess is not working out so well. I am using a data
received function like so.
private void port_DataReceived()
{
byte[] data = port.Input;
this.RxMESSAGE += Encoding.ASCII.GetString(data,0,data.Length);
}
and I have another function that cycles a certain period of time searching
RxMESSAGE for data comming in as so.
private bool searchRxForMessage(string message, int secondsToSearch)
{
DateTime finish = new
DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,DateTime.Now.
Hour,DateTime.Now.Minute,DateTime.Now.Second + secondsToSearch);
DateTime current = DateTime.Now;
while( (((TimeSpan)(finish - current)).TotalSeconds >= 0) )
{
if(this.RxMESSAGE.Length >= message.Length)
{
if(this.RxMESSAGE.IndexOf(message) > 0)
return true;
}
current = DateTime.Now;
}
return false;
}
I have port.RThreashhold = 1 so every byte that comes in is added to
RxMESSAGE.
to me it seems like it is not behaving correctly because I am in a while
loop on the same form that is running the port_DataReceived delagate?