Yaskawa MP920 Communications Module User Manual

Page 289

Advertising
background image

C.2 Sample Programs for Slave Station

C-13

C

//Sets the serial number.
sbuf[1] = rbuf[1];

// Send a received data.

// Sets the destination channel number.
sbuf[2] = rbuf[3];

// Sets the PLC source channel number.

// Sets the source channel number.
sbuf[3] = 0x00;

// Fixed to 0 since a personal computer has no channel number.

sbuf[4] = 0x00;

// Reserved

sbuf[5] = 0x00;

// Reserved

// Sets all the number of data items (from the start of 218 header to the end of MEMOBUS data).
sbuf[6] = (char)((12 + 2 + memex_len) & 0x00FF);
//L (218 header (12 bytes) + MEMOBUS header length (2 bytes) + Extended MEMOBUS length

//(memex_len bytes)

sbuf[7] = (char)(((12 + 2 + memex_len) >> 8) & 0x00FF); // H

sbuf[8] = 0x00;

// Reserved

sbuf[9] = 0x00;

// Reserved

sbuf[10] = 0x00;// Reserved
sbuf[11] = 0x00;// Reserved

// Sets the send data length (218 header + Extended MEMOBUS data).
*slen = (int)(memex_len + 12 + 2);

}

/*****************************************************/
/* Extended MEMOBUS Command Check

*/

/* Checks the header of the received data.

*/

/*****************************************************/
int chk_cmd_data( int rlen )
{

int rc;
unsigned shortdata_len, memex_len;

rc = 0;

// Total data length
data_len = (unsigned short)((unsigned char)rbuf[7]) << 8;
data_len += (unsigned short)((unsigned char)rbuf[6]);

// Checks the total data length.
if ( rlen != (int)data_len )
{

rc = -1;
return( rc );

}

// Checks the packet type.
if ( rbuf[0] != 0x11 )// Commands other than MEMOBUS commands are not accepted.
{

rc = -2;
return( rc );

}

Advertising