📄 main.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RS232"
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE hComm;
bool DTR, RTS;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TxDataButtonClick(TObject *Sender)
{
RS2321->OutputString(TxMemo->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenPortButtonClick(TObject *Sender)
{
if (RS2321->PortOpen) {
ShowMessage("Port has opened");
return;
}
switch (PortRadioGroup->ItemIndex)
{
case 0 :
RS2321->CommPort = pnCOM1;
break;
case 1:
RS2321->CommPort = pnCOM2;
break;
case 2:
RS2321->CommPort = pnCOM3;
break;
default:
RS2321->CommPort = pnCOM4;
break;
}
RS2321->PortOpen = true;
RS2321->DTREnabled = false;
RS2321->RTSEnabled = false;
DTR = false;
RTS = false;
DTRShape->Brush->Color = clWhite;
RTSShape->Brush->Color = clWhite;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RxDataButtonClick(TObject *Sender)
{
RxMemo->Text = RS2321->Input;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StopSystemButtonClick(TObject *Sender)
{
if (!RS2321->PortOpen)
RS2321->PortOpen = false;
exit(0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if (RS2321->CTSHolding)
CTSShape->Brush->Color = clRed;
else
CTSShape->Brush->Color = clWhite;
if (RS2321->DSRHolding)
DSRShape->Brush->Color = clRed;
else
DSRShape->Brush->Color = clWhite;
if (RS2321->RIHolding)
RIShape->Brush->Color = clRed;
else
RIShape->Brush->Color = clWhite;
if (RS2321->CDHolding)
CDShape->Brush->Color = clRed;
else
CDShape->Brush->Color = clWhite;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DTRBtnClick(TObject *Sender)
{
if (RS2321->DTREnabled) {
DTRShape->Brush->Color = clWhite;
RS2321->DTREnabled = false;
}
else {
DTRShape->Brush->Color = clRed;
RS2321->DTREnabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RTSBtnClick(TObject *Sender)
{
if (RS2321->RTSEnabled) {
RTSShape->Brush->Color = clWhite;
RS2321->RTSEnabled = false;
}
else {
RTSShape->Brush->Color = clRed;
RS2321->RTSEnabled = true;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::RS2321ReceiveData(TObject *Sender)
{
RxMemo->Text = RxMemo->Text + RS2321->Input;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TxMemoKeyPress(TObject *Sender, char &Key)
{
if (Key == 0x0D)
RS2321->OutputString(TxMemo->Text);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -