openenergysolutions / modbus-cpp

Modbus TCP master library in modern C++
https://aegis4ics.github.io/modbus-cpp/
Apache License 2.0
2 stars 0 forks source link

Simplify construction of Read/Write requests #21

Open jadamcrain opened 6 years ago

jadamcrain commented 6 years ago

I found this a little awkward:

session->send_request(
    ::modbus::WriteSingleRegisterRequest { .value = ::modbus::RegisterValue {.address = self->address, .value = write_value }},
    write_handler
);

Since both values are "uint16_t" explicitly naming the argument is a good idea for code clarity. We might consider making "Address" a real type instead of a typedef and giving it an explicit constructor. In general, I'm not a fan of using C-style struct initialization in C++ code.

Let's polish the external API in this regard in the next iteration before release.