YASKAWA MP920 User Manual page 286

Machine controller
Table of Contents

Advertisement

exit(0);
}
// Prepares the response data.
mk_rsp_data( &send_len );
// Sends the response data.
// This processing will not end if the Slave cannot send the response data.
slen = send( new_sd, &sbuf[0], send_len, 0 );
if ( slen != send_len )// The number of bytes that was sent will be returned if the sending process is successful.
{
closesocket(new_sd);
printf( "Error: Send !! -> %d\n", slen );
exit(0);
}
printf( "Hit Any Key !!\n" );
}
}
/***********************************************************************************/
/* Preparation of extended MEMOBUS response data
/*
/* An appropriate response for the function code (SFC=03, 06, 08, 09, 0B, or 10) of extended
/* MEMOBUS protocol will be returned. In this sample program, an error response will be
/* returned for other function codes as they are not supported.
/* A dummy data will be prepared and returned for Read command.
/************************************************************************************/
void mk_rsp_data( int *slen )
{
int
i;
unsigned shortdata_size, memex_len;
/****************************************/
/* Preparation of Extended MEMOBUS Data
/**************************************/
// MFC
sbuf[14] = 0x20;
// SFC
sbuf[15] = rbuf[15];
// Set the CPU numbers.
sbuf[16] = (rbuf[16] << 4) & 0xF0;    // The destination is the source CPU. Local CPU No.: 0
// Processing for each function code
switch( rbuf[15] )
{
case
0x03: // Read Holding Register Contents
data_size = (unsigned short)((unsigned char)rbuf[19]) << 8;
data_size += (unsigned short)((unsigned char)rbuf[20]);
data_size *= 2;// Read data size in bytes
memex_len = data_size + 3;        // Extended MEMOBUS length for response
// data size + 3byte(MFC,SFC,CPU NO)
// Prepares a dummy data.
// Converts then sends the requested word unit data into byte units.
for( i = 0; i < data_size; i++ )
{
}
break;
*/
// Fixed to 20H
//Send a received data.
sbuf[17 + i] = i;// Sets data read from sbuf[17].
C-11
C.2 Sample Programs for Slave Station
*/
*/
*/
*/
*/
*/
C

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents