Python Modbus如何访问多个从属数据

2024-05-29 05:34:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想请你们的师傅帮忙

我们使用modbus与设备通信,但前提是pymodbs的主设备和从设备的比例为1:1

问题是一个主人想要管理几个奴隶。 为此,我们必须使用slave_id,这在pymodbs中是不可能的,我们发现umodbus是可能的

def get_serial_port():
    """ Return serial.Serial instance, ready to use for RS485."""
    port = Serial(port='/dev/ttyS1', baudrate=9600, parity=PARITY_NONE,
              stopbits=1, bytesize=8, timeout=1)

    fh = port.fileno()

    # A struct with configuration for serial port.
    serial_rs485 = struct.pack('hhhhhhhh', 1, 0, 0, 0, 0, 0, 0, 0)
    fcntl.ioctl(fh, 0x542F, serial_rs485)

    return port

serial_port = get_serial_port()

错误消息

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 8, in get_serial_port
OSError: [Errno 25] Inappropriate ioctl for device

问题在于,在从umodbus获取端口的过程中,错误发生在0x542F。 我们怎样才能解决这个问题

是否可以在1:m时在pymodbus中进行通信

enter link description here

多谢各位

enter image description here


Tags: forgetport错误stdinlineserialstruct

热门问题