Ejemplo n.º 1
0
def run_server():

    block1 = ModbusSequentialDataBlock(0x00, [0] * 0xFF)
    block2 = ModbusSequentialDataBlock(0x10, [0] * 0xFF)
    block3 = ModbusSequentialDataBlock(0x00, [0] * 0xFF)
    block4 = ModbusSequentialDataBlock(0x00, [0] * 0xFF)
    store1 = ModbusSlaveContext(co=block3, di=block4, hr=block1, ir=block2)
    store2 = ModbusSlaveContext(co=block3, di=block4, hr=block1, ir=block2)

    slaves = {0xFF: store1}

    context = ModbusServerContext(slaves=slaves, single=False)

    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 = '1.0'

    interval = 1
    server = ModbusTcpServer(context,
                             identity=identity,
                             address=('0.0.0.0', 502))
    t = threading.Thread(target=server.serve_forever, daemon=True)
    t.start()
    loop = LoopingCall(f=updatevalues, a=server)
    loop.start(interval, now=True)
    reactor.run()
Ejemplo n.º 2
0
    def __init__(self, system_settings):
        """
        Modified StartTcpServer from pymodbus.server.sync

        .. warning:: DO NOT CHANGE START TCP SERVER SECTION! VERY SENSITIVE!
        """
        identity = ModbusDeviceIdentification()
        identity.VendorName = system_settings['company']
        identity.ProductCode = system_settings['product']
        identity.VendorUrl = system_settings['url']
        identity.ProductName = system_settings['product']
        identity.ModelName = system_settings['version']
        identity.MajorMinorRevision = system_settings['version']

        framer = ModbusSocketFramer
        if MODBUS_FILL_EMPTY_DATA:
            slave = ModbusSlaveContext()
        else:
            # TODO: Complete this feature! Does not work properly at the moment!
            empty_block = ModbusSparseDataBlock({0x00: 0x00})
            slave = ModbusSlaveContext(di=empty_block,
                                       co=empty_block,
                                       hr=empty_block,
                                       ir=empty_block)

        # LOGGER.debug("slave.store = " + str(slave.store))
        context = ModbusServerContext(slaves=slave, single=True)
        self.server = ModbusTcpServer(context, framer)
        self.server.RequestHandlerClass = CustomModbusHandler
        super(ModbusProcess, self).__init__(target=self.server.serve_forever)
Ejemplo n.º 3
0
def run_updating_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #
    slaves = {
        0x0A: ModbusSlaveContext(),
        0x0B: ModbusSlaveContext(),
        0x0C: ModbusSlaveContext(),
    }
    context = ModbusServerContext(slaves=slaves, single=False)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'Synology NAS'
    identity.ProductCode = 'Synology'
    identity.VendorUrl = ''
    identity.ProductName = 'Synology Server'
    identity.ModelName = 'Synology Server'
    identity.MajorMinorRevision = '0.0.1'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    StartTcpServer(context,
                   identity=identity,
                   address=(MODBUS_SERVER_IP, MODBUS_SERVER_PORT))
Ejemplo n.º 4
0
def run_server(device, baud=9600):
    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [25185] * 1024),
                               ir=ModbusSequentialDataBlock(0, [25185] * 1024))
    slaves = {
        1: copy.deepcopy(store),
        2: copy.deepcopy(store),
        3: copy.deepcopy(store),
        4: copy.deepcopy(store),
        5: copy.deepcopy(store),
        6: copy.deepcopy(store),
        246: copy.deepcopy(store)
    }
    context = ModbusServerContext(
        slaves=slaves,
        single=False,
    )

    # RTU Server
    StartSerialServer(context,
                      identity=None,
                      port=device,
                      framer=ModbusRtuFramer,
                      stopbits=1,
                      bytesize=8,
                      parity=serial.PARITY_NONE,
                      baudrate=baud)
Ejemplo n.º 5
0
def run_PiCam_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #

    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [1] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [0] * 100),
                               ir=ModbusSequentialDataBlock(0, [17] * 100))
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'Robot system design'
    identity.ProductCode = 'PI'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    time = utilities_modbus.REGISTER_REFRESH_FREQUENCY
    loop = LoopingCall(f=updating_server, a=(context, ))
    loop.start(time, now=False)  # initially delay by time
    StartTcpServer(context,
                   identity=identity,
                   address=(utilities_modbus.IP, utilities_modbus.PORT))
