App - 12 App - 12
MELSEC-F
APPENDIX
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 {
rb= length;
// Update the receive data storage
//
position
rec= 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;
Содержание FX3U-ENET
Страница 1: ...USER S MANUAL FX3U ENET ...
Страница 2: ......
Страница 159: ...8 6 8 6 MELSEC F 8 COMMUNICATION USING MC PROTOCOL MEMO ...
Страница 295: ...App 25 App 25 MELSEC F APPENDIX MEMO ...
Страница 297: ......