#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 <<
"Reads holding registers of slave[" << slv.
number() <<
"] on " <<
cout <<
"R0=" << registers[0].
value() << endl;
cout <<
"R1=" << registers[1].
value() << endl;
cout <<
"R2=" << registers[2].
value() << endl;
cout <<
"R3=" << registers[3].
value() << endl;
}
else {
cerr <<
"Unable to read input registers ! " << mb.
lastError() << endl;
exit (EXIT_FAILURE);
}
}
else {
cerr <<
"Unable to open MODBUS connection to " << port <<
" : " << mb.
lastError() << endl;
exit (EXIT_FAILURE);
}
return 0;
}