Ejemplo n.º 6
0
    def __init__(self, slave_id, **kwargs):
        """Modbusスレーブの初期化

        Args:
            slave_id: RPi-GP10のスレーブデバイスID
            slave:    i2cスレーブアドレス
            strobe:   ストローブピン番号
            trigger:  トリガーピン番号
        """

        d = {}
        d['i2caddr'] = kwargs.get('slave', 0x20)
        d['strobe']  = kwargs.get('strobe', 14)
        d['trigger'] = kwargs.get('trigger', 15)

        self._gp10     = Gp10(**d)
        self._output   = 0xFF
        self._slave_id = slave_id
        self._polarity = {"output": 0x00, "input": 0x00}
        self._strobe   = {"enable": False, "time": 1, "remain": -1}
        self._trigger  = {"enable": False, "values": [False] * 8}

        Gp10ModbusSlave.gp10_trigger["gp10"] = self._gp10

        # Modbus データストア
        self._store = ModbusSlaveContext(
            di=ModbusSequentialDataBlock(0, [False]*17),
            co=ModbusSequentialDataBlock(0, [False]*27),
            hr=ModbusSequentialDataBlock(0, [0, self._strobe["time"]]),
            ir=ModbusSequentialDataBlock(9999, [0]*2))
Ejemplo n.º 7
0
def run_updating_server():
    # ----------------------------------------------------------------------- # 
    # initialize your data store
    # ----------------------------------------------------------------------- # 
    
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [17]*100),
        co=ModbusSequentialDataBlock(0, [17]*100),
        hr=ModbusSequentialDataBlock(0, [17]*100),
        ir=ModbusSequentialDataBlock(0, [17]*100))
    context = ModbusServerContext(slaves=store, single=True)
    
    # ----------------------------------------------------------------------- # 
    # initialize the server information
    # ----------------------------------------------------------------------- # 
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'pymodbus'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'pymodbus Server'
    identity.ModelName = 'pymodbus Server'
    identity.MajorMinorRevision = '2.3.0'
    
    # ----------------------------------------------------------------------- # 
    # run the server you want
    # ----------------------------------------------------------------------- # 
    time = 5  # 5 seconds delay
    loop = LoopingCall(f=updating_writer, a=(context,))
    loop.start(time, now=False) # initially delay by time
    StartTcpServer(context, identity=identity, address=("localhost", 5020))
Ejemplo n.º 8
0
def run_custom_db_server():
    # ----------------------------------------------------------------------- # 
    # initialize your data store
    # ----------------------------------------------------------------------- # 
    block  = CustomDataBlock([0]*100)
    store  = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #

    identity = ModbusDeviceIdentification()
    identity.VendorName = 'pymodbus'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'pymodbus Server'
    identity.ModelName = 'pymodbus Server'
    identity.MajorMinorRevision = '2.3.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #

    # p = Process(target=device_writer, args=(queue,))
    # p.start()
    StartTcpServer(context, identity=identity, address=("localhost", 5020))
Ejemplo n.º 9
0
def run_updating_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #

    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [17] * 100),
                               ir=ModbusSequentialDataBlock(0, [17] * 100))
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    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 = '2.2.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    time = 0.5  # 5 seconds delay
    loop = LoopingCall(f=updating_writer, a=(context, ))
    loop.start(time, now=False)  # initially delay by time
    StartSerialServer(context,
                      framer=ModbusRtuFramer,
                      identity=identity,
                      port='/dev/ttyS0',
                      timeout=1,
                      baudrate=460800)
Ejemplo n.º 10
0
    def initRegistersArea(self, hr_size):
        # ----------------------------------------------------------------------- #
        # initialize the server information
        # ----------------------------------------------------------------------- #
        # If you don't set this or any fields, they are defaulted to empty strings.
        # ----------------------------------------------------------------------- #
        identity = ModbusDeviceIdentification()
        identity.VendorName = 'ITLabs'
        identity.ProductCode = 'Conta-e-spara'
        identity.VendorUrl = 'https://github.com/fablabromagna-org/Conta-Spara'
        identity.ProductName = 'CS Modbus Gateway'
        identity.ModelName = 'Modbus Gateway'
        identity.MajorMinorRevision = '1.0'
        self.modbusIdentity = identity

        # ----------------------------------------------------------------------- #
        # initialize the data store
        # ----------------------------------------------------------------------- #
        store = ModbusSlaveContext(
            # di=ModbusSequentialDataBlock(0, [991]*100),
            # co=ModbusSequentialDataBlock(0, [992]*100),
            hr=ModbusSequentialDataBlock(0, [0] * hr_size))

        self.Size = hr_size

        self.clientContext = ModbusServerContext(slaves=store, single=True)
        return self.clientContext
