Luc JEAN kindly suggests: I recommend to post the questions on the google discussion group. More people can answer. :)
So here is a question on the modbusTk add_block(self, block_name, block_type, starting_address, size)
The MODBUS Application Protocol Specification V1.1b3 shows the MODBUS Addressing model in Fig 8 (please see the attached figure). I thought that the block added in modbusTk referred to the Device application blocks in the leftmost column. The starting_address in the add_block(), I presumed, referred to the starting address of the Device application blocks. So, in an RTU slave application, I added a holding-register block of 1024 words at location 4096 by slave_1.add_block('hr', cst.HOLDING_REGISTERS, 4096, 1024). I sent a modbus PDU to write multiple registers at holding register 5. (The MODBUS standard does state that the holding registers or any other of the 4 modbus block models are addressed from 1 to n and in the PDU they will be named 0 to n-1. But modbusTk finds that the holding register 5 is less than the starting address 4096 and gives addressing error.
I feel that the starting_address in the add_block(...) should refer to where the device application block is allocated and that the address in the PDU should not be compared with the starting_address of the block but only its size.
If the add_block() refers to 4 types of blocks within the mid column of the diagram, the starting_address will always be 0 and need not be specified. Or is modbusTk saving some memory? That is, a particular modbus application may use only holding registers 5,6,7 and then 12,13. So are we adding blocks with:
add_block(slave=1, blocktype=hr,
starting_add=5. length=3) and
add_block(slave=1, blocktype=hr,
starting_add=12. Length=2). ?
In the unittests, in
_read_continuous_blocks, modbusTk create
add_block(self._name+"1",
block_type, 0, 20)
add_block(self._name+"2", block_type,
20, 80)
add_block(self._name+"3", block_type, 100, 20)
Under what situation would multiple blocks of the same type be used please?
Could you please clarify what I should use for the starting_address in the add_block? From where will I get the value for starting_address and when should I create multiple blocks of the same type.
If the block created by add_block() is an application memory block, as I thought, then I would give the starting_address parameter as the address of the device application block where the modbus data blocks will be mapped. The MODBUS Application specification says that these device application blocks could be separate, or overlap or there could be just one device application block. This means that, for example, analog_input 3 and holding_register 9 could be the same memory address.
Cheers
k vinod kumar
--