我想创建一个Modbus服务器(IP地址:152.168.96.11-与系统相同),并在另一个系统(IP地址:152.168.96.32)中运行Modbus客户端。我的客户端应用程序成功运行,并且我正在使用pymodbus服务器应用程序创建Modbus服务器应用程序。 32位数据交换(出于测试目的,可以读写)。我想读写特定地址的值到Modbus客户端。
如何配置python pymodbus服务器,使其能够读取和写入数据到客户端IP地址
这是pymodbus服务器应用程序-
# --------------------------------------------------------------------------- #
# import the various server implementations
# --------------------------------------------------------------------------- #
from pymodbus.server.sync import StartTcpServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
# --------------------------------------------------------------------------- #
# configure the service logging
# --------------------------------------------------------------------------- #
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
def run_server():
# ----------------------------------------------------------------------- #
# initialize your data store
# ----------------------------------------------------------------------- #
block = ModbusSequentialDataBlock(0, [888]*32)
store = ModbusSlaveContext(hr=block)
slaves = {
0x01: store,
}
context = ModbusServerContext(slaves=slaves, 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=('0.0.0.0', 255))
if __name__ == "__main__":
run_server()
最佳答案
请参阅Github中提出的issue,并从贡献者那里进行跟进。
关于python - 使用pymodbus模块的Python Modbus服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49479516/