Hello and thank you for considering this issue: I send a command from a PC via a virtual serial port to the embedded system, which returns the command when the embedded system completed the command.
I can send the command in order and see an echo when the command is completed by the embedded system, but I had trouble finding a suitable way to wait or delay the program until an echo command is received so that I can continue and send the next command . I believe this is the type of "high level" flow control I'm trying to implement. The code is in C #. I would like to wait from the echo and have a timeout, in case of loss of connection between the PC and the embedded system, so that the program does not freeze. Any wizz kids that can offer a neat way to do this? I'm not a great C # programmer, just learning.
This is the receive function that I have:
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (!comport.IsOpen) return;
if (CurrentDataMode == DataMode.Text)
{
string data = comport.ReadExisting();
Log(LogMsgType.Incoming, data);
}
else
{
int bytes = comport.BytesToRead;
byte[] buffer = new byte[bytes];
comport.Read(buffer, 0, bytes);
Log(LogMsgType.Incoming, ByteArrayToHexString(buffer));
}
}
This is an example of calling the Transmitt command:
text = "AR" + 50 + "\r";
this.comport.Write(text);
[Thread.Sleep(TIMEGAP)] , , :
text = "AR" + 50 + "\r";
this.comport.Write(text);
Thread.Sleep(TIMEGAP);
[Thread.Sleep(TIMEGAP)] /, , , , , , [AR50\r ] , , 5 , .
?
!