C++builder串口通信設(shè)計(一)-串口接收數(shù)據(jù)
1、復(fù)制mscomm32.ocx到windowssystem32下
本文引用地址:http://m.butianyuan.cn/article/201611/322881.htm2、注冊
二、在c++builder下引入mscomm32.ocx
選擇菜單component->Import ActiveX Control,
選擇“Microsoft Comm Control 6.0(Version1.1)”,點擊“install”
然后可以在ActiveX控件組看到一個像電話的控件。
三、建立應(yīng)用工程
1、設(shè)計界面
引入了mscomm32控件,memo1控件,Button1,Button2,RadioButton1和RadioButton2
1) 其中memo1用于顯示串口接收內(nèi)容
2)Button1用于控制串口的開啟和關(guān)閉,Button2用于終止應(yīng)用程序
3)RadioButton1和RadioButton2用于選擇串口接收方式(類型)
2、unit1.h內(nèi)容,其中紅色為引入的全局變量
#include
#include
#include "MSCommLib_OCX.h"
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMSComm *MSComm1;
TMemo *Memo1;
TButton *Button1;
TButton *Button2;
TGroupBox *GroupBox1;
TRadioButton *RadioButton1;
TRadioButton *RadioButton2;
void __fastcall Button1Click(TObject *Sender);
void __fastcall MSComm1Comm(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall RadioButton1Click(TObject *Sender);
void __fastcall RadioButton2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
int type;//0--字符串,1---二進(jìn)制
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
評論