b-robotized / b-robotized/modbus_hardware_interface

Issue with the "bits" mode (writing)

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
19
Forks
9
PR merge metrics
No merged PRs in 30d

Description

Hi,

Thanks for this package, it is very useful.

I recently tried to use it to control the digital output of a Wago module (WAGO [750-1504](https://www.wago.com/fr/syst%C3%A8mes-i-o/sortie-digitale-%C3%A0-16-canaux/p/750-1504)).
I used the `bits` mode. The reading works as expected, but I ran into some issues when using the for wrting with the following config:

```yaml
...

${ address }
1
bits
float

...
```

The issues, related with the writing function "float", seems to be located in the `ModbusInterfaceWriteConfig::double_to_modbus_8` method.
More specifically:

https://github.com/StoglRobotics/modbus_hardware_interface/blob/c60afb2ce93c7b4ac50c31349052ebf6bed241b0/include/modbus_hardware_interface/modbus_client.hpp#L451-L457

Got it to work by only writing a single bit:

```diff
modbus_float_to_uint_8_ = [](const float & value) -> std::vector
{
std::vector data(1);
+ data[0] = value == 0.0 ? 0x00 : 0xFF;
- // TODO(Manual) Maybe clamp, round and check that its zero/one?
- data.push_back(static_cast(value));
return data;
};
```

It should be noted that the rounding to `0` or `1` is simply to avoid undefined casting behavior, but it might not be strictly necessary.

Did you test only writing bits? If yes, is this an issue you faced or do I use the library incorrectly?

Cheers.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.