-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameSerialSettings.cpp
152 lines (128 loc) · 4.4 KB
/
FrameSerialSettings.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <algorithm>
#include "FrameSerialSettings.h"
using std::lower_bound;
using std::min;
using std::max;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//TfrmeSerialSettings *frmeSerialSettings;
//---------------------------------------------------------------------------
__fastcall TfrmeSerialSettings::TfrmeSerialSettings(TComponent* Owner)
: TFrame(Owner)
{
}
//---------------------------------------------------------------------------
bool TfrmeSerialSettings::CheckParsValidity() const
{
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363214(v=vs.85).aspx
// o The number of data bits must be 5 to 8 bits.
// o The use of 5 data bits with 2 stop bits is an invalid combination,
// as is 6, 7, or 8 data bits with 1.5 stop bits.
return cmboxDataBits->ItemIndex >= 0 &&
( Bits != 5 || StopBits != TWOSTOPBITS ) &&
( Bits <= 5 || StopBits != ONE5STOPBITS );
}
//---------------------------------------------------------------------------
static DWORD const BaudRate[] = {
CBR_110
, CBR_300
, CBR_600
, CBR_1200
, CBR_2400
, CBR_4800
, CBR_9600
, CBR_14400
, CBR_19200
, CBR_38400
, CBR_57600
, CBR_115200
, CBR_128000
, CBR_256000
};
String TfrmeSerialSettings::GetPortName() const
{
return Trim( cmboxPortName->Text );
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetPortName( String Val )
{
cmboxPortName->Text = Trim( Val );
}
//---------------------------------------------------------------------------
TStrings& TfrmeSerialSettings::GetPortNameList() const
{
return *cmboxPortName->Items;
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetPortNameList( TStrings& Val )
{
cmboxPortName->Items->Assign( &Val );
}
//---------------------------------------------------------------------------
int TfrmeSerialSettings::GetSpeed() const
{
int const Idx = cmboxSpeed->ItemIndex;
if ( Idx >= 0 && Idx < static_cast<int>( sizeof BaudRate / sizeof *BaudRate ) ) {
return BaudRate[Idx];
}
return CBR_115200;
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetSpeed( int Value )
{
DWORD const * Begin = BaudRate;
DWORD const * End = BaudRate + sizeof BaudRate / sizeof *BaudRate;
DWORD const * Ptr = lower_bound( Begin, End, Value );
cmboxSpeed->ItemIndex = Ptr == End ? -1 : Ptr - Begin;
}
//---------------------------------------------------------------------------
int TfrmeSerialSettings::GetParity() const
{
int const Idx = cmboxParity->ItemIndex;
return Idx >= 0 ? Idx : NOPARITY;
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetParity( int Value )
{
cmboxParity->ItemIndex =
min( max( Value, 0 ), cmboxParity->Items->Count - 1 );
}
//---------------------------------------------------------------------------
int TfrmeSerialSettings::GetBits() const
{
int const Idx = cmboxDataBits->ItemIndex;
return Idx >= 0 ? Idx + 5 : 8;
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetBits( int Value )
{
cmboxDataBits->ItemIndex =
min( max( Value - 5, 0 ), cmboxDataBits->Items->Count - 1 );
}
//---------------------------------------------------------------------------
int TfrmeSerialSettings::GetStopBits() const
{
int const Idx = cmboxStopBits->ItemIndex;
return Idx >= 0 ? Idx : ONESTOPBIT;
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetStopBits( int Value )
{
cmboxStopBits->ItemIndex =
min( max( Value, 0 ), cmboxStopBits->Items->Count - 1 );
}
//---------------------------------------------------------------------------
bool TfrmeSerialSettings::GetCancelTXEcho() const
{
return checkboxCancelTXEcho->Checked;
}
//---------------------------------------------------------------------------
void TfrmeSerialSettings::SetCancelTXEcho( bool Val )
{
checkboxCancelTXEcho->Checked = Val;
}
//---------------------------------------------------------------------------