Mitsubishi Electric MELSEC-L SERIES Basic User Manual page 361

Melsec-l ethernet interface module
Hide thumbs Also See for MELSEC-L SERIES:
Table of Contents

Advertisement

// Perform receiving size check and receiving processing simultaneously
rbuf_idx = 0;
recv_size = 0; // Initialize the number of receive data
while(1) {
length = recv(socketno, (char*)(&r_buf[rbuf_idx]), (BUF_SIZE - rbuf_idx), 0);
if(length == 0) {
Sockerror(ERROR_RECEIVE);
return (SOCK_NG);
}
if(length == SOCKET_ERROR) {
nErrorStatus = WSAGetLastError();
if(nErrorStatus != WSAEWOULDBLOCK) {
Sockerror(ERROR_RECEIVE);
return (SOCK_NG);
} else {
continue;
}
} 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);
if(shutdown(socketno,2)!=SOCK_OK){
Sockerror(ERROR_SHUTDOWN);
return(SOCK_NG);
}
if(closesocket(socketno)!=SOCK_OK){
Sockerror(ERROR_CLOSE);
return(SOCK_NG);
}
Closeflag=FLAG_OFF;
WSACleanup();
printf("\nAJ_test End.\n\n Normally completed. \n");
printf("Press any key to exit the program.\n");
Dmykeyin=getchar(); // Wait for key input
return(SOCK_OK);
}
// Receive data storage head index
// initialization
// Response data receiving
// 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
// Processing to disable
// sending/receiving
// Error handling
// Close processing
// Error handling
// Connection completion flag off
// Release Winsock.DLL
APPENDICES
A
359

Advertisement

Table of Contents
loading

Table of Contents