Skip to content

Commit c4a7efa

Browse files
update TCP client example and USAGE docs for on_get callbacks, see #51, contributes to #31
1 parent 5f0e25d commit c4a7efa

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docs/USAGE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ be `percent`.
231231
###### Optional callbacks
232232

233233
The optional keys `on_set_cb` and `on_get_cb` can be used to register a
234-
callback function on client side which is executed after a new value has been
235-
set or after a register value has been requested.
234+
callback function on client side which is executed **after** a new value has
235+
been set or **before** the response of a requested register value has been
236+
sent.
236237

237238
```{note}
238239
Getter callbacks can be registered for all registers with the `on_get_cb`

examples/tcp_client_example.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,18 @@ def my_discrete_inputs_register_get_cb(reg_type, address, val):
9999

100100

101101
def my_inputs_register_get_cb(reg_type, address, val):
102+
# usage of global isn't great, but okay for an example
103+
global client
104+
102105
print('Custom callback, called on getting {} at {}, currently: {}'.
103106
format(reg_type, address, val))
104107

108+
# any operation should be as short as possible to avoid response timeouts
109+
# It would be also possible to read the leatest pin state at this time
110+
val += 1
111+
client.set_ist(address=address, value=val)
112+
print('Incremented current value by +1 before sending response')
113+
105114

106115
def reset_data_registers_cb(reg_type, address, val):
107116
# usage of global isn't great, but okay for an example

0 commit comments

Comments
 (0)