-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModbusTCP_Indy.cpp
97 lines (78 loc) · 2.92 KB
/
ModbusTCP_Indy.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//---------------------------------------------------------------------------
#pragma hdrstop
#include "ModbusTCP_Indy.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma comment( lib, "IndyCore" )
#pragma comment( lib, "IndySystem" )
//---------------------------------------------------------------------------
namespace Modbus {
//---------------------------------------------------------------------------
namespace Master {
//---------------------------------------------------------------------------
TCPProtocolIndy::TCPProtocolIndy( String Host, uint16_t Port )
: idTCPClient_( new TIdTCPClient( 0 ) )
{
idTCPClient_->ConnectTimeout = 5000;
idTCPClient_->ReadTimeout = 2000;
DoSetHost( Host );
DoSetPort( Port );
}
//---------------------------------------------------------------------------
String TCPProtocolIndy::DoGetHost() const
{
return idTCPClient_->Host;
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoSetHost( String Val )
{
idTCPClient_->Host = Val;
}
//---------------------------------------------------------------------------
uint16_t TCPProtocolIndy::DoGetPort() const
{
return idTCPClient_->Port;
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoSetPort( uint16_t Val )
{
idTCPClient_->Port = Val;
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoOpen()
{
idTCPClient_->Connect();
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoClose()
{
idTCPClient_->Disconnect( true );
}
//---------------------------------------------------------------------------
bool TCPProtocolIndy::DoIsConnected() const
{
return idTCPClient_.get() && idTCPClient_->IOHandler &&
idTCPClient_->IOHandler->Connected();
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoInputBufferClear()
{
idTCPClient_->IOHandler->InputBuffer->Clear();
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoWrite( TBytes const OutBuffer )
{
//DebugBytesToHex( _T( "TCP TX: " ), OutBuffer );
idTCPClient_->IOHandler->Write( OutBuffer, OutBuffer.Length, OutBuffer.Low );
}
//---------------------------------------------------------------------------
void TCPProtocolIndy::DoRead( TBytes & InBuffer, size_t Length )
{
idTCPClient_->IOHandler->ReadBytes( InBuffer, Length, false );
//DebugBytesToHex( _T( "TCP RX: " ), InBuffer );
}
//---------------------------------------------------------------------------
}; // End of namespace Master
//---------------------------------------------------------------------------
}; // End of namespace Modbus
//---------------------------------------------------------------------------