全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3189
推到 Plurk!
推到 Facebook!

TComm安裝與16進制傳送接收程式

 
bt1
一般會員


發表:38
回覆:14
積分:10
註冊:2003-06-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-14 10:26:42 IP:140.124.xxx.xxx 未訂閱
本RS232的元件是由書本[c++ Builder與RS232串列通訊控制]內ch4所附的元件.    安裝方式: step1:把TComm資料夾copy到C:\Program Files\Borland\CBuilder5    step2:開啟BCB5    step3:進入Compoment--->Install Component--->在Into existing package中的Unit file name中按       Browse按鈕,設路徑為C:\Program Files\Borland\CBuilder5\TComm       選Comm.cpp     step4: 安裝完,關閉BCB5,並儲存檔案.    step5:開啟BCB5,可以在上面一排元件中的system中看到TComm元件(一個9pin的Rs232端子,下方數字1010)    setp6:安裝完成.    [運用]    開啟:  Comm1->PortOpen = true;    傳送:  Comm1->OutputByte(ByteSend);    接收:  ByteReceive=Comm1->ReadInputByte();    關閉:  Comm1->PortOpen=false;    全域變數的宣告:     DynamicArray ByteSend,ByteReceive; String rdata[255]; [範例]16進制傳送和接收 功能說明: Button1:傳送資料 Timer1:自動接收資料 //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Comm" #pragma resource "*.dfm" TForm1 *Form1; DynamicArray ByteSend,ByteReceive; String rdata[255]; long i; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Comm1->PortOpen = true; ShowMessage("Comm1已開啟"); Timer1->Enabled=true; //自動接收 } //--------------------------------------------------------------------------- void Delay(DWORD DT) { long tt; tt=GetTickCount(); while (GetTickCount()-ttProcessMessages(); if ((GetTickCount()-tt)<=0) tt=GetTickCount(); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { ByteSend.Length =4; ByteSend[0] = 0x01; ByteSend[1] = 0x03; ByteSend[2] = 0x0c; ByteSend[3] = 0x00; Comm1->OutputByte(ByteSend);//傳送出去 Delay(1000); //延遲100毫秒 //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Delay(100); //延遲100毫秒 ByteReceive=Comm1->ReadInputByte(); for(i=0;i
系統時間:2024-03-29 23:16:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!