#include <iostream>
#include <iomanip>
#include <modbuspp.h>
using namespace std;
int main (int argc, char **argv) {
string port ("/dev/ttyUSB0");
if (argc > 1) {
port = argv[1];
}
cout <<
"Reads identifier of slave[" << slv.
number() <<
"] on " <<
cout <<
"Length: " << i.
size() << endl;
cout <<
"Id : 0x" << setfill (
'0') << setw (2) << hex << (int) i.
id() << endl;
cout <<
"Status: " << (i.
status() ?
"On" :
"Off") << endl;
cout <<
"Data : " << i.
data() << endl;
}
else {
cerr <<
"Unable to read slave identifier ! " << mb.
lastError() << endl;
exit (EXIT_FAILURE);
}
}
else {
cerr <<
"Unable to open MODBUS connection to " << port <<
" : " << mb.
lastError() << endl;
exit (EXIT_FAILURE);
}
return 0;
}