|
// ---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
// ---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "CPort.hpp"
#include "CPortCtl.hpp"
// ---------------------------------------------------------------------------
class TForm1 : public TForm {
__published: // IDE-managed Components
TComPort *ComPort1;
TComPort *ComPort2;
TComLed *ComLed1;
TComLed *ComLed2;
TComComboBox *ComComboBox1;
TComComboBox *ComComboBox2;
TButton *Button1;
TButton *Button2;
TButton *Button3;
TButton *Button4;
TButton *Button5;
TMemo *Memo1;
TMemo *Memo2;
TButton *Button6;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
void __fastcall Button5Click(TObject *Sender);
void __fastcall Button6Click(TObject *Sender);
void __fastcall ComPort2RxChar(TObject *Sender, int Count);
void __fastcall ComPort1RxChar(TObject *Sender, int Count);
private: // User declarations
public : // User declarations
__fastcall TForm1(TComponent* Owner);
};
// ---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
// ---------------------------------------------------------------------------
#endif
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CPort"
#pragma link "CPortCtl"
#pragma resource "*.dfm"
TForm1 *Form1;
// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender) {
ComPort1->Connected = true;
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender) {
ComPort2->Connected = true;
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender) {
ComPort1->Connected = false;
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender) {
ComPort2->Connected = false;
}
// ---------------------------------------------------------------------------
unsigned char buf1[128];
unsigned char buf2[128];
void __fastcall TForm1::Button5Click(TObject *Sender) {
buf1[0] = 0x30;
buf1[1] = 0x31;
buf1[2] = 0x32;
buf1[3] = 0x33;
buf1[4] = 0x34;
buf1[5] = 0x35;
buf1[6] = 0x36;
buf1[7] = 0x37;
buf1[8] = 0x38;
buf1[9] = 0x39;
buf1[10] = 0x00;
ComPort1->Write(buf1, 10);
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender) {
buf2[0] = 'a';
buf2[1] = 'b';
buf2[2] = 'c';
buf2[3] = 'd';
buf2[4] = 'e';
buf2[5] = 'f';
buf2[6] = 'g';
buf2[7] = 'h';
buf2[8] = 'i';
buf2[9] = 'j';
buf2[10] = 0x00;
ComPort2->Write(buf2, 10);
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::ComPort2RxChar(TObject *Sender, int Count) {
AnsiString Str;
Str.SetLength(Count);
ComPort2->Read(&Str[1], Count);
Memo2->Lines->Add(Str);
}
// ---------------------------------------------------------------------------
void __fastcall TForm1::ComPort1RxChar(TObject *Sender, int Count)
{
AnsiString Str;
Str.SetLength(Count);
ComPort1->Read(&Str[1], Count);
Memo1->Lines->Add(Str);
}
//---------------------------------------------------------------------------
|
|