Ejemplo n.º 11
0
def run_async_server():
    store_feed1 = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [17]*100),
        co=ModbusSequentialDataBlock(0, [17]*100),
        hr=ModbusSequentialDataBlock(0, [17]*100),
        ir=ModbusSequentialDataBlock(0, [17]*100))
    context_feed1 = ModbusServerContext(slaves=store_feed1, single=True)
    
    # ----------------------------------------------------------------------- # 
    # initialize the server information
    # ----------------------------------------------------------------------- # 
    # If you don't set this or any fields, they are defaulted to empty strings.
    # ----------------------------------------------------------------------- # 
    identity_feed1 = ModbusDeviceIdentification()
    identity_feed1.VendorName = 'Pymodbus'
    identity_feed1.ProductCode = 'PM'
    identity_feed1.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity_feed1.ProductName = 'Pymodbus Server'
    identity_feed1.ModelName = 'Pymodbus Server'
    identity_feed1.MajorMinorRevision = '1.0'
    
     
      
    # ----------------------------------------------------------------------- # 
    # run the server you want
    # ----------------------------------------------------------------------- # 
    
    StartTcpServer(context_feed1, identity=identity_feed1, address=("192.168.95.10", 502))
Ejemplo n.º 12
0
def run_custom_db_server(address, port):
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #
    coil_block = ModbusSequentialDataBlock(1, [0] * 256)
    discrete_input_block = ModbusSequentialDataBlock(10001, [0] * 256)
    input_register_block = ModbusSequentialDataBlock(30001, register_data)
    holding_register_block = ModbusSequentialDataBlock(40001, register_data)
    store = ModbusSlaveContext(di=discrete_input_block,
                               co=coil_block,
                               hr=holding_register_block,
                               ir=input_register_block,
                               zero_mode=True)
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #

    identity = ModbusDeviceIdentification()
    identity.VendorName = 'pymodbus'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'pymodbus Server'
    identity.ModelName = 'pymodbus Server'
    identity.MajorMinorRevision = '2.3.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #

    # p = Process(target=device_writer, args=(queue,))
    # p.start()
    StartTcpServer(context, identity=identity, address=(address, port))
Ejemplo n.º 13
0
def run_server():

    # Initialize data store
    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [17] * 100),
                               ir=ModbusSequentialDataBlock(0, [17] * 100))

    context = ModbusServerContext(slaves=store, single=True)

    # Server information
    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 = '2.3.0'

    # run the server you want after creating tasks

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("127.0.0.1", 9977))

    loop = asyncio.get_event_loop()
    loop.create_task(start_servers(context, identity, loop))
    loop.create_task(updating_writer(context, 0.3, sock))
    loop.run_forever()
    sock.close()
Ejemplo n.º 14
0
def run_server():
    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [17] * 100),
                               ir=ModbusSequentialDataBlock(0, [17] * 100))

    store.register(CustomModbusRequest.function_code, 'cm',
                   ModbusSequentialDataBlock(0, [17] * 100))
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    # If you don't set this or any fields, they are defaulted to empty 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 = '2.1.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    # Tcp:
    StartTcpServer(context,
                   identity=identity,
                   address=("localhost", 5020),
                   custom_functions=[CustomModbusRequest])
Ejemplo n.º 15
0
def run_updating_server():
    # ----------------------------------------------------------------------- # 
    # initialize your data store
    # ----------------------------------------------------------------------- # 
    
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [0]*100),
        co=ModbusSequentialDataBlock(0, [0]*100),
        hr=ModbusSequentialDataBlock(0, [0]*100),
        ir=ModbusSequentialDataBlock(0, [0]*100))
    context = ModbusServerContext(slaves=store, single=True)
    
    # ----------------------------------------------------------------------- # 
    # initialize the server information
    # ----------------------------------------------------------------------- # 
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'dreams by Eqinov'
    identity.ProductName = 'demo pilotage wattsense'
    identity.MajorMinorRevision = '1.0'
    
    # ----------------------------------------------------------------------- # 
    # run the server you want
    # ----------------------------------------------------------------------- # 
    timeRead = 1  # 1 second delay
    readLoop = LoopingCall(f=read_context, a=(context,))
    readLoop.start(timeRead, now=False) # initially delay by time	
	
    timeWrite = 30  # 1 second delay
    writeLoop = LoopingCall(f=write_context, a=(context,))
    writeLoop.start(timeWrite, now=False) # initially delay by time	
    StartTcpServer(context, identity=identity, address=("0.0.0.0", 5020))
