EasyManua.ls Logo

Mitsubishi Electric FX3U-ENET-ADP - Page 144

Mitsubishi Electric FX3U-ENET-ADP
162 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Appendix C: Program Examples
138
FX3U-ENET-ADP User's Manual
Appendix C-1 Program example for communication using MC protocol -1
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-ADP 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;
case ERROR_BIND:
printf("Failed to bind.");
break;
case ERROR_CONNECT:
printf("Failed to establish connection.");
break;
case ERROR_SEND:
printf("Sending failed.");
break;
case ERROR_RECIEVE:
printf("Receiving failed.");
break;
case ERROR_SHUTDOWN:
printf("Failed to shutdown.");
break;
case ERROR_CLOSE:
printf("Failed to close normally.");
break;
}
}
printf("Error code is %d.\n", nErrorStatus);
if(Closeflag==FLAG_ON){
nErrorStatus=shutdown(socketno,2); // Shutdown processing
nErrorStatus=closesocket(socketno); // Close processing
Closeflag=FLAG_OFF; // Connection completion flag off
}
printf("Press any key to exit the program.\n");
Dmykeyin=getchar(); // Wait for a key input
WSACleanup(); // Release Winsock.DLL
return;
}

Table of Contents

Related product manuals