2.13 Communications with a Windows PC (Visual C++ Application)
Using Automatic Reception with the MP3000 as a Slave
2-353
return ( rc );
}
iSerial++; // Increment the serial number of the 218 header
return ( rc );
}
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/
/∗ Create Extended MEMOBUS protocol command ∗/
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/
void mk_cmd_data( unsigned char SFC, unsigned char CPUNum,
unsigned short Adr, unsigned short DataNum, char∗ sbuf )
{
//Calculate number of data items
//MEMOBUS data length from MFC to end of data
switch(SFC)
{
case 0x09:
MDATAi = 8;
break;
default:
break;
}
//Calculate total number of data items
DATAi = MDATAi +14; //218 header (12 bytes) + Length part (2 bytes) + MEMOBUS data length
(variable)
// Create the 218 header part
// Initialize the send/receive buffers
memset( sbuf, 0x00, DATA_SIZE );
// Set the register type.
sbuf[0] = 0x11; // Extended MEMOBUS command
// Set the serial number and increment for every transmission
sbuf[1] = iSerial;
// Set the destination channel number
sbuf[2] = 0x00; // Always 0 hex because the PLC channel is undefined
// Set the source channel number
sbuf[3] = 0x00; // Always 0 hex because channel numbers do not apply to PCs
sbuf[4] = 0x00; // Reserved.
sbuf[5] = 0x00; // Reserved.