📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "YbCommDevice"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
try
{
YbCommDevice1->Active = true;
}
catch(Exception &e)
{
ShowMessage("YbCommDevice1: "+e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonSet1Click(TObject *Sender)
{
YbCommDevice1->SettingsDialog(this,true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonSend1Click(TObject *Sender)
{
YbCommDevice1->Write(Memo1->Text.c_str(), Memo1->Text.Length());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
//收到的字节数不会超过串口缓存的容量, 所以分配一个缓存容量相同的Buf
char Buf[8192+1]; //多一个文本结束符
int n = YbCommDevice1->Read(Buf,8192);
if(n>0) //收到字节数
{
Buf[n] = 0; //添加一个文本结束符 '\0'
Memo1->Text = Memo1->Text + Buf;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -