?? main.~cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
h_RS232 = CreateFile(ComboBox1->Text.c_str(),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL );
if (h_RS232)
{
ShowMessage("Connect Success!");
BitBtn1->Enabled = false;
BitBtn2->Enabled = true;
BitBtn3->Enabled = true;
}
else
{
ShowMessage("Connect Fail!");
BitBtn1->Enabled = true;
BitBtn2->Enabled = false;
BitBtn3->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
if (h_RS232)
{
CloseHandle(h_RS232);
ShowMessage("Disconnect!");
BitBtn1->Enabled = true;
BitBtn2->Enabled = false;
BitBtn3->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
if ((h_RS232) && (Edit1->Text != ""))
{
DCB dcb;
ZeroMemory(&dcb, sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
dcb.BaudRate = 4800;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if(SetCommState(h_RS232,&dcb))
{
DWORD ByteCount;
WriteFile(h_RS232,
Edit1->Text.c_str(),
strlen(Edit1->Text.c_str()),
&ByteCount,
NULL);
}
Edit1->Text = "";
}
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -