I am using RasPi connected to other system via serial console. My other system is running modbus master and Raspi is acting as modbus slave. Raspi has written to some register values and master is continuously asking for some register values.
Below is the code for slave
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
from threading import Thread
from pandas import read_csv
import time
import logging
logging.basicConfig()
log = logging.getLogger("pymodbus")
#log.setLevel(logging.ERROR)
log.setLevel(logging.DEBUG)
class test:
# '''
# '''
def __init__(self, configfile='map_default.csv', timeoutval = .05, baudrateval=115200 ):
#---------------------------------------------------------------------------#
# initialize data store
#---------------------------------------------------------------------------#
log.info("Initializing MODBUS simulator data store...")
block = ModbusSequentialDataBlock(0, [0]*2000)
self.cphm_sim = ModbusSlaveContext()
self.context = ModbusServerContext(slaves=self.cphm_sim, single=True)
self.identity = ModbusDeviceIdentification()
self.setIdentity( {"VendorName" : "inc",
"ProductCode" : Sim",
"VendorUrl" : "url.com/",
"ProductName" : "Simulator",
"ModelName" : "Simulator",
"MajorMinorRevision" : "1.0"})
self.readConfig_init(configfile)
thread = Thread(target=self.start_server, args=(timeoutval, baudrateval))
thread.start()
def start_server(self, timeoutval, baudrateval):
log.error("Modbus Serial server started.Simulator data store initialization finished.")
StartSerialServer(self.context, framer=ModbusRtuFramer, identity=self.identity, port='/dev/ttyUSB0', timeout=timeoutval, baudrate=baudrateval)
Getting logs on Raspi as
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer -
DEBUG:pymodbus.server.sync:Error: Socket error occurred device reports readiness to read but returned no data (device disconnected or multiple access on port?)
DEBUG:pymodbus.framer.rtu_framer:Getting Frame - 0x3 0x5 0x3a 0x0 0x2
DEBUG:pymodbus.factory:Factory Request[3]
DEBUG:pymodbus.framer.rtu_framer:Frame advanced, resetting header!!
DEBUG:pymodbus.datastore.context:validate[3] 1339:2
DEBUG:pymodbus.datastore.context:getValues[3] 1339:2
DEBUG:pymodbus.server.sync:send: 01030400000000fa33
DEBUG:pymodbus.framer.rtu_framer:Resetting frame - Current Frame in buffer -
DEBUG:pymodbus.server.sync:Error: Socket error occurred device reports readiness to read but returned no data (device disconnected or multiple access on port?)
On Master it is failed to retreive some of the registers. Sometimes It is able to read the registers and next time it reads successfully.
Anybody aware what wrong I am doing here