Comments (7)
Modbus protocol defines Function Code 1 (read coils) to read coils (bits) by address of coils (16 bits), which means every read (1 address) will get you 16 bits of coil values.
Refer to Modbus Wiki for more details.
For your case, in order to read 2 coils (2 bits), you will still need to read from 1 address (16 bits) and you need to parse the specific 2 bits from the response. If you want to read the 20th and 21st coils (bits), firstly check out which coil address to use (device document shall provide), here let's assume they are within the second coil address (address 1, because address 0 already occupies 16 bits/coils), you can try below config to read the value,
poll,coil,1,16,BE_BE
ref,coil17-32,16,bool16,rw
If it works, the received coil17-32
value shall contain the 20th and 21st coil values.
from modpoll.
I am aware that the answer contains more than two bits and I need to extract them from the appropriate place.
Wikipedia only say, the coil address and and the corresponding number of coils are of 16 bit length. (So, it's possible to request coil addresses above 256 and to request more than 255 coils at once). I have read again in the Modbus specification (page 11+12, Section 6.1, https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf). Here it looks like single coils, or in my case 2 coils, are allowed to be requested. The line 'poll,coil,20,2,BE_BE' does this correctly. The specification says that multiples of 8 bit are included in the response (not 16 bit). So when reading two coils, I expect only 1 byte in the response. In fact, as seen in the Wireshark log, the two bits are also correctly encoded into this response byte. Up to this point, everything is fine.
Let me briefly explain my problem:
- The device rejects queries of more than 2 coils by sending an error telegram, because only two coils are implemented in the device (Is this compliant with specification? I think so! But am not sure!).
- However, modpoll only allows matching lengths in the 'ref' line, but there are no matching data formats for 2 queried coils.
What do you think about the suggestion to decouple the specifications of the bit-widths for the 'poll' and 'ref' commands, so that it becomes possible to query only two coils. Is this restriction by the 'ref' command absolutely necessary?
Make working something similar like this would be very nice:
poll,coil,20,2,BE_BE
ref,coil20-36,16,bool16,rw
or better
poll,coil,20,2,BE_BE
ref,coil20-28,8,bool8,rw
I can live well with the representation of whole bytes or words in the output. The output of single coils would be a future nice new feature, but is not necessary. But decoupling the hardcoded data widths is really a problem, when the device only allows requesting less than 8 coils.
from modpoll.
OK, I see what you mean. We shall allow the tool read only 2 coils and receive one byte which contains 2 bits with padding 6 zero bits at higher order. Let me figure it out.
from modpoll.
Hi @jannemann70 , please try using the latest version (v0.6.0) with the following config,
poll,coil,20,2,BE_BE
ref,coil20-21,20,bool8,rw
Just to point out, the <address>
in ref
line uses the MODBUS address, which is different from the coil no.
So address 20 and coil 20 is totally different, the above config assumes your target coils are at address 20.
poll,<object_type>,<start_address>,<size>,<endian>
ref,<ref_name>,<address>,<dtype>,<rw>,<unit>,<scale>
Let me know if it works on your side.
Shaodong
from modpoll.
Installed successfully with both on windows (python 3.8.5)
pip3 install modpoll==0.6.0
or
pip3 install modpoll==0.6.1
Tried using tag 0.6.0 (and 0.6.1), running into similar error as described in #24.
C:\WINDOWS\system32>modpoll -v
Traceback (most recent call last):
File "c:\program files\python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\program files\python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python38\Scripts\modpoll.exe\__main__.py", line 4, in <module>
ImportError: cannot import name 'app' from 'modpoll' (c:\program files\python38\lib\site-packages\modpoll\__init__.py)
Are there any further steps to do?
from modpoll.
The issue was caused by poetry tool changes, which is fixed in v0.6.2, feel free to try again.
from modpoll.
RESOLVED
Thanks a lot for immediate resposes, and feature enhancements!
Great tool for testing purposes.
Best regards, Jan
Here, my output for the device I'm testing:
device,mydevice,1,,
poll,coil,20,2,BE_BE
ref,coil20-21,20,bool8,rw
poll,input_register,10,1,BE_BE
ref,value,10,int16,r,myunit,0.1
> modpoll --tcp 192.168.16.100 --config device.cfg --rate 0.1 --interval 0.01 -p
modpoll - A New Command Line Tool for Modbus
2023-09-19 09:29:45,898 | I | modpoll.main | No MQTT host specified, skip MQTT setup.
2023-09-19 09:29:45,898 | I | modpoll.modbus_task | Loading config from: device.cfg
2023-09-19 09:29:45,901 | I | modpoll.modbus_task | Added new device mydevice
2023-09-19 09:29:45,902 | I | modpoll.modbus_task | Add poller (start_address=20, size=2) to device mydevice
2023-09-19 09:29:45,902 | I | modpoll.modbus_task | Add poller (start_address=10, size=1) to device mydevice
2023-09-19 09:29:45,903 | I | modpoll.main | ====== modpoll polling at rate:0.1s, actual:0.1s ======
2023-09-19 09:29:45,960 | I | modpoll.modbus_task | Reading device:mydevice, FuncCode:1, Start_address:20, Size:2... SUCCESS
2023-09-19 09:29:45,978 | I | modpoll.modbus_task | Reading device:mydevice, FuncCode:4, Start_address:10, Size:1... SUCCESS
===== references from device: mydevice =====
+-----------+--------+---------+---------------------------------------------------------+
| name | unit | address | value |
+-----------+--------+---------+---------------------------------------------------------+
| coil20-21 | None | 20 | [False, False, False, False, False, False, True, False] |
| value | myunit | 10 | 0 |
+-----------+--------+---------+---------------------------------------------------------+
Done.
2023-09-19 09:29:46,004 | I | modpoll.main | ====== modpoll polling at rate:0.1s, actual:0.100693s ======
2023-09-19 09:29:46,013 | I | modpoll.modbus_task | Reading device:mydevice, FuncCode:1, Start_address:20, Size:2... SUCCESS
2023-09-19 09:29:46,030 | I | modpoll.modbus_task | Reading device:mydevice, FuncCode:4, Start_address:10, Size:1... SUCCESS
===== references from device: mydevice =====
+-----------+--------+---------+---------------------------------------------------------+
| name | unit | address | value |
+-----------+--------+---------+---------------------------------------------------------+
| coil20-21 | None | 20 | [False, False, False, False, False, False, True, False] |
| value | myunit | 10 | 0 |
+-----------+--------+---------+---------------------------------------------------------+
Done.
...
from modpoll.
Related Issues (20)
- Consider add device 'IP ADDR' and 'port' to .csv file HOT 3
- Consider upgrade `pymodbus` to version 3.2.2 HOT 2
- Add poll interval/rate for every single poll HOT 4
- writing registers with modpoll - how to do....? ...reading works fine ! HOT 7
- How must the config file look like?
- docker compose file example is missing HOT 1
- pip install modpoll - dosn't work HOT 2
- Consider update dependency of `pymodbus` to v3.5.2 HOT 1
- unable to run modpoll HOT 1
- Exceptions when calling local config file HOT 5
- Issue specifying <object_type>+<start_address> HOT 2
- Modbus TCP RTU Framer HOT 3
- Ommiting Addresses Prior to a Specified Coil HOT 2
- pyserial missing in dockerimage
- Move to RS485 breaks implementation HOT 7
- morningstar float16 support HOT 5
- Added logic to only push mqtt messages when a change is outside of a range HOT 2
- breaking change in paho.mqtt.python HOT 1
- Publish timestamp along with data HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modpoll.