33#include < QCoreApplication>
44#include " tests/reg_map_read_write_test.h"
55#include " tests/tcp_read_write_test.h"
6+ #include " tests/rtu_read_write_test.h"
67
78#include " slave_tcp.h"
9+ #include " slave_rtu.h"
810#include " factory.h"
911
1012using namespace libmodbus_cpp ;
@@ -19,38 +21,42 @@ using namespace libmodbus_cpp;
1921// }
2022// }
2123
22- const bool RUN_TESTS = true ;
24+ const bool RUN_TESTS = false ;
2325
2426int main (int argc, char *argv[])
2527{
2628 if (RUN_TESTS) {
2729 QCoreApplication app (argc, argv);
28- libmodbus_cpp::RegMapReadWriteTest t1;
29- QTest::qExec (&t1);
30+ // libmodbus_cpp::RegMapReadWriteTest t1;
31+ // QTest::qExec(&t1);
3032
31- libmodbus_cpp::TcpReadWriteTest t2;
32- QTest::qExec (&t2);
33+ // libmodbus_cpp::TcpReadWriteTest t2;
34+ // QTest::qExec(&t2);
35+
36+ libmodbus_cpp::RtuReadWriteTest t3;
37+ QTest::qExec (&t3);
3338 return 0 ;
3439 }
3540
3641 QCoreApplication app (argc, argv);
37- SlaveTcp *s = Factory::createTcpSlave (" 127.0.0.1" , 1502 );
42+ // SlaveTcp *s = Factory::createTcpSlave("127.0.0.1", 1502);
43+ SlaveRtu *s = Factory::createRtuSlave (" /home/prikhodko_ev/ttySimSlave" , 9600 );
3844 s->initMap (32 , 32 , 32 , 32 );
39- // s->setValueToInputRegister(8, 0x0102030405060708L);
45+ s->setValueToInputRegister (8 , 0x0102030405060708L );
4046// printInputRegisters(s);
41- s->setValueToInputRegister (8 , 0x12345678 );
47+ // s->setValueToInputRegister(8, 0x12345678);
4248// printInputRegisters(s);
43- s->addHook (MODBUS_FC_READ_INPUT_REGISTERS, 8 , [s, counter = 0ull ]() mutable -> void {
44- s->setValueToInputRegister (8 , ++counter);
45- // printInputRegisters(s);
46- });
49+ // s->addHook(MODBUS_FC_READ_INPUT_REGISTERS, 8, [s, counter = 0ull]() mutable -> void {
50+ // s->setValueToInputRegister(8, ++counter);
51+ // // printInputRegisters(s);
52+ // });
4753
4854 // for (int i = 0; i < 32; ++i) {
4955 // s.setValueToHoldingRegister(i, (short)(i + 1));
5056 // s.setValueToInputRegister(i, (short)(i + 1));
5157 // }
5258
53- s->startListen (10 );
59+ s->startListen ();
5460
5561 return app.exec ();
5662}
0 commit comments