Ejemplo n.º 16
0
def run_updating_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #

    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [17] * 100),
                               ir=ModbusSequentialDataBlock(0, [17] * 100))
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'pymodbus'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'pymodbus Server'
    identity.ModelName = 'pymodbus Server'
    identity.MajorMinorRevision = '2.2.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    time = 5  # 5 seconds delay
    #loop = LoopingCall(f=updating_writer, a=(context,))
    #loop.start(time, now=False) # initially delay by time
    #StartSerialServer(context, identity=identity, port="/dev/tty.usbserial-AK066TL5", framer=ModbusRtuFramer)
    StartSerialServer(context,
                      identity=identity,
                      port="/dev/tty.usbserial-AK066OZW",
                      framer=ModbusRtuFramer)
Ejemplo n.º 17
0
def run_updating_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #
    InitialValueList = [0] * 29 + CheckInitialValues()

    store = ModbusSlaveContext(
        hr=ModbusSequentialDataBlock(0, InitialValueList))
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'pymodbus'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'pymodbus Server'
    identity.ModelName = 'pymodbus Server'
    identity.MajorMinorRevision = '2.3.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    time = scan_interval  # 5 seconds delay
    loop = LoopingCall(f=updating_writer, a=(context, ))
    loop.start(time, now=False)  # initially delay by time
    StartTcpServer(context, identity=identity, address=(ip_address, port))
Ejemplo n.º 18
0
def init():
    slaves = {
        UNIT: ModbusSlaveContext(
            di=ModbusSequentialDataBlock(0, [17]*100),
            co=ModbusSequentialDataBlock(0, [17]*100),
            hr=ModbusSequentialDataBlock(0, [17]*100),
            ir=ModbusSequentialDataBlock(0, [17]*100)
        )
    }
    context = ModbusServerContext(slaves=slaves, single=False)

    identity = ModbusDeviceIdentification()
    identity.VendorName = 'HAXOM'
    identity.ProductCode = 'SIMU-ICS-PORTAIL'
    identity.VendorUrl = 'https://github.com/haxom/'
    identity.ProductName = 'SIMU-ICS'
    identity.ModelName = 'PORTAIL'
    identity.MajorMinorRevision = '1.0.0'

    print(f'Modbus slave launched on {listen_int}:{listen_port}')
    StartTcpServer(
        context,
        identity=identity,
        address=(listen_int, listen_port)
    )
def run_async_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #
    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [17] * 100),
                               co=ModbusSequentialDataBlock(0, [17] * 100),
                               hr=ModbusSequentialDataBlock(0, [17] * 100),
                               ir=ModbusSequentialDataBlock(0, [17] * 100))
    store.register(CustomModbusRequest.function_code, 'cm',
                   ModbusSequentialDataBlock(0, [17] * 100))
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'Pymodbus'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'Pymodbus Server'
    identity.ModelName = 'Pymodbus Server'
    identity.MajorMinorRevision = '2.2.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    StartTcpServer(context,
                   identity=identity,
                   address=("192.168.0.119", 5020),
                   custom_functions=[CustomModbusRequest])
Ejemplo n.º 20
0
def run_callback_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #
    queue = Queue()
    devices = read_device_map("device-mapping")
    block = CallbackDataBlock(devices, queue)
    store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    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()

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    p = Process(target=device_writer, args=(queue,))
    p.start()
    StartTcpServer(context, identity=identity, address=("localhost", 5020))
Ejemplo n.º 21
0
def run_callback_server():
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #
    queue = Queue()
    devices = {}
    temp = get_temp_c()

    devices[1] = temp  # thermostat BT
    devices[2] = 0  # heater
    devices[3] = 0  # fan

    block = CallbackDataBlock(devices, queue)
    store = ModbusSlaveContext(di=block, co=block, hr=block, ir=block)
    context = ModbusServerContext(slaves=store, single=True)

    identity = ModbusDeviceIdentification()
    identity.VendorName = 'nick_labs'
    identity.ProductCode = 'PM'
    identity.VendorUrl = 'http://github.com/bashwork/pymodbus/'
    identity.ProductName = 'poppycock Server'
    identity.ModelName = 'poppycock Server'
    identity.MajorMinorRevision = '1.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    p = Process(target=device_handler, args=(queue, ))
    p.start()
    StartTcpServer(context, identity=identity, address=("0.0.0.0", 5020))
