Mitsubishi Electric FX3U-ENET-ADP User Manual page 144

Table of Contents

Advertisement

FX
-ENET-ADP User's Manual
3U
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("\nFX3U-ENET-ADP Test End.\n\n Normally completed. \n");
printf("Press any key to exit the program.\n");
Dmykeyin=getchar();
return(SOCK_OK);
}
void Sockerror(int error_kind)
{
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);
nErrorStatus=closesocket(socketno);
Closeflag=FLAG_OFF;
}
printf("Press any key to exit the program.\n");
Dmykeyin=getchar();
WSACleanup();
return;
}
138
Appendix C-1 Program example for communication using MC protocol -1
// Processing to disable sending/receiving
// Error handling
// Close processing
// Error handling
// Connection completion flag off
// Release Winsock.DLL
// Wait for key input
// Error handling function
// Shutdown processing
// Close processing
// Connection completion flag off
// Wait for a key input
// Release Winsock.DLL
Appendix C: Program Examples

Advertisement

Table of Contents
loading

Table of Contents