App - 11 App - 11
MELSEC-F
APPENDIX
Closeflag=FLAG_ON;
// Connection completion flag ON
// Go to non-blocking mode
ulCmdArg = 1;
ioctlsocket(socketno, FIONBIO, &ulCmdArg);
// Set to non-blocking mode
strcpy(s_buf, "03FF000A4420000000000500112233445566778899AA");
// D0 to D4 batch write request (1E frame)
length=(int)strlen(s_buf);
if(send(socketno,s_buf,length,0)==SOCKET_ERROR){
// Data sending
Sockerror(ERROR_SEND);
// Error handling
return
(SOCK_NG);
}
printf("\n send data\n%s\n",s_buf);
// Perform receiving size check and receiving processing simultaneously
rbuf_idx = 0; // Receive data storage head index initialization
recv_size = 0; // Initialize the number of receive data
while(1)
{
length = recv(socketno, &r_buf[rbuf_idx], (BUF_SIZE - rbuf_idx), 0);
// Response data receiving
if(length == 0) {
// Is connection cut off?
Sockerror(ERROR_RECIEVE);
// Error handling
return
(SOCK_NG);
}
if(length == SOCKET_ERROR) {
nErrorStatus
=
WSAGetLastError();
if(nErrorStatus != WSAEWOULDBLOCK) {
Sockerror(ERROR_RECIEVE);
// Error handling
return
(SOCK_NG);
} else {
continue;
// Repeat until messages are received
}
} else {
rb= length;
// Update the receive data storage
//
position
rec= length;
// Update the number of receive data
if(recv_size >= RECV_ANS_1)
// Have all response messages been
//
received?
break;
// Stop repeating as messages have
// been received
}
}
r_buf[rbuf_idx] = '\0' ;
// Set NULL at the end of receive data
printf("\n
receive
data\n%s\n",r_buf);
strcpy(s_buf, "01FF000A4420000000000500");
// D0 to D4 batch read request
// (1E frame)
length=(int)strlen(s_buf);
if(send(socketno,s_buf,length,0)==SOCKET_ERROR){
// Data sending
Sockerror(ERROR_SEND);
// Error handling
return
(SOCK_NG);
}
printf("\n send data\n%s\n",s_buf);
// Perform receiving size check and receiving processing simultaneously
rbuf_idx = 0;
// Receive data storage head index
//
initialization
recv_size = 0;
// Initialize the number of receive data
Содержание FX3U-ENET
Страница 1: ...USER S MANUAL FX3U ENET ...
Страница 2: ......
Страница 159: ...8 6 8 6 MELSEC F 8 COMMUNICATION USING MC PROTOCOL MEMO ...
Страница 295: ...App 25 App 25 MELSEC F APPENDIX MEMO ...
Страница 297: ......