Mitsubishi Electric FX3U-ENET-ADP User Manual page 143

Table of Contents

Advertisement

FX
-ENET-ADP User's Manual
3U
if(length == SOCKET_ERROR) {
nErrorStatus = WSAGetLastError();
if(nErrorStatus != WSAEWOULDBLOCK) {
} else {
}
} else {
rbuf_idx += length;
recv_size += length;
if(recv_size >= RECV_ANS_1)
}
}
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){
Sockerror(ERROR_SEND);
return (SOCK_NG);
}
printf("\n send data\n%s\n",s_buf);
// Perform receiving size check and receiving processing simultaneously
rbuf_idx = 0;
recv_size = 0;
while(1) {
length = recv(socketno, &r_buf[rbuf_idx], (BUF_SIZE - rbuf_idx), 0);
// Response data receiving
if(length == 0) {
Sockerror(ERROR_RECIEVE);
return (SOCK_NG);
}
if(length == SOCKET_ERROR) {
nErrorStatus = WSAGetLastError();
if(nErrorStatus != WSAEWOULDBLOCK) {
} else {
}
} else {
rbuf_idx += length;
recv_size += length;
if(recv_size >= RECV_ANS_2)
break;
}
}
r_buf[rbuf_idx] = '\0' ;
printf("\receive data\n%s\n", r_buf);
Appendix C-1 Program example for communication using MC protocol -1
Sockerror(ERROR_RECIEVE);
return (SOCK_NG);
continue;
break;
Sockerror(ERROR_RECIEVE);
return (SOCK_NG);
continue;
Appendix C: Program Examples
// Error handling
// Repeat until messages are received
// Update the receive data storage position
// Update the number of receive data
// Have all response messages been received?
// Stop repeating as messages have been received
// Data sending
// Error handling
// Receive data storage head index initialization
// Initialize the number of receive data
// Is connection cut off?
// Error handling
// Error handling
// Repeat until messages are received
// Update the receive data storage position
// Update the number of receive data
// Have all response messages been received?
// Stop repeating as messages have been received
// Set NULL at the end of receive data
B
C
D
E
137

Advertisement

Table of Contents
loading

Table of Contents