Example #1
0
 def get_point(self, point_name):    
     register = self.get_register_by_name(point_name)
     client = SyncModbusClient(self.ip_address, port=self.port)
     try:
         result = register.get_state(client)
     except (ConnectionException, ModbusIOException, ModbusInterfaceException):
         result = None
     finally:
         client.close()
     return result
Example #2
0
 def set_point_sync(self, point_name, value):
     register = self.point_map[point_name]
     client = SyncModbusClient(self.ip_address, port=self.port)
     result = None
     try:
         result = register.set_state_sync(client, value)
     except (ConnectionException, ModbusIOException,
             ModbusInterfaceException):
         result = None
     finally:
         client.close()
     return result
Example #3
0
    def scrape_all(self):
        result_dict = {}
        try:
            client = SyncModbusClient(self.ip_address, port=self.port)

            result_dict.update(self.scrape_byte_registers(client, True))
            result_dict.update(self.scrape_byte_registers(client, False))

            result_dict.update(self.scrape_bit_registers(client, True))
            result_dict.update(self.scrape_bit_registers(client, False))
        except (ConnectionException, ModbusIOException,
                ModbusInterfaceException):
            print("ERROR: Failed to scrape device at " + self.ip_address +
                  ":" + str(self.port) + " " + "ID: " + str(self.slave_id))
            return None
        finally:
            client.close()

        return result_dict
Example #4
0
def modbus_client(address, port):
    with socket_lock():
        with closing(SyncModbusClient(address, port)) as client:
            yield client