9. Serial Communications RS-232
Borland C + + Builder does not contain any object or control for RS232 communication, so you have to find third-party resources to perform this function. RS232 serial communications can be implemented in many different ways you can access the Windows APIs (work hard and complex), you can install the Visual Basic ActiveX Mscomm32.ocx or you can use a controller developed for the Builder C + +. In our case we will use a small control Freeware developed by Victor Chen.
Borland c + + builder Serial Port Components
Methods:
void Open (); Open communication port
void Close (); Close communication port
bool Enabled (); State Communications Port
int Write (char Buf [], DWORD Count); Write Output Buffer
int Read (char Buf [], DWORD Count); Read the Input Buffer
InQueCount int (); number or bytes in the Input Buffer, -1 = Port Closed
OutQueCount int (); number or bytes in the Output Buffer, -1 = Port Closed
PurgeIn void (); Clean Input Buffer
PurgeOut void (); Clean Output Buffer
/ / Functions} {Comm escape
SetDTRState void (bool State);
SetRTSState void (bool State);
SetBREAKState void (bool State);
SetXONState void (bool State);
UpdateDataControlBlock void ();
TComm Properties
BaudRate (Baud Rate)
br110, BR300, br600, br1200, br2400, br4800, br9600, br14400, br19200, br38400, br56000, br57600, br115200, br128000, br256000
DataBits (Data bits)
da4, Qa5, DA6, DA7, DA8,
DeviceName (communications port name)
Com1, Com2 ...
EventChars
FlowControl (Flow Control)
fcNone, fcCTS, fcDTR, fcSoftware, fcDefault
MonitorEvents (Monitoring events)
Options
coParityCheck, coDsrSensitivity, coIgnoreXOff, coErrorChar, coNullStrip
Parity (Parity)
Panon, paOdd, paEven, paMark, PASPAC
ReadBufSize (read buffer size)
4096
ReadTimeout
1000
StopBits (Stop Bits)
SB10, SB 15, SB20
SuspendTime
5
WriteBufSize (write buffer size)
2048
WriteTimeout (timeout in script)
1000

TComm control properties of RS-232
Events
/ / OnBreak
void __fastcall TForm1:: Comm1Break (TObject * Sender) {
}
/ / OnComStatEvent
void __fastcall TForm1:: Comm1ComStatEvent (TObject * Sender, DWORD Status, COMSTAT COMSTAT) {
}
/ / OnCts
void __fastcall TForm1:: Comm1Cts (TObject * Sender) {
}
/ / OnDsr
void __fastcall TForm1:: Comm1Dsr (TObject * Sender) {
}
/ / OnRing
void __fastcall TForm1:: Comm1Ring (TObject * Sender) {
}
/ / OnRlsd
void __fastcall TForm1:: Comm1Rlsd (TObject * Sender) {
}
/ / OnError
void __fastcall TForm1:: Comm1Error (TObject * Sender, int Errors) {
}
/ / OnRxChar
void __fastcall TForm1:: Comm1RxChar (TObject * Sender, DWORD Count) {
}
/ / OnRxFlag;
void __fastcall TForm1:: Comm1RxFlag (TObject * Sender) {
}
/ / OnTxEmpty;
void __fastcall TForm1:: Comm1TxEmpty (TObject * Sender) {
}
Indicators:
bool Connected = {read = FConnected};
/ / Status flags} {Comm
CTS bool = {index = 1, read = GetModemState};
bool DSR = {index = 2, read = GetModemState};
RING bool = {index = 3, read = GetModemState};
RLSD bool = {index = 4, read = GetModemState};
CtsHold bool = {index = 1, read = GetComState};
DsrHold bool = {index = 2, read = GetComState};
RlsdHold bool = {index = 3, read = GetComState};
XOffHold bool = {index = 4, read = GetComState};
XOffSent bool = {index = 5, read = GetComState};
__property HANDLE Handle = {read = FHandle};

Events TComm control RS-232 communications