Bus Query CycleThe communication on the RS-485 bus is always initiated by the master (Linux host running the Master Software). In order for the master to obtain status from PI units, a round cycle of query commands needs to be issued on the bus. For each step in the cycle, the master sends the command to an (addressed) unit, then waits for the response before sending a command to the next unit.
In general, commands are not sent as they are produced. Instead, they are queued and sent at regular time intervals over the bus.
Two commands are noticeable:
GET STATUS: Get GPI and Alarm status from addressed unit.
GET ADDR : Broadcast command to which each unit responses with its address.
This command serves auto-discovering purposes.
GET ADDR is particularly interesting. Since it is a broadcast command, all units will decode it simultaneously; however, units can not be allowed to respond at once because that would cause collisions in the bus. The implemented solution is that each unit delay the response by 1 ms multiplied by its address, minus 1. Thus unit with address 1 will respond immediately, unit 2 will delay 1 ms, unit 3 will delay 2 ms and so on.
With 14 units in the bus (maximum permitted) it will take 14 ms for all units to respond. This figure imposes a lower limit to the query cycle step time. The implemented value is 20 ms. GET STATUS commands (and any other, by the matter) is sent every 20 ms. The complete cycle will take 280 ms in the worst case (14 units).
At 19200 baud, a GET STATUS command plus the response will take 3.25 ms in the worst case, so the tolerance to communication and processing delays is more than adequate.
NOTA:
-----
Otra posibilidad es hacer el query cycle "normal" de 5 ms, y solo hacerlo de 20 ms si el comando lanzado es GET ADDR. Se puede incluso renunciar a la idea de un query cycle fijo y dejar que cada comando tenga su propio "tiempo de espera" para la respuesta el cual se puede hasta calcular at run-time (en lugar de fijarlo por disenno).
|