Example #1
0
def modbus_server(request):
    modbus_server = Server(address='127.0.0.1', port=5020)
    modbus_server.define_slave(1, PPSPi32Client, unsigned=True)

    # Set values for registers from server as the default values
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigUShort"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigUInt"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigULong"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigShort"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigInt"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigFloat"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("BigLong"), 0)
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleUShort"), unpack('<H', pack('>H', 0))[0])
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleUInt"), unpack('<I', pack('>I', 0))[0])
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleULong"), unpack('<Q', pack('>Q', 0))[0])
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleShort"), unpack('<h', pack('>h', 0))[0])
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleInt"), unpack('<i', pack('>i', 0))[0])
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleFloat"), unpack('<f', pack('>f', 0))[0])
    modbus_server.set_values(1, PPSPi32Client().field_by_name("LittleLong"), unpack('<q', pack('>q', 0))[0])

    modbus_server.start()
    time.sleep(1)
    yield modbus_server
    time.sleep(1)
    modbus_server.stop()
Example #2
0
def modbus_server(request):
    ModbusClient = Catalog()['battery_meter'].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()
Example #3
0
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()
Example #4
0
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()
Example #5
0
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()

    ModbusClient = Catalog()['modbus_tk_test'].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()
Example #6
0
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()
Example #7
0
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()
Example #8
0
    # 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()
Example #9
0
    #     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()