Pymodbus多个从站错误

时间:2017-07-21 10:44:11

标签: python modbus rs485

我创建了两个从站和一个主站(RTU),当我从slave id 1请求某些东西时,两个从站都获得了请求,因此其中一个信号slave 1不存在而另一个识别id并发送数据背部。但是当数据被发送回主设备时,其他从设备会尝试解析它,从而导致错误。

SLAVE 2 LOG:

DEBUG:pymodbus.server.sync:Started thread to serve client
DEBUG:pymodbus.server.sync:Client Connected [/dev/ttyUSB2:/dev/ttyUSB2]
DEBUG:pymodbus.server.sync:0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.server.sync:requested slave does not exist: 1
DEBUG:pymodbus.server.sync:0x1 0x3 0x2 0x0 0x11 0x78 0x48
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4

SLAVE 1 LOG:

DEBUG:pymodbus.server.sync:Started thread to serve client
DEBUG:pymodbus.server.sync:Client Connected [/dev/ttyUSB1:/dev/ttyUSB1]
DEBUG:pymodbus.server.sync:0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.datastore.context:validate[3] 1:1
DEBUG:pymodbus.datastore.context:getValues[3] 1:1
DEBUG:pymodbus.server.sync:send: 01030200117848
DEBUG:pymodbus.server.sync:0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.datastore.context:validate[3] 1:1
DEBUG:pymodbus.datastore.context:getValues[3] 1:1
DEBUG:pymodbus.server.sync:send: 01030200117848
DEBUG:pymodbus.server.sync:0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa

SLAVE 2中的另一个日志:

DEBUG:pymodbus.server.sync:Started thread to serve client
DEBUG:pymodbus.server.sync:Client Connected [/dev/ttyUSB2:/dev/ttyUSB2]
DEBUG:pymodbus.server.sync:0x1 0x3
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x0 0x0 0x0 0x1 0x84 0xa 0x1 0x3 0x2 0x0 0x12 0x38 0x49
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.server.sync:requested slave does not exist: 1
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x1 0x3 0x2 0x0 0x12 0x38 0x49
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x1 0x3 0x0 0x0 0x0 0x1 0x84 0xa 0x1 0x3 0x2 0x0 0x12 0x38 0x49
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x2 0x3 0x0 0x0 0x0 0x1 0x84 0x39
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x2 0x3 0x0 0x0 0x0 0x1 0x84 0x39
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x2 0x3 0x0 0x0 0x0 0x1 0x84 0x39
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4
DEBUG:pymodbus.server.sync:0x2 0x3 0x0 0x0 0x0 0x1 0x84 0x39
DEBUG:pymodbus.factory:Factory Request[1]
ERROR:pymodbus.server.sync:Socket error occurred unpack requires a string argument of length 4

如何让slave 2忽略以0x1开头的数据包? 我不知道这是图书馆中的错误还是我做错了。

这是奴隶2的代码:

#!/usr/bin/env python
from pymodbus.server.sync import StartSerialServer

from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock
from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext

from pymodbus.transaction import ModbusRtuFramer

import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

store = ModbusSlaveContext(
    di = ModbusSequentialDataBlock(0, [17]*100),
    co = ModbusSequentialDataBlock(0, [17]*100),
    hr = ModbusSequentialDataBlock(0, [17]*100),
    ir = ModbusSequentialDataBlock(0, [17]*100))

store2 = ModbusSlaveContext(
    di = ModbusSequentialDataBlock(0, [17]*100),
    co = ModbusSequentialDataBlock(0, [17]*100),
    hr = ModbusSequentialDataBlock(0, [18]*100),
    ir = ModbusSequentialDataBlock(0, [17]*100))

slaves_stores = {
    0x02: store2
}

context = ModbusServerContext(slaves=slaves_stores, single=False)

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'

StartSerialServer(context, framer=ModbusRtuFramer, identity=identity, 
port='/dev/ttyUSB2', stopbits=2, bytesize=8, parity='O', 
ignore_missing_slaves=True, timeout=.005, baudrate=921600)

0 个答案:

没有答案