Skip to content

Commit 87a764e

Browse files
extend list of allowed output values of write_single_coil values to 0, 1, False, True, 0x0, 0xFF00, resolve brainelectronics#14
1 parent 3dfe683 commit 87a764e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
changed to `False` to avoid confusion behaviour if not explicitly defined,
2222
see [issue 13][ref-issue-13]
2323
- Missing function docstring added to `setup_registers` function
24+
- `write_single_coil` allows `0`, `1`, `False`, `True`, `0x0` or `0xFF00`
25+
instead of `0x0` and `0xFF00` only as set value, see [issue 14][ref-issue-14]
2426

2527
## [1.0.0] - 2022-02-26
2628
### Added
@@ -80,6 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8082
[0.1.0]: https://github.com/brainelectronics/micropython-modbus/tree/0.1.0
8183

8284
[ref-issue-13]: https://github.com/brainelectronics/micropython-modbus/issues/13
85+
[ref-issue-14]: https://github.com/brainelectronics/micropython-modbus/issues/14
8386

8487
[ref-pypi]: https://pypi.org/
8588
[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py

umodbus/functions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ def read_input_registers(starting_address, quantity):
4444

4545

4646
def write_single_coil(output_address, output_value):
47-
if output_value not in [0x0000, 0xFF00]:
47+
if output_value not in [0x0000, 0xFF00, True]:
4848
raise ValueError('Illegal coil value')
4949

50+
if output_value not in [0x0000, 0xFF00]:
51+
if output_value:
52+
output_value = 0xFF00
53+
else:
54+
output_value = 0x0000
55+
5056
return struct.pack('>BHH', Const.WRITE_SINGLE_COIL, output_address, output_value)
5157

5258

0 commit comments

Comments
 (0)