stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.75k forks source link

modbus_read_bits maps each bit on an entire uint8_t #609

Open Mdp11 opened 2 years ago

Mdp11 commented 2 years ago

Hello everyone,

I was studying the library, and found out that the modbus_read_bits function, maps each bit read on an entire byte. This is a bit cumbersome when reading 2000 coils, since it will require 2000 bytes to be preallocated instead of 250.

Is there any way to use this function and get the bits grouped? I think an alternative is to use modbus_send_raw_request and modbus_receive_confirmation, but from the documentation I read that they must be used for debugging purposes.

Any help would be appreciated. Thanks!

stephane commented 2 years ago

The proper way to do that would be to only use bit instead of byte for storage. Not currently on my TODO list.