def watts_on_server(): # For rtu transport: connect to the Elkor Watts On meter by usb to the RS-485 interface # Can define ModbusClient2 by Map or defined the class as ModbusClient1 or ModbusClient2 # modbus_map = Map( # map_dir='/Users/anhnguyen/repos/kisensum-volttron/volttron/services/core/MasterDriverAgent/master_driver/interfaces/modbus_tk/maps', # addressing='offset', name='watts_on', file='watts_on.csv', endian='big') # ModbusClient2 = modbus_map.get_class() ModbusClient2 = Catalog()['watts_on'].get_class() client = ModbusClient2(slave_address=2, verbose=True) client.set_transport_rtu('/dev/tty.usbserial-AL00IEEY', 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, False) # Get reading values for defined registers print(dict((field.name, value) for field, value, timestamp in client.dump_all())) setattr(client, "serial_baud_rate", 115) client.write_all() print(getattr(client, "serial_baud_rate"))
def modbus_server(request): ModbusClient = Catalog()['mixed_endian_reg'].get_class() server_process = Server(address='127.0.0.1', port=5020) server_process.define_slave(1, ModbusClient, unsigned=False) server_process.start() time.sleep(1) yield server_process time.sleep(1) server_process.stop()
def modbus_server(request): modbus_client = Catalog()['battery_meter'].get_class() server_process = Server(address=IP, port=PORT) server_process.define_slave(1, modbus_client, unsigned=False) server_process.start() time.sleep(1) yield server_process time.sleep(1) server_process.stop()
def modbus_server(request): # modbus_map = Map(map_dir=os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "maps")), # addressing='address', name='ion6200', file='ion6200.csv', endian='big') # ModbusClient = modbus_map.get_class() ModbusClient = Catalog()['ion6200'].get_class() server_process = Server(address='127.0.0.1', port=5020) server_process.define_slave(1, ModbusClient, unsigned=False) server_process.start() time.sleep(1) yield server_process time.sleep(1) server_process.stop()
def modbus_server(request): # modbus_map = Map( # map_dir=os.path.abspath( # os.path.join(os.path.dirname(__file__), "..", "maps")), # addressing='offset', name='modbus_tk_test', # file='modbus_tk_test.csv', endian='big') # ModbusClient = modbus_map.get_class() modbus_client = Catalog()['modbus_tk_test'].get_class() server_process = Server(address=IP, port=PORT) server_process.define_slave(1, modbus_client, unsigned=False) server_process.start() time.sleep(1) yield server_process time.sleep(1) server_process.stop()
# modbus_map = Map( # map_dir='/Users/anhnguyen/repos/kisensum-volttron/volttron/services/core/MasterDriverAgent/master_driver/interfaces/modbus_tk/maps', # addressing='offset', name='watts_on', file='watts_on.csv', endian='big') # ModbusClient2 = modbus_map.get_class() ModbusClient2 = Catalog()['watts_on'].get_class() client = ModbusClient2(slave_address=2, verbose=True) client.set_transport_rtu('/dev/tty.usbserial-AL00IEEY', 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, False) # Get reading values for defined registers print dict( (field.name, value) for field, value, timestamp in client.dump_all()) setattr(client, "serial_baud_rate", 115) client.write_all() print getattr(client, "serial_baud_rate") if __name__ == '__main__': # For tcp transport ModbusClient = Catalog()['modbus_tk_test'].get_class() server_process = Server(address='127.0.0.1', port=5020) server_process.define_slave(1, ModbusClient, unsigned=True) server_process.start() # For rtu transport # watts_on_server()