Appendix C: Program Examples
138
FX
3U
-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;
}
Содержание FX3U-ENET-ADP
Страница 1: ...FX3U ENET ADP USER S MANUAL ...
Страница 2: ......
Страница 6: ... 4 Safety Precautions Read these precautions before use MEMO ...
Страница 160: ...154 FX3U ENET ADP User s Manual Revised History Revised History Date Revision Description 2 2012 A First Edition ...
Страница 161: ......