Ejemplo n.º 22
0
def run_server():
    store = ModbusSlaveContext(di=ModbusSequentialDataBlock(0, [101] * 100),
                               co=ModbusSequentialDataBlock(0, [111] * 100),
                               hr=ModbusSequentialDataBlock(0, [1101] * 100),
                               ir=ModbusSequentialDataBlock(0, [111] * 100))

    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    # If you don't set this or any fields, they are defaulted to empty 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 = '2.3.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    # Tcp:
    StartTcpServer(context, identity=identity, address=("0.0.0.0", 9001))
Ejemplo n.º 23
0
def run_server():
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [17] * 100),
        co=ModbusSequentialDataBlock(0, [17] * 100),
        hr=ModbusSequentialDataBlock(0, [17] * 100),
        ir=ModbusSequentialDataBlock(0, [17] * 100),
    )

    context = ModbusServerContext(slaves=store, single=True)

    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()

    StartTlsServer(
        context,
        identity=identity,
        certfile="server.crt",
        keyfile="server.key",
        address=("127.0.0.1", 8020),
    )
Ejemplo n.º 24
0
def run_callback_server(ip, porta, queue, queue2):
    # ----------------------------------------------------------------------- #
    # initialize your data store
    # ----------------------------------------------------------------------- #

    diDataBlock = CallbackDataBlock(di_map(), queue, queue2)
    coDataBlock = CallbackDataBlock(co_map(), queue, queue2)
    hrDataBlock = CallbackDataBlock(hr_map(), queue, queue2)
    irDataBlock = CallbackDataBlock(ir_map(), queue, queue2)
    
    store = ModbusSlaveContext(di=diDataBlock, co=coDataBlock, hr=hrDataBlock, ir=irDataBlock)
    context = ModbusServerContext(slaves=store, single=True)

    # ----------------------------------------------------------------------- #
    # initialize the server information
    # ----------------------------------------------------------------------- #
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'LHF Instrumentacao'
    identity.ProductCode = 'mOHM 1.0'
    identity.VendorUrl = 'lhf.ind.br'
    identity.ProductName = 'Miliohmimetro'
    identity.MajorMinorRevision = '1.0'

    # ----------------------------------------------------------------------- #
    # run the server you want
    # ----------------------------------------------------------------------- #
    StartTcpServer(context, identity=identity, address=(ip, porta))
Ejemplo n.º 25
0
def run_server():
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [17] * 100),
        co=ModbusSequentialDataBlock(0, [17] * 100),
        hr=ModbusSequentialDataBlock(0, [17] * 100),
        ir=ModbusSequentialDataBlock(0, [17] * 100),
    )

    context = ModbusServerContext(slaves=store, single=True)

    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()

    # socat -d -d PTY,link=/tmp/ptyp0,raw,echo=0,ispeed=9600 PTY,link=/tmp/ttyp0,raw,echo=0,ospeed=9600

    StartSerialServer(
        context,
        framer=ModbusRtuFramer,
        identity=identity,
        port="/tmp/ttyp0",
        timeout=0.005,
        baudrate=9600,
    )
Ejemplo n.º 26
0
def run_simulation_server():
    # ----------------------------------------------------------------------- # 
    # initialize your data store
    # ----------------------------------------------------------------------- # 
    
    store = ModbusSlaveContext(
        co=ModbusSparseDataBlock({100: 0, 110: 0, 120: 0, 130: 0,}),#initiate Coils
        di=ModbusSparseDataBlock({100: 0, 110: 0}), #initiate discrete inputs
        ir=ModbusSparseDataBlock({100: 0, 110: 0, 120:0, 130:0, 140:0}), #initiate input registers
        hr=ModbusSparseDataBlock({100: 60000, 110: 10000, 120:655}), zero_mode=True) #initiate holding registers
    context = ModbusServerContext(slaves=store, single=True)
    
    # ----------------------------------------------------------------------- # 
    # initialize the server information
    # ----------------------------------------------------------------------- # 
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'akiUP'
    identity.ProductCode = 'IOP'
    identity.VendorUrl = 'https://github.com/akiUp/ICSonPySim'
    identity.ProductName = 'ICSonPy'
    identity.ModelName = 'ICS Simulation'
    identity.MajorMinorRevision = '0.0.1'
    
    # ----------------------------------------------------------------------- # 
    # run the Modbus Server with looping call of simulation
    # ----------------------------------------------------------------------- # 
    time = 0.1  # process frequency delay in seconds, increase if you want to slow down the process
    loop = LoopingCall(f=Process, mbcontext=(context,)) # Main caleer function continiously calls the Process() function
    loop.start(time, now=False) # initially delay by time
    StartTcpServer(context, identity=identity, address=("0.0.0.0", 502))
