address space numbers in long form addresses (40001, 30001) don't correspond to Modbus function numbers.
Examples for that long form addresses can be found http://www.modbus.org/docs/PI_MBUS_300.pdf --- decoders/modbus/pd.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/decoders/modbus/pd.py b/decoders/modbus/pd.py index d2307b9..102e863 100644 --- a/decoders/modbus/pd.py +++ b/decoders/modbus/pd.py @@ -628,6 +628,29 @@ def parse(self): # Just a message saying we don't need to parse anymore this round. pass + + def get_long_address(self, function, starting_address): + '''Get long form name for addresses. + Example: holding register 60 becomes 40061.''' + space = {1: 'COIL', + 2: 'INP_BIT', + 3: 'HOLD_REG', + 4: 'INP_REG', + 15: 'COIL', + 16: 'HOLD_REG', + 23: 'HOLD_REG' + }[function] + + base_address = {'COIL': 0, + 'INP_BIT': 10000, + 'HOLD_REG': 40000, + 'INP_REG': 30000, + }[space] + + if starting_address > 9998: + base_address *= 10 + return base_address + starting_address + 1 + def parse_read_data_command(self): '''Interpret a command to read x units of data starting at address, ie functions 1, 2, 3 and 4, and write the result to the annotations.''' @@ -647,8 +670,8 @@ def parse_read_data_command(self): starting_address = self.half_word(2) # Some instruction manuals use a long form name for addresses, this is # listed here for convienience. - # Example: holding register 60 becomes 30061. - address_name = 10000 * function + 1 + starting_address + # Example: holding register 60 becomes 40061. + address_name = self.get_long_address(function, starting_address) self.puti(3, 'address', 'Start at address 0x{:X} / {:d}'.format(starting_address, address_name)) @@ -680,12 +703,10 @@ def parse_write_multiple(self): data_unit = 'Coils' max_outputs = 0x07B0 ratio_bytes_data = 1/8 - long_address_offset = 10001 elif function == 16: data_unit = 'Registers' max_outputs = 0x007B ratio_bytes_data = 2 - long_address_offset = 30001 self.puti(1, 'function', 'Function {}: Write Multiple {}'.format(function, data_unit)) @@ -693,7 +714,7 @@ def parse_write_multiple(self): starting_address = self.half_word(2) # Some instruction manuals use a long form name for addresses, this is # listed here for convienience. - address_name = long_address_offset + starting_address + address_name = get_long_address(function, starting_address) self.puti(3, 'address', 'Start at address 0x{:X} / {:d}'.format(starting_address, address_name)) @@ -779,8 +800,8 @@ def parse_read_write_registers(self): starting_address = self.half_word(2) # Some instruction manuals use a long form name for addresses, this is # listed here for convienience. - # Example: holding register 60 becomes 30061. - address_name = 30001 + starting_address + # Example: holding register 60 becomes 40061. + address_name = self.get_long_address(23, starting_address) self.puti(3, 'address', 'Read starting at address 0x{:X} / {:d}'.format(starting_address, address_name)) -- 2.19.1 _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel