YASKAWA MP920 User Manual page 279

Machine controller
Table of Contents

Advertisement

Appendix C C Language Sample Programs
C.1.1 TCP (When Using Extended MEMOBUS Protocol (SFC = 09))
}
// Prepares the extended MEMOBUS protocol command, Read Holding Register Contents (SFC = 09).
void mk_cmd_data(void)
{
closesocket(sd);
printf( "Error: Recv !! -> %d\n", rlen );
exit(0);
}
// Checks the response data.
rc = chk_rsp_data( rlen );
if ( rc != 0 )//Errors in received data
closesocket(sd);
exit(0);
}
sbuf[1] ++;// Increments the serial number of 218 header.
printf( "Hit Any Key !!\n" );
}
// Prepares the 218 header.
// Sets the data type.
sbuf[0] = 0x11;// Extended MEMOBUS (reference command)
// Sets the serial number (The serial number will be incremented every send data.)
sbuf[1] = 0x00;
// Sets the destination channel number.
sbuf[2] = 0x00; // The channel number can be fixed to 0 as the channel of PLC is not specified.
// Sets the destination channel number.
sbuf[3] = 0x00; // Always set to 0 because a personal computer has no channel number.
sbuf[4] = 0x00; // Reserved
sbuf[5] = 0x00; // Reserved
// Sets all the number of data items (from the starting of 218 header to the end of MEMOBUS data).
sbuf[6] = 0x16; // L (22 bytes = 218 header (12 bytes) + MEMOBUS data (10 bytes)
sbuf[7] = 0x00; // H
sbuf[8] = 0x00;// Reserved
sbuf[9] = 0x00;// Reserved
sbuf[10] = 0x00;// Reserved
sbuf[11] = 0x00;// Reserved
// Prepares the MEMOBUS data.
// Length: From MFC to the end of data
sbuf[12] = 0x08;
// MEMOBUS data length (L)
sbuf[13] = 0x00;
// MEMOBUS data length (H)
x
// MFC is fixed to 0
20
sbuf[14] = 0x20;
// SFC is 0x09 (Read Holding Register Contents (extended))
sbuf[15] = 0x09;
// Sets the CPU number.
sbuf[16] = 0x10;
// Remote CPU No.: CPU1. Multi CPUs: 1 - 4. Local CPU No.: always 0.
sbuf[17] = 0x00;
// Always 0 for Spare.
C-4

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents