Skip to content

Commit

Permalink
Add modbus device specification to API (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
kratochvil01 committed Mar 27, 2024
1 parent 5dd1352 commit c911583
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions evok/modbus_slave.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,15 @@ def __init__(self, client: Union[EvokModbusTcpClient, EvokModbusSerialClient],
self.loop: Union[None, IOLoop] = None
self.circuit: Union[None, str] = circuit
self.modbus_type = 'UNKNOWN'
if type(self.client) in [EvokModbusTcpClient, AsyncModbusTcpClient]:
self.modbus_spec = 'UNKNOWN'
if type(self.client) in [EvokModbusTcpClient]:
self.client: EvokModbusTcpClient
self.modbus_type = 'TCP'
elif type(self.client) in [EvokModbusSerialClient, AsyncModbusSerialClient]:
self.modbus_spec = self.client.host
elif type(self.client) in [EvokModbusSerialClient]:
self.client: EvokModbusSerialClient
self.modbus_type = 'RTU'
self.modbus_spec = self.client.port

def get(self):
return self.full()
Expand Down Expand Up @@ -243,6 +248,7 @@ def full(self):
'last_comm': 0x7fffffff,
'slave_id': self.modbus_address,
'modbus_type': self.modbus_type,
'modbus_spec': self.modbus_spec,
'scan_interval': self.scan_interval,
}
if self.alias != '':
Expand Down
2 changes: 2 additions & 0 deletions evok/modbus_unipi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, port: str, framer: Type[ModbusFramer] = ModbusRtuFramer, baud
for method_name in ['read_holding_registers', 'read_input_registers', 'write_register', 'write_registers',
'write_coil', 'connect']:
setattr(self, method_name, self.__block(getattr(self, method_name)))
self.port = port
self.lock = asyncio.Lock()
self.stime = time.time()
self.block_count = 0
Expand Down Expand Up @@ -46,6 +47,7 @@ def __init__(self, host: str, port: int = 502, framer: Type[ModbusFramer] = Modb
for method_name in ['read_holding_registers', 'read_input_registers', 'write_register', 'write_registers',
'write_coil']:
setattr(self, method_name, self.__block(getattr(self, method_name)))
self.host = host
self.lock = asyncio.Lock()
self.stime = time.time()
self.block_count = 0
Expand Down

0 comments on commit c911583

Please sign in to comment.