程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Spcomm串口控件的例程

Spcomm串口控件的例程

編輯:Delphi
//串口初始化

           procedure TForm1.BitBtn3Click(Sender: TObject);
            begin
               comm1.startcomm;
            end;
              //關閉串口
            procedure TForm1.BitBtn4Click(Sender: TObject);
            begin
               comm1.StopComm;
            end;
            //發送數據
            procedure TForm1.BitBtn1Click(Sender: TObject);{var str:string;
                ch1:char;
            begin
            comm1.WriteCommData(ch,1);
            end.
            //接收數據
            procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
              BufferLength: Word);
            type   ss=array[1..500]of char ;
            var    str1:^ss;
                   i:integer;
                   s:array[0..15] of char ;
                   n:integer;
            begin
                   str1:=Buffer;
                 //s[]=('0','1','2','3'...'E')
                   for i:=0 to 9 do
                   s[i]:=chr(48+i);
                   for i:=10 to 15 do
                   s[i]:=chr(55+i);
                   for i:=1 to bufferlength do
                   begin
                   n:=ord(str1^[i]);
                   listbox1.Items.add(
                             inttostr(listbox1.Items.Count+1)
                           &n

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved