#!/usr/bin/env python #---------------------------------------------------------------------------# import os from pymodbus.server.async import StartTcpServer 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) os.system('clear') #---------------------------------------------------------------------------# # 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,0,1,0,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)) context = ModbusServerContext(slaves=store, single=True) #---------------------------------------------------------------------------# identity = ModbusDeviceIdentification() identity.VendorName = 'Pymodbus TCP' identity.VendorUrl = 'http://www.chispolinux.blogspot.com' identity.ProductName = 'Simulador de dispositivos by JMQ' identity.MajorMinorRevision = '1.0' #---------------------------------------------------------------------------# StartTcpServer(context, identity=identity, address=("localhost", 5020))
Generated by GNU Enscript 1.6.5.90.
No hay comentarios:
Publicar un comentario