首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用pymodbus模块的pymodbus服务器

使用pymodbus模块的pymodbus服务器
EN

Stack Overflow用户
提问于 2018-03-25 18:40:53
回答 1查看 4K关注 0票数 1

我希望创建一个Modbus服务器(IP地址: 152.168.96.11 -与系统相同)和运行在不同系统中的Modbus客户端( IP地址: 152.168.96.32)。我的客户端应用程序正在成功运行,我正在使用pymodbus服务器应用程序创建Modbus服务器应用程序。32位数据交换(为测试目的而读或写)。我想读写特定地址的值到Modbus客户端。

如何将python pymodbus服务器配置为能够将数据读写到客户端IP地址的服务器?

这是pymodbus服务器应用程序-

代码语言:javascript
运行
复制
# --------------------------------------------------------------------------- # 
# 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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-28 08:47:01

请参考Github中提出的issue,并从贡献者那里跟进。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49479516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档