2.13 Communications with a Windows PC (Visual C++ Application)
Using Automatic Reception with the MP3000 as a Slave
2-355
rcvDATAi = 20 + ( (sbuf[21] << 8)
|
sbuf[20] ) ∗ 2;
if ( rlen != rcvDATAi )
{
rc = -3;
return( rc );
}
break;
default:
break;
}
// Check the packet type
if ( rbuf[0] != 0x19 ) // Not a MEMOBUS response
{
rc = -4;
return( rc );
}
// Check the serial number
if ( sbuf[1] != rbuf[1] ) // Do not match the serial number of the command
{
rc = -5;
return( rc );
}
//Check the total data length of the message
if ( (rbuf[6] != (rcvDATAi & 0x00FF)) &&
(rbuf[7] != (rcvDATAi & 0xFF00) >> 8) ) // ? bytes = 218 header (12 bytes)
{ // + MEMOBUS data (always 8 bytes + variable DataNum ∗ 2 bytes)
rc = -6;
return( rc );
}
// Check the total MEMOBUS data length
// Check the MFC
if ( rbuf[14] != 0x20 )// MFC is always 20 hex
{
rc = -7;
return( rc );
}
// Check the SFC
if ( rbuf[15] != sbuf[15] )
{
rc = -8;
return( rc );
}