The requirement is to constantly read data from the hardware and send data to the upper layers for further processing.
I am currently using a synchronous mechanism. those. Request → Wait → Read ---> Send for processing.
do
{
int ix = iy;
iy = 0;
if(ix<1)
{
while (((ix = ReadSst(ref sBuffer)) < 1) && bProcessNotEnded == true)
{
if (ix < 0)
{
eErr = CError.BUFF_KILL;
break;
}
Thread.Sleep(2);
iTimeOut += 2;
if (iTimeOut > TIMEOUT_2000)
{
eErr = CError.TIMEOUT_ERR;
objLogger.WriteLine("HW TIMED OUT");
break;
}
}
}
iBytesRead = ix;
if (iBytesRead <= 0)
{
eErr = CError.READ_ERR;
objLogger.WriteLine("READ ERROR");
break;
}
sReadMsg = sReadMsg + sBuffer;
if(sReadMsg.Length >0)
iEndPos = sReadMsg.IndexOf('\n',1);
else
iEndPos = -1;
if (sReadMsg.Length > 2)
{
if ((iEndPos == 0 && sReadMsg[0] == '\n') || (iEndPos > 0 && sReadMsg[sReadMsg.Length - 1] == '\n' && sReadMsg[sReadMsg.Length - 2] == '\r'))
{
Thread.Sleep(50);
if (sReadMsg.Length >= 3 && sReadMsg[sReadMsg.Length - 3] == 'a')
continue;
iy = ReadSst(ref sBuffer);
if (iy == 0)
{
bProcessNotEnded = false;
objLogger.WriteLine("bProcessNotEnded is made false, End of frame detected");
break;
}
else if (iy < 0)
{
eErr = CError.BUFF_KILL;
break;
}
}
}
} while (bProcessNotEnded);
The ReadSst method is a call made by hardware to request data.
As you can see from the code, the true logic of the loop is and is read until the bProcessNotEnded flag is true. As soon as the end of the frame is detected in the line buffer that I get, I set the flag to false and the loop stops (just like reading from hardware).
, parallelism , , , .
-, .