diff --git a/Modbus_communication/Modbus_TCP/TCP_client.cpp b/Modbus_communication/Modbus_TCP/TCP_client.cpp index 2a0a9a2..a5ed0da 100644 --- a/Modbus_communication/Modbus_TCP/TCP_client.cpp +++ b/Modbus_communication/Modbus_TCP/TCP_client.cpp @@ -101,10 +101,10 @@ SOCKET Init_client(string IP, unsigned int Port_number) cout << "尝试连接TCP从站失败" << endl; } cout << "连接TCP从站成功" << endl; - //TIMEVAL timeout; - //timeout.tv_sec = 2000; //ms - //timeout.tv_usec = 0; //us - //setsockopt(ClientSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval));//设置接收超时时间 + TIMEVAL timeout; + timeout.tv_sec = 2000; //ms + timeout.tv_usec = 0; //us + setsockopt(ClientSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval));//设置接收超时时间 return ClientSocket; }