Skip to content

Commit

Permalink
Fix Discrete Registers - and also coil registers was broken after add…
Browse files Browse the repository at this point in the history
…ing more debug output. Adjusted documentation
  • Loading branch information
Sven Bunge committed Oct 27, 2022
1 parent 5c808bb commit 9152116
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<input type="string" const_name="modbus_slave_ip" init_value="127.0.0.1">IP of modbus server</input>
<input type="number" const_name="port" init_value="502">Modbus TCP Port (default: 502)</input>
<input type="number" const_name="slave-id" init_value="1">Modbus slave id</input>
<input type="string" const_name="options" init_value="">Special options if needed, sep. by colon. Options: NoKeepAlive,Sleep100ms</input>
<input type="string" const_name="options" init_value="">Special options if needed, sep. by colon. Options see docu.</input>
<input type="number" const_name="modbus_wordorder" init_value="0">Word order: 0: LittleEndian (Modbus default); 1: BigEndian</input>
<input type="number" const_name="modbus_byteorder" init_value="1">Byte order: 0: LittleEndian; 1: BigEndian (Modbus default)</input>
<input type="number" const_name="reg_offset" init_value="0">Register offset: Shifts all registers. Default 0, often -1</input>
Expand Down
7 changes: 5 additions & 2 deletions doc/log14184.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Dieser GIRA Homeserver Logikbaustein liest mittels Modbus TCP Werte aus.
| 42 | Text | uint16 | Abfrage 8: Datentyp (* |
| 43 | Zahl | 1 | Abfrage 8: Bei numerischen Datentypen: Multiplikator, bei String: Länge des Strings für Abfrage (* |

Der Datentyp ist nur nötig bei Registertypen 3 (Holding) und 4 (Input). Bei den Anderen (Coil, Discrete) wird dieser ignoriert,
da es sich um boolische Rückgabewerte handelt (0 oder 1).

*) Unterstützt keine dynamischen Änderungen!

## Ausgänge
Expand Down Expand Up @@ -101,9 +104,9 @@ Sind die Register in Modicon Notation, so ist der Typ manuell zu wählen und die
40001 => Holding Register, Function Type 3 mit Register 1

| Register Adressen | Function Type | Typ |
| ----------------- |---------------|------------------------------------------------------------------------------------------|
|-------------------|---------------|------------------------------------------------------------------------------------------|
| 00000 - 09999 | 1 | Coil: 1bit-Register für boolische Representationen. Kann gelesen und geschrieben werden |
| 20000 - 29999 | 2 | Discrete Register: 1bit-Register für boolische Representationen. Kann nur gelesen werden |
| 10000 - 19999 | 2 | Discrete Register: 1bit-Register für boolische Representationen. Kann nur gelesen werden |
| 30000 - 39999 | 4 | Input Register: 16bit-Register - können nur gelesen werden |
| 40000 - 49999 | 3 | Holding Register: 16bit-Register - können gelesen und geschrieben werden |

Expand Down
8 changes: 5 additions & 3 deletions src/14184_hs_modbusTCP_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def fetch_register(self, input_num, input_addr_id, input_reg_read_type, input_re
if register_read_type == 1:
result = self.client.read_coils(register_addr, unit=unit_id)
elif register_read_type == 2:
result = self.client.read_discrete_inputs(register_addr, reg_fetch_size, unit=unit_id)
result = self.client.read_discrete_inputs(register_addr, unit=unit_id)
elif register_read_type == 3:
result = self.client.read_holding_registers(register_addr, reg_fetch_size, unit=unit_id)
elif register_read_type == 4:
Expand All @@ -192,11 +192,13 @@ def fetch_register(self, input_num, input_addr_id, input_reg_read_type, input_re
+ " of type " + self._get_input_value(input_reg_datatype), str(result))
return None

if register_read_type == 1:
# fetch coils (true/false)
if register_read_type == 1 or register_read_type == 2:
# fetch coils / discrete registers (true/false)
raw_value = result.bits
value = result.bits[0]
self._set_output_value(pin_output_num_id, int(value))
else:
# multi byte registers
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=self.byte_order(),
wordorder=self.word_order())
if register_settings.get('numeric'):
Expand Down

0 comments on commit 9152116

Please sign in to comment.