-
Notifications
You must be signed in to change notification settings - Fork 23
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
Proposal: Functions for dealing with multi-register values #33
Comments
I also thought about a more descriptive and high-level interface. Dreaming of a generically parameterized trait that statically describe the process image. In C++ this would be possible using some template-metaprograming. Rust is still a little limited in that regard and tbh. I'm also no Rust guru (but maybe a good opportunity to learn). I think the biggest drawback is that rust doesn't have variadic generics so maybe some macro-magic is required here. The goal would be to let the compiler validate data-access at compiletime to find type and index errors and to access a static stack array efficiently. |
I'm not sure you would need that level of abstraction in the modbus library. It feels like that level of validation should be left to device driver implementations. That being said, you could add the following type agnostic functions as a QoL improvement:
And add the following to deal with word order:
I'm willing to implement this if you don't have any objections. What are your thoughts? |
LGTM Would it make sense to also add Coils to ModbusValue or even implement ModbusValue for |
On the surface, it looks like Coils should be included, but since they work on the bit level, and have asymmetric data representation depending on what function code you are using, I think it makes more sense to leave them as their own explicit functions. |
Commonly, Modbus utilizes values that are represented by multiple registers (IEEE 32-bit Float being the most common). Would there be any interest in including this higher-level functionality? If so, what thoughts are there on how to implement this? I've accomplished this in my own projects by implementing traits on f32 and u32 that provide
T::to_registers(self) -> [u16;2]
andT::from_registers([u16;2]) -> T
. For a more general implementation, there would need to be a way to specify either low or high word order. Any input here is appreciated.The text was updated successfully, but these errors were encountered: