J
jayderk
Hello All,
I am trying to get this function to work correctly and can not seem to do
so.
basically this function searches the port.input for a time of
"secondsToSearch" for a message that starts with "message".
you can see that I don't even bother searching until the length of data in
the buffer is greater then what I am searching for.
can you see any problems with this?
private bool searchRxForMessage(string message, int secondsToSearch)
{
Library.CfDebugger.WriteDebugLine("search for:" + message);
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;
txtTx.Text = "Start loop";
//this.refresh();
while( (((TimeSpan)(finish - current)).TotalSeconds >= 0) )
{
Library.CfDebugger.WriteDebugLine("input buffer:" +
port.InputLen.ToString());
if(port.InputLen >= message.Length)
{
string stringToSearch =
Encoding.ASCII.GetString(port.Input,0,port.InputLen);
Library.CfDebugger.WriteDebugLine(stringToSearch);
if(stringToSearch.StartsWith(message))
return true;
}
current = DateTime.Now;
}
txtTx.Text = " stop loop";
//this.refresh();
Library.CfDebugger.WriteDebugLine("didn't find it");
return false;
}
I am trying to get this function to work correctly and can not seem to do
so.
basically this function searches the port.input for a time of
"secondsToSearch" for a message that starts with "message".
you can see that I don't even bother searching until the length of data in
the buffer is greater then what I am searching for.
can you see any problems with this?
private bool searchRxForMessage(string message, int secondsToSearch)
{
Library.CfDebugger.WriteDebugLine("search for:" + message);
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;
txtTx.Text = "Start loop";
//this.refresh();
while( (((TimeSpan)(finish - current)).TotalSeconds >= 0) )
{
Library.CfDebugger.WriteDebugLine("input buffer:" +
port.InputLen.ToString());
if(port.InputLen >= message.Length)
{
string stringToSearch =
Encoding.ASCII.GetString(port.Input,0,port.InputLen);
Library.CfDebugger.WriteDebugLine(stringToSearch);
if(stringToSearch.StartsWith(message))
return true;
}
current = DateTime.Now;
}
txtTx.Text = " stop loop";
//this.refresh();
Library.CfDebugger.WriteDebugLine("didn't find it");
return false;
}