2.13 Communications with a Windows PC (Visual C++ Application)
Using Automatic Reception with the MP3000 as a Slave
2-354
// Set the total number of data items from the start of the 218 header to the end of MEMOBUS data
sbuf[6] = (unsigned char)(DATAi & 0x00FF); // Data length (L)
sbuf[7] = (unsigned char)((DATAi & 0xFF00) >> 8); // Data length (H)
sbuf[8] = 0x00; // Reserved.
sbuf[9] = 0x00; // Reserved.
sbuf[10] = 0x00; // Reserved.
sbuf[11] = 0x00; // Reserved.
// Create the MEMOBUS data part
// Length from MFC to end of data
sbuf[12] = (unsigned char)(MDATAi & 0x00FF); // MEMOBUS data length (L)
sbuf[13] = (unsigned char)((MDATAi & 0xFF00) >> 8); // MEMOBUS data length (H)
// MFC is always 20 hex
sbuf[14] = 0x20;
// SFC
sbuf[15] = SFC;
// Set the CPU number
sbuf[16] = (unsigned char)(CPUNum << 4); // The local CPU number is always 0 hex
sbuf[17] = 0x00; // The spare is always 0 hex
// Set the reference number
sbuf[18] = (unsigned char)(Adr & 0x00FF); // Adr(L)
sbuf[19] = (unsigned char)((Adr & 0xFF00) >> 8); // Adr(H)
// Set the number of registers
sbuf[20] = (unsigned char)(DataNum & 0x00FF); // DataNum(L)
sbuf[21] = (unsigned char)((DataNum & 0xFF00) >> 8); // DataNum(H)
}
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
/
/
∗
Check response data
∗
/
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
/
int chk_rsp_data(int rlen, char
∗
sbuf, char
∗
rbuf)
{
short rcvDATAi; // Total number of data items to receive
int rc = 0;
// Check the total data length
switch ( sbuf[15] )
{
case 0x09: