1 year ago
#341801
Biraveen Nedunchelian
Is my pymodbus slave code usable or have i done something wrong?
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
python
modbus
pymodbus
0 Answers
Your Answer