我的pymodbus奴隶代码是否可用,还是我做错了什么?
代码如下。如果我做了一些愚蠢的事情,我提前道歉。我导入了时间,因为我想在最终代码中延迟,
from pymodbus.version import version
from pymodbus.server.sync import StartSerialServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock, ModbusSparseDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
from pymodbus.transaction import ModbusRtuFramer, ModbusBinaryFramer
import time
#-----------------------------------------------------------------------------------------------
import logging
from twisted.names import client
FORMAT = ('%(asctime)-15s %(threadName)-15s'
' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#-----------------------------------------------------------------------------------------------
def run_server():
store = ModbusSlaveContext(
di=ModbusSequentialDataBlock(0, [17] * 100), #adresse, verdi( di = digital inputs)
co=ModbusSequentialDataBlock(0, [17] * 100), #--_-- (Coils)
hr=ModbusSequentialDataBlock(0, [17] * 100), #--_-- (Holding registers)
ir=ModbusSequentialDataBlock(0, [17] * 100)) #--_-- (input registers)
context = ModbusServerContext(slaves=store, single=True)
#Dette under mås til og måte være fast(slik jeg forstod det) ellers ville du bare få tomme 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 = version.short()
StartSerialServer(context,
framer=ModbusRtuFramer,
identity=identity,
port='COM1',
timeout=1,
baudrate=9600)
#if client.connect():
# print("det funker bro, u good homie")
run_server()
因为我无法访问 modbus 主站,所以我很难知道它是否有效。我会很乐意接受指导。
我想要的是通过 RTU 连接到主站/客户端并发送一些消息(如果可能)的代码
The code is the following. I apologise in advance if ive done something silly. I have imported time as i want to have a delay in my final code
from pymodbus.version import version
from pymodbus.server.sync import StartSerialServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock, ModbusSparseDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext
from pymodbus.transaction import ModbusRtuFramer, ModbusBinaryFramer
import time
#-----------------------------------------------------------------------------------------------
import logging
from twisted.names import client
FORMAT = ('%(asctime)-15s %(threadName)-15s'
' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#-----------------------------------------------------------------------------------------------
def run_server():
store = ModbusSlaveContext(
di=ModbusSequentialDataBlock(0, [17] * 100), #adresse, verdi( di = digital inputs)
co=ModbusSequentialDataBlock(0, [17] * 100), #--_-- (Coils)
hr=ModbusSequentialDataBlock(0, [17] * 100), #--_-- (Holding registers)
ir=ModbusSequentialDataBlock(0, [17] * 100)) #--_-- (input registers)
context = ModbusServerContext(slaves=store, single=True)
#Dette under mås til og måte være fast(slik jeg forstod det) ellers ville du bare få tomme 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 = version.short()
StartSerialServer(context,
framer=ModbusRtuFramer,
identity=identity,
port='COM1',
timeout=1,
baudrate=9600)
#if client.connect():
# print("det funker bro, u good homie")
run_server()
As I have no access to a modbus master, it is very difficult for me to know if it will work or not. I will happily be guided.
What I want is the code to connect to a master/client trough RTU and send some messages if possible
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论