国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品

查看: 5425|回復: 2
打印 上一主題 下一主題

串口控件SPComm多方法使用例程

[復制鏈接]
跳轉到指定樓層
樓主
發表于 2009-4-2 23:52:00 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
關鍵詞: SPComm , 串口 , 控件 , 例程
重點注意:本例程一定要將串口的2,3腳短聯做自發自收演示)
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  str: string;
begin
  str := '';
  for i := 0 to 2047 do
  begin
    str := str + Char(i and $ff);//所有字符0x00~0xff
  end;
  Comm1.PortOpen := true;//打開串口(注意:本例將串口的2,3腳短聯做自發自收演示)
  Comm1.Output := str;//發送2048個字符到串口
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: PAnsiChar;//舊事件處理方法用Buffer: Pointer
  BufferLength: Word);
var
  i: integer;
  str: string;
begin                                      
  Memo1.Lines.Add('SPCOMM控件改造應用方法一:(String)');
  SetString(str, Buffer, BufferLength);//從串口接收BufferLength個字節
  if Length(str) <> BufferLength then Exit;
  for i := 0 to BufferLength - 1 do
  begin
    if (i and $f) = 0 then
    begin
      Buffers := inttohex(i, 4) + ': ';
    end;
    if (i and $ff) = Byte(str[i + 1]) then//str[i]從str[1]開始
      Buffers := Buffers + '0x' + inttohex(Byte(str[i + 1]), 2) + ' '
    else //接收錯誤顯示
      Buffers := Buffers + '**/' + inttohex(Byte(str[i + 1]), 2) + ' ';
    if (i and $f) = $f then
    begin
      Memo1.Lines.Add(Buffers);//輸出一行顯示數據
      Buffers := '';
    end;
  end;
  Memo1.Lines.Add('');
  Memo1.Lines.Add('SPCOMM控件改造應用方法二:(Array)');
  for i := 0 to BufferLength - 1 do
  begin
    if (i and $f) = 0 then
    begin
      Buffers := inttohex(i, 4) + ': ';
    end;
    if (i and $ff) = Byte(Buffer[i]) then//Buffer[i]從Buffer[0]開始
      Buffers := Buffers + '0x' + inttohex(Byte(Buffer[i]), 2) + ' '
    else //接收錯誤顯示
      Buffers := Buffers + '**' + inttohex(Byte(Buffer[i]), 2) + ' ';
    if (i and $f) = $f then
    begin
      Memo1.Lines.Add(Buffers);//輸出一行顯示數據
      Buffers := '';
    end;
  end;
  Memo1.Lines.Add('');
  Memo1.Lines.Add('SPCOMM控件改造應用方法三:(Pointer)');
  for i := 0 to BufferLength - 1 do
  begin
    if (i and $f) = 0 then
    begin
      Buffers := inttohex(i, 4) + ': ';
    end;
    if (i and $ff) = Byte((Buffer + i)^) then//Buffer+i從Buffer開始
      Buffers := Buffers + '0x' + inttohex(Byte((Buffer + i)^), 2) + ' '
    else //接收錯誤顯示
      Buffers := Buffers + '**' + inttohex(Byte((Buffer + i)^), 2) + ' ';
    if (i and $f) = $f then
    begin
      Memo1.Lines.Add(Buffers);//輸出一行顯示數據
      Buffers := '';
    end;
  end;
  Memo1.Lines.Add('');
  Memo1.Lines.Add('SPCOMM控件改造應用方法四:(Pointer)');
  for i := 0 to BufferLength - 1 do
  begin
    if (i and $f) = 0 then
    begin
      Buffers := inttohex(i, 4) + ': ';
    end;
    if (i and $ff) = Byte(Buffer^) then
      Buffers := Buffers + '0x' + inttohex(Byte(Buffer^), 2) + ' '
    else //接收錯誤顯示
      Buffers := Buffers + '**' + inttohex(Byte(Buffer^), 2) + ' ';
    if (i and $f) = $f then
    begin
      Memo1.Lines.Add(Buffers);//輸出一行顯示數據
      Buffers := '';
    end;
    Inc(Buffer, SizeOf(Char));//移動字符指針
  end;
end;
沙發
發表于 2010-8-5 18:39:29 | 只看該作者
樓主也搞DELPHI
板凳
發表于 2011-2-12 15:58:52 | 只看該作者
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日本高清视频一区二区 | 国产极品美女视频 | 好男人www免费高清视频在线 | 男人天堂网在线视频 | 国产骚片 | 国产黄mmd在线观看免费 | 亚洲黄色官网 | 草莓视频免费下载观看丝瓜 | 四虎影音先锋 | 欧美一级高清片免费一级 | 最新国产在线播放 | 成年人网站在线 | 亚洲综合激情在线影院 | 91精品国 | 美女视频黄的免费看网站 | 亚洲一区日韩二区欧美三区 | 一级黄色片在线看 | 欧美亚洲国产精品久久蜜芽 | 国产ppp在线视频在线观看 | 国产a久久精品一区二区三区 | 毛片网在线| 国产精品99久久免费观看 | 久久er国产精品免费观看1 | 国产欧美日韩高清专区手机版 | 伊人艹 | 亚洲精品一卡2卡3卡三卡四卡 | 亚洲黄色片在线观看 | 久久美女福利视频 | 四虎影院在线播放 | 午夜网页 | 91国在线高清视频 | 亚洲精品第一卡2卡3卡4卡5卡 | 四虎精品免费永久在线 | 麻豆国产高清精品国在线 | 日本激情视频网站 | 青青青在线观看视频免费播放 | 一级做a爰毛片 | 小叔用力插插深点 | 天美麻豆国产传媒免费视频 | 999视频精品全部免费观看 | 欧美成人三级一区二区在线观看 |