#include <iostream>
#include <string>
#include <modbuspp.h>
using namespace std;
int main (int argc, char **argv) {
string port ("/dev/ttyUSB0");
if (argc > 1) {
port = argv[1];
}
cout <<
"Write holding registers of slave[" << slv.
number() <<
"] on " <<
int ret;
registers[0] = 152.3;
registers[1] = 1010.7;
registers[2] = 45;
registers[3] = 901;
if (ret < 0) {
cerr <<
"Unable to write input registers ! " << mb.
lastError() << endl;
exit (EXIT_FAILURE);
}
else {
cout << ret << " registers written (16-bit)." << endl;
}
}
else {
cerr <<
"Unable to open MODBUS connection to " << port <<
" : " << mb.
lastError() << endl;
exit (EXIT_FAILURE);
}
return 0;
}