Mitsumi electronic NZ2GF-ETB Network Card User Manual


 
82
if(send(socketno, (char *)(s_buf), SEND_REQ_2, 0) == SOCKET_ERROR) {
// Data sending
Sockerror(ERROR_SEND); // Error handling
return (SOCK_NG);
}
// Receiving data with the size checked
rbuf_idx = 0; // Initializes the head index of the receive data storage
recv_size = 0; // Initializes the number of receive data
while(1) {
length = recv(socketno, (char *)(&r_buf[rbuf_idx]), (BUF_SIZE - rbuf_idx), 0);
// Receiving response data
if(length == 0) { // Was the 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 data are received.
}
}
else {
rbuf_idx += length; // Updates the receive data storage location.
recv_size += length; // Updates the number of receive data.
if(recv_size >= RECV_ANS_2) // Received all response messages?
break; // Stops the repetition as they were received.
}
}
printf("\nRY read completed\n");
//Read value display
for (i = 0; i < 2; i++) {
disp[0] = r_buf[11+(i*2)];
disp[1] = r_buf[12+(i*2)];
printf("RY00%d0 to RY00%dF read value: %4X\n", i, i, *(USHORT*)&disp);
}
printf("\n\n");
break;