Ejemplo n.º 27
0
    def run(self):

        store = ModbusSlaveContext(
            di=ModbusSequentialDataBlock(0, [i for i in range(100)],),
            co=ModbusSequentialDataBlock(0, [i for i in range(100)]),
            hr=ModbusSequentialDataBlock(0, [i for i in range(100)]),
            ir=ModbusSequentialDataBlock(0, [i for i in range(100)]),
            zero_mode=True
            )

        for key, value in store.store.items():
            log.debug('number of coils/registers in {}: {}'.format(key, len(value.values)))

        context = ModbusServerContext(slaves=store, single=True)

        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 = '1.5'

        self.server = ModbusTcpServer(context, identity=identity, address=("localhost", 5020))
        log.info("starting modbus tcp server [localhost:5020]: {}".format(self.server))
        self.server.serve_forever()
Ejemplo n.º 28
0
 def _add_default_slave_context(self):
     return ModbusSlaveContext(
         di=CustomDataBlock(0, 0),
         hr=CustomDataBlock(0, 0),
         co=CustomDataBlock(0, 0),
         ir=CustomDataBlock(0, 0),
     )
Ejemplo n.º 29
0
def modbus_master(module, properties):
    log.debug('Modbus master module : ' + str(module))
    # Modbus Master
    #--------------------------------------------------------------------------#
    # initialize your data store
    #--------------------------------------------------------------------------#
    store = ModbusSlaveContext(co=ModbusSequentialDataBlock(0, [0] * 100),
                               hr=ModbusSequentialDataBlock(0, [0] * 100))
    context = ModbusServerContext(slaves=store, single=True)

    #--------------------------------------------------------------------------#
    # initialize the server information
    #--------------------------------------------------------------------------#
    identity = ModbusDeviceIdentification()
    identity.VendorName = 'ASO+AKO'
    identity.ProductCode = 'DYODEv2'
    identity.VendorUrl = 'http://github.com/wavestone-cdt/dyode'
    identity.ProductName = 'DYODE'
    identity.ModelName = 'Very Low Cost @ BlackHat Arsenal'
    identity.MajorMinorRevision = '1.0'

    #--------------------------------------------------------------------------#
    # run the server you want
    #--------------------------------------------------------------------------#
    time = 1  # 1 seconds delay
    loop = LoopingCall(f=modbus_master_update, a=(module, properties, context))
    loop.start(time, now=False)  # initially delay by time
    StartTcpServer(context, identity=identity, address=("0.0.0.0", \
                   properties['port_out']))
Ejemplo n.º 30
0
 def __init__(self, threadID, name, config, modbusRs2modbusTcp,
              modbusTcp2modbusRs):
     threading.Thread.__init__(self)
     self.threadID = threadID
     self.name = name
     self.config = config
     self.log = logging.getLogger(name)
     self.modbusRs2modbusTcp = modbusRs2modbusTcp  # kolejka do odbierania danych z modbusRs
     self.modbusTcp2modbusRs = modbusTcp2modbusRs  # kolejka do wysylania danych do modbusRS
     self.tick = 0.01
     self.interval = 0.1
     self.exitFlag = False
     self.store = ModbusSlaveContext(  # Tworzymy rejestr. Inicjalizujemy wszystko zerami.
         di=ModbusSequentialDataBlock(0, [00] * 1),
         co=ModbusSequentialDataBlock(0, [00] * 1),
         hr=ModbusSequentialDataBlock(0, [00] * 100000),
         ir=ModbusSequentialDataBlock(0, [00] * 1))
     # Multipleksacja na podstawie adresów rejestrów HR a nie na poziomie Unit Id.
     self.context = ModbusServerContext(slaves=self.store, single=True)
     self.identity = ModbusDeviceIdentification()
     self.identity.VendorName = 'pymodbus'
     self.identity.ProductCode = 'PM'
     self.identity.VendorUrl = 'itcloud'
     self.identity.ProductName = 'pymodbus Server'
     self.identity.ModelName = 'pymodbus Server'
     self.identity.MajorMinorRevision = '1.0'
     self.framer = ModbusSocketFramer
     self.server = ModbusTcpServer(self.context, self.framer, self.identity,
                                   (self.config["modbusTcp"]["bindIp"],
                                    self.config["modbusTcp"]["bindPort"]))