-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value limits accepted by Slave on the Holding Register (HREGS) #69
Comments
@beyonlo I see your need on this topic. As of now, according to the docs
micropython-modbus/umodbus/modbus.py Lines 246 to 252 in fa6430c
Maybe we could introduce a return value to the callbacks and stop executing further steps if the return value is e.g. if self._register_dict[reg_type][address].get('pre_set_cb', 0):
_cb = self._register_dict[reg_type][address]['on_set_cb']
if _cb(reg_type=reg_type, address=address, val=val):
return request.send_exception(Const.ILLEGAL_DATA_VALUE)
# the following code exists already
self._set_changed_register(reg_type=reg_type,
address=address,
value=val)
if self._register_dict[reg_type][address].get('on_set_cb', 0):
_cb = self._register_dict[reg_type][address]['on_set_cb']
_cb(reg_type=reg_type, address=address, val=val) to be used as (not tested) def my_holding_register_get_cb(reg_type, address, val):
print('Custom callback, called on getting {} at {}, currently: {}'.
format(reg_type, address, val))
def my_holding_register_set_cb(reg_type, address, val):
print('Custom callback, called on setting {} at {} to: {}'.
format(reg_type, address, val))
def my_holding_register_pre_set_cb(reg_type, address, val):
print('Custom callback, called on setting {} at {} to: {}'.
format(reg_type, address, val))
if val not in range(0, 101):
return False
else:
return True
client.add_hreg(
address=93,
value=19,
on_pre_set_cb=my_holding_register_pre_set_cb,
on_set_cb=my_holding_register_set_cb,
on_get_cb=my_holding_register_get_cb
) |
@brainelectronics Excellent! Thank you for the example :) |
@GimmickNG could you please to port this example for the your |
@beyonlo Looking at this, I'm not sure it needs to specifically be ported for the async examples - the only changes required seem to be adding the |
@GimmickNG Could you please to create/add an example for that? Maybe just add an entry to the host_tests.py? So, I can test it for you :) Thank you in advance! |
Are there any updates on this feature? the latest (2.3.7 version) does not include this. |
Description
Is there a way to set what are the values allowed and/or min and max values allowed on the
Slave
?Example 1:
The address
93
is number29
. I would like that address accept just min value1
and max value8
Example 2:
The address
96
is number1600
. I would like that address accept just one of this list [1600, 2100, 2300, 5000, 132, 8003]So, if
ModBus Master
try to set a different value than that allowed, will be not accepted by theSlave
, and an error will be returned to theMaster.
Is possible to do that or something similar?
Thank you!
Reproduction steps
...
MicroPython version
1.19.1
MicroPython board
ESP32
MicroPython Modbus version
Relevant log output
No response
User code
No response
Additional informations
No response
The text was updated successfully, but these errors were encountered: