5735b406
Peter M. Groen
Revert "Setting u...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include <iostream>
#include "ModbusAdapter.h"
int main( int argc, char* argv[] )
{
ModbusAdapter oModbus;
ConnectionConfig oConfig( ConnectionPort::CP_EXTERNAL, 9600, Parity::PAR_NONE, 8, 1, 1 );
std::cout << "========================= [START] Connection test ================================" << std::endl;
oModbus.ModbusConnect( oConfig );
if( oModbus.isConnected() )
{
std::cout << "Successful connected to : " << oConfig.getPort() << std::endl;
}
else
{
std::cout << "There was a problem connecting to : " << oConfig.getPort() << std::endl;
}
oModbus.ModbusDisconnect();
if( !oModbus.isConnected() )
{
std::cout << "Successful disconnected from : " << oConfig.getPort() << std::endl;
}
else
{
std::cout << "There was a problem disconnecting from : " << oConfig.getPort() << std::endl;
}
std::cout << "========================= [END] Connection test ===============================" << std::endl;
std::cout << "========================= [START] Reading test ================================" << std::endl;
std::cout << "== Reading the Hold Registers ==" << std::endl;
oModbus.ModbusConnect( oConfig );
if( oModbus.isConnected() )
{
std::cout << "Successful connected to : " << oConfig.getPort() << std::endl;
modbusData returnValues = oModbus.ModbusReadHoldReg( 1, MODBUS_FC_READ_HOLDING_REGISTERS, 2 );
if( returnValues.size() == 2 )
{
std::cout << "2 items returned from MODBUS_FC_READ_HOLDING_REGISTERS " << std::endl;
}
else
{
std::cout << "There was an error reading the Hold Registers " << std::endl;
std::cout << "Number of items returned : " << returnValues.size() << std::endl;
}
std::cout << "== Reading the Temperature ==" << std::endl;
returnValues = oModbus.ModbusReadData( 0x01, MODBUS_FC_READ_INPUT_REGISTERS, 0x00, 0x02 );
if( returnValues.size() == 0 )
{
std::cout << "No values returned " << std::endl;
}
else
{
std::cout << "Number of items returned : " << returnValues.size() << std::endl;
}
}
else
{
std::cout << "There was a problem connecting to : " << oConfig.getPort() << std::endl;
return -1;
}
oModbus.ModbusDisconnect();
std::cout << "=========================== [END] Reading test ================================" << std::endl;
}
|