我正在我的Linux PC上设置一个Modbus TCP服务器。当我运行端口502下面的代码时,当我检查nmap时,在我的计算机上没有打开。
有人有这方面的经验吗?
https://pymodbus.readthedocs.io/en/latest/examples/synchronous-server.html
from pymodbus.server.async import StartTcpServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
store = ModbusSlaveContext(
di = ModbusSequentialDataBlock(0, [17]*100),
co = ModbusSequentialDataBlock(0, [17]*100),
hr = ModbusSequentialDataBlock(0, [17]*100),
ir = ModbusSequentialDataBlock(0, [17]*100))
context = ModbusServerContext(slaves=store, single=True)
#---------------------------------------------------------------------------#
# initialize the server information
#---------------------------------------------------------------------------#
# If you don't set this or any fields, they are defaulted to empty strings.
#---------------------------------------------------------------------------#
identity = ModbusDeviceIdentification()
identity.VendorName = 'Pymodbus'
identity.ProductCode = 'PM'
identity.VendorUrl = 'http://github.com/riptideio/pymodbus/'
identity.ProductName = 'Pymodbus Server'
identity.ModelName = 'Pymodbus Server'
identity.MajorMinorRevision = '1.0'
#---------------------------------------------------------------------------#
# run the server you want
#---------------------------------------------------------------------------#
# Tcp:
StartTcpServer(context, identity=identity, address=('localhost', 502))
编辑:如果我与同一台计算机上的客户端连接到服务器,则服务器正在工作。如果关闭服务器,则客户端响应端口502已关闭。
发布于 2017-11-13 17:58:04
您在此调用中作为服务器侦听地址提供的'localhost'
字符串:
StartTcpServer(context, identity=identity, address=('localhost', 502))
告诉服务器只侦听与服务器在同一系统上运行的客户端的连接。如果希望服务器接受来自其他系统的连接,则将空字符串''
作为地址传递,而不是'localhost'
。空字符串告诉服务器在该系统的所有接口上侦听。
https://stackoverflow.com/questions/47264617
复制相似问题