【发布时间】:2018-08-29 06:47:15
【问题描述】:
我正在尝试使用 TCP/IP 连接与设备(使用以太网连接)进行通信。发送连接请求时,出现错误:
dial tcp 192.168.137.10:502: connectex: A connection attempt failed because
the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond
但如果我连接到模拟器(它将充当设备),它会连接并发送给我响应。
我正在使用GO 进行编码。这是我连接到设备的代码
conn, err := net.Dial("tcp", "192.168.137.10:502")
if err != nil {
return nil, err
} else {
return conn, nil
}
硬件信息:
- Windows 10、64 位机器
- 通过 TCP/IP 连接的 PLC 设备
【问题讨论】:
-
很可能 Go 在这里没有问题,硬件设备有问题。这种情况的验证很简单:您需要通过不同方式尝试相同的连接来排除 Go 出错的可能性。我会尝试
telnet 192.168.137.10 502。这是how to do it。如果您发现telnet有效,而您的 Go 程序仍然无效,那将是一个有趣的情况,那么请回来提一个精致的问题。