#!/usr/bin/env python #---------------------------------------------------------------------------# from pymodbus.server.async import StartSerialServer from pymodbus.device import ModbusDeviceIdentification from pymodbus.datastore import ModbusSequentialDataBlock from pymodbus.datastore import ModbusSlaveContext, ModbusServerContext from pymodbus.transaction import ModbusRtuFramer, ModbusAsciiFramer #---------------------------------------------------------------------------# import logging logging.basicConfig() log = logging.getLogger() log.setLevel(logging.DEBUG) #---------------------------------------------------------------------------# # di - entradas discretas # co - coils # hr - holding registros # ir - input registros hr01 = 100 hr02 = 110 hr03 = 120 hr04 = 130 hr05 = 140 hr06 = 150 hr07 = 160 hr08 = 170 ir01 = 100 ir02 = 110 ir03 = 120 ir04 = 130 ir05 = 140 ir06 = 150 ir07 = 160 ir08 = 170 Reg_DI = [1,0,1,1,1,1,1,0,1] Reg_CO = [1,0,1,1,1,1,1,0,1] Reg_HR = [hr01, hr02, hr03, hr04, hr05, hr06, hr07, hr08] Reg_IR = [ir01, ir02, ir03, ir04, ir05, ir06, ir07, ir08] store = ModbusSlaveContext( di=ModbusSequentialDataBlock(0, Reg_DI), co=ModbusSequentialDataBlock(0, Reg_CO), hr=ModbusSequentialDataBlock(0, Reg_HR), ir=ModbusSequentialDataBlock(0, Reg_IR)) esclavos = { 0x01: store, 0x02: store, 0x03: store, 0x04: store, 0x05: store, 0x06: store, 0x07: store, 0x08: store, } context = ModbusServerContext(slaves=esclavos, single=False) #---------------------------------------------------------------------------# identity = ModbusDeviceIdentification() identity.VendorName = 'Pymodbus SERIE' identity.VendorUrl = 'http://www.chispolinux.blogspot.com' identity.ProductName = 'Simulador de dispositivos by JMQ' identity.MajorMinorRevision = '1.0' #---------------------------------------------------------------------------# StartSerialServer(context, identity=identity, port='/dev/ttyUSB1', baudrate='9600', framer=ModbusRtuFramer)
Generated by GNU Enscript 1.6.5.90.
No hay comentarios:
Publicar un comentario