Mitsubishi Electronics MELSEC-F Universal Remote User Manual


 
App - 12
MELSEC-F
APPENDIX
App - 12
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 {
rbuf_idx += length; // Update the receive data storage
// position
recv_size += length; // Update the number of receive data
if(recv_size >= RECV_ANS_2) // 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("\receive data\n%s\n", r_buf);
if(shutdown(socketno,2)!=SOCK_OK){ // Processing to disable
// sending/receiving
Sockerror(ERROR_SHUTDOWN); // Error handling
return(SOCK_NG);
}
if(closesocket(socketno)!=SOCK_OK){ // Close processing
Sockerror(ERROR_CLOSE); // Error handling
return(SOCK_NG);
}
Closeflag=FLAG_OFF; // Connection completion flag off
WSACleanup(); // Release Winsock.DLL
printf("\nFX3U-ENET 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);
}
void Sockerror(int error_kind) // Error handling function
{
if(error_kind==ERROR_INITIAL){
printf("Initial processing is abnormal.");
}
else{
nErrorStatus=WSAGetLastError();
switch(error_kind){
case ERROR_SOCKET:
printf("Failed to create socket.");
break;