我有一些与ADAM模块(研华的以太网I/O模块,ADAM-6000/6200系列)通信的代码,它连接到一个套接字,并在循环中成功读取数据,它过去工作得很好,但现在它停止并等待sysread()
完成,永远不会完成。
我可以做些什么来帮助解决或进一步诊断此问题?
编码
socket($socket, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "Unable to Connect";
connect($socket, sockaddr_in('1000', inet_aton($ip_address)
....
print "\n\ndo_command() begin:\n";
print "Send: " . Data::Dumper::qquote($str) . "\n";
syswrite($socket, $str);
usleep(600000);
print "Wrote to socket\n";
print "Waiting on sysread to finish...\n";
my $bytes = sysread($socket, $data_line, 200);
print "Data Read: " . Data::Dumper::qquote($data_line) . "\n";
print "Bytes Read: $bytes\n";
输出
do_command() begin:
Send: "#01\r"
Wrote to socket
Waiting on sysread to finish...
脚本执行不会超过最后一行。在我重新启动脚本后,它会再次运行一段时间,然后在同一个位置再次停止。通常脚本会无限期地循环执行这些指令。
strace输出
write(4, "#01\r", 4) = 4
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=600000000}, NULL) = 0
write(1, "Wrote to socket\n", 16) = 16
write(1, "Waiting on sysread to finish...\n", 32) = 32
read(4, ">+00.018+00.016+00.020+00.008-00"..., 200) = 58
write(1, "Data Read: \">+00.018+00.016+00.0"..., 73) = 73
write(1, "Bytes Read: 58\n", 15) = 15
write(1, "\n", 1) = 1
write(1, "Sleeping for .1 seconds\n", 24) = 24
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=100000000}, NULL) = 0
write(1, "Read Cycle\n", 11) = 11
write(1, "\n\ndo_command() begin:\n", 22) = 22
write(1, "Send: \"#01\\r\"\n", 14) = 14
write(4, "#01\r", 4) = 4
clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=0, tv_nsec=600000000}, NULL) = 0
write(1, "Wrote to socket\n", 16) = 16
write(1, "Waiting on sysread to finish...\n", 32) = 32
read(4,
1条答案
按热度按时间pb3s4cty1#
重新启动远程计算机解决了问题。