YASKAWA MP920 User Manual page 287

Machine controller
Table of Contents

Advertisement

Appendix C C Language Sample Programs
C.2.1 TCP (When Using Extended MEMOBUS Protocol)
    
}
// Length: From MFC to the end of data
sbuf[12] = (char)(memex_len & 0x00FF); // Extended MEMOBUS length L
sbuf[13] = (char)((memex_len >> 8) & 0x00FF); // Extended MEMOBUS length H
/****************************/
/* Preparation of 218 Header
/**************************/
// Sets the data type.
sbuf[0] = 0x19;
case
0x06: //Modify a Single Holding Register Contents
case
0x08: // Loopback Test
memex_len = 7;// Extended MEMOBUS Length for Response
sbuf[17] = rbuf[17];// Send a received data.
sbuf[18] = rbuf[18];// Send a received data.
sbuf[19] = rbuf[19];// Send a received data.
sbuf[20] = rbuf[20];// Send a received data.
break;
case
0x09: // Read Holding Register Contents (extended)
data_size = (unsigned short)((unsigned char)rbuf[21]) << 8;
data_size += (unsigned short)((unsigned char)rbuf[20]);
data_size *= 2;// Read data size in bytes
memex_len = data_size + 6;// Extended MEMOBUS Length for Response
// data size + 6 bytes (MFC, SFC, CPU No, SPEAR, REG No)
sbuf[17] = 0x00;
// Spare is fixed to 0.
// Sets the number of registers.
sbuf[18] = rbuf[20];
sbuf[19] = rbuf[21];
// Prepares a dummy data.
// Converts then sends the requested word unit data into byte units.
for( i = 0; i < (data_size / 2); i++ )
{
sbuf[20 + 2 * i] = i;    // Set data read from sbuf[20].
}
break;
case
0x0B: // Write to Holding Register (extended)
memex_len = 8;// Extended MEMOBUS Length for Response
sbuf[17] = 0x00;
// Spare is fixed to 0.
sbuf[18] = rbuf[18];// Send a received data.
sbuf[19] = rbuf[19];// Send a received data.
sbuf[20] = rbuf[20];// Send a received data.
sbuf[21] = rbuf[21];// Send a received data.
break;
case
0x10: // Write to Holding Register (extended)
memex_len = 7;// Extended MEMOBUS Length for Response
sbuf[17] = rbuf[17];// Send a received data.
sbuf[18] = rbuf[18];// Send a received data.
sbuf[19] = rbuf[19];// Send a received data.
sbuf[20] = rbuf[20];// Send a received data.
break;
default:// In this sample program, function code other than the above listed are judged
// as not supported codes and an error response will be returned.
memex_len = 4;// Extended MEMOBUS Length for Response
sbuf[15] |= 0x80;// Error response (SFC + 80H)
sbuf[17] = 0x01;// Error response (SFC error)
*/
// Extended MEMOBUS (Response)
// DataNum(L)
// DataNum(H)
C-12

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents