-
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
Bug: error when trying to write multiple coils - host.write_multiple_coils()
#22
Comments
host.write_multiple_coils()
)
host.write_multiple_coils()
)host.write_multiple_coils()
host.write_multiple_coils()
host.write_multiple_coils()
See Modbus Application Protocol section 6.11
|
@beyonlo could you try my fixes of https://github.com/brainelectronics/micropython-modbus/tree/feature/create-test-framework, this bug should now be fixed. At least this is what my new unittests report |
@brainelectronics I can't to test the because this new version has problem to connect: ModBus TCP Master - ESP32_02: >>> from umodbus.tcp import TCP as ModbusTCPMaster
>>> host = ModbusTCPMaster(slave_ip='192.168.1.4', slave_port=502, timeout=5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "umodbus/tcp.py", line 30, in __init__
OSError: [Errno 118] EHOSTUNREACH
>>> ModBus TCP Slave - ESP32_01: $ mpremote run tcp_client_example.py
Waiting for WiFi connection...
Waiting for WiFi connection...
Waiting for WiFi connection...
Connected to WiFi.
('192.168.1.4', '255.255.255.0', '192.168.1.1', '192.168.1.1')
Setting up registers ...
Register setup done
Serving as TCP client on 192.168.1.4:502 Note: I tried to use a old version (1.1.0) on for the Master and I have the same error. However I tried to connect via |
In both, Master and Slave I installed via pip the version 1.2.0rc5.dev28: >> import upip
>>> upip.index_urls = ['https://test.pypi.org/pypi']
>>> upip.install('micropython-modbus')
Installing to: /lib/
Warning: test.pypi.org SSL certificate is not validated
Installing micropython-modbus 1.2.0rc5.dev28 from https://test-files.pythonhosted.org/packages/5d/75/753871c80d40e9d6659e6e7185b0022d26f137265c2c333ad0865079fb89/micropython-modbus-1.2.0rc5.dev28.tar.gz I tried as well, just for sure, download the .zip from that new version and test it, and I have the same error. |
I tested the ModBus RTU Slave: ModBus RTU Master: >>> from umodbus.serial import Serial as ModbusRTUMaster
>>> rtu_pins = (18, 17)
>>> host = ModbusRTUMaster(baudrate=9600, data_bits=8, stop_bits=1, parity=None, pins=rtu_pins)
>>>
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)
[True, False, False, False, False, False, False, False]
>>>
>>> host.write_multiple_coils(slave_addr=10, starting_address=123, output_values=[1,1,1,0,0,1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/umodbus/serial.py", line 274, in write_multiple_coils
File "/lib/umodbus/serial.py", line 173, in _send_receive
File "/lib/umodbus/serial.py", line 190, in _validate_resp_hdr
ValueError: slave returned exception code: 1
>>> host.write_multiple_coils(slave_addr=10, starting_address=123, output_values=[1,1,1,0,0,1,1,1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/umodbus/serial.py", line 274, in write_multiple_coils
File "/lib/umodbus/serial.py", line 173, in _send_receive
File "/lib/umodbus/serial.py", line 190, in _validate_resp_hdr
ValueError: slave returned exception code: 1
>>>
>>> host.write_single_coil(slave_addr=10, output_address=123, output_value=0)
True
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)
[False, False, False, False, False, False, False, False] Scenario used: Installation method: via pip: >>> import upip
>>> upip.index_urls = ['https://test.pypi.org/pypi']
>>> upip.install('micropython-modbus')
Installing to: /lib/
Warning: test.pypi.org SSL certificate is not validated
Installing micropython-modbus 1.2.0rc5.dev28 from https://test-files.pythonhosted.org/packages/5d/75/753871c80d40e9d6659e6e7185b0022d26f137265c2c333ad0865079fb89/micropython-modbus-1.2.0rc5.dev28.tar.gz |
Relates to #24 |
Relates to #38 |
This bug was extracted from PR #10 report, in this reply:
Error when trying to write multiple coils (
host.write_multiple_coils()
)I not found examples on the docs about how is the correct way to write multiple coils, so I get a example from here
The text was updated successfully, but these errors were encountered: