到目前为止的故事。我使用非常有用的教程设置了服务器和客户端,最初我使用“YouTube”在Raspberry Pi上做了这件事,没有任何问题。
https://github.com/Johannes4Linux/Simple-ModbusTCP-Server/blob/master/Simple_ModbusServer.py
然后,我尝试使用以太网端口在我的Windows PC上设置客户端,并连接到服务器(Pi)。
我在Pi中使用了"ifconfig“命令中的"inet”ip地址,而不是windows中的"ipconfig“中的地址(它们是不同的)。
client = ModbusClient(host="192.168.0.16", port=502, debug=True)
client.open()
connect error
False我曾尝试从windows ping此地址"cmd“,但连接超时。
ping 168.168.0.16
Pinging 168.168.0.16 with 32 bytes of data:
Request timed out.我感觉我错过了一些非常明显的东西。如果有人能帮助我,我将不胜感激。
发布于 2021-03-18 19:42:40
好吧,所以事实证明我有一点像个wally。在我的实现中,许多重要的概念都丢失了。
使用ipconfig/all调试问题时发现ipV4 =192.168.4.180(重复)
我已经在PC和Pi上设置了IP地址,我忘记了我已经更改了dchpcd.conf文件。因此,这些设备试图在网络子网中获取相同的地址。
下面的实现对我很有效:

在Pi上设置
from pyModbusTCP.server import ModbusServer, DataBank
server = ModbusServer(host="192.168.4.181", port=502, no_block=True)PC上的设置
from pyModbusTCP.client import ModbusClient
client = ModbusClient(host="192.168.4.181", port=502)
client.open()我发现这个指南在我的网络复习咒语中非常有用:https://www.ionos.co.uk/digitalguide/server/configuration/provide-raspberry-pi-with-a-static-ip-address/#:~:text=To%20assign%20an%20IP%20address,with%20the%20IPv4%20address%20192.168。
我很乐意删除这篇文章,但我想我还是把它留在这里吧,以防有人有意见或觉得有用。像往常一样,我会回答自己的问题,但有时只是将我自己的无知形式化成非黑即白的形式是有用的。
https://stackoverflow.com/questions/66659923
复制相似问题