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

查看: 5404|回復: 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
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩一区二区三区在线播放 | 欧美天天综合 | 67194国产| 四虎精品在线观看 | 四虎国产精品永久在线 | 亚洲第一区二区快射影院 | 九七在线 | 亚洲不卡av不卡一区二区 | 免费网站看黄 | 特片网在线观看 | 99re国产精品视频首页 | 久久青视频 | 99久热只有精品视频免费看 | 一级毛片成人免费看免费不卡 | 日韩不卡一区 | 综合久久久久久久 | 亚洲日本在线观看视频 | 99免费在线观看 | 亚州 色 图 综合 | 在线观看噜噜噜私人影院 | 在线好吊色视频98gao | 四虎影永久在线观看精品 | 亚洲视频一区二区在线观看 | 无遮挡h肉动漫在线观看 | 西野翔在线播放 | 欧美黑人hd | 国产网红在线 | 欧美视频免费在线观看 | 99热在线国产| 香蕉视频一区二区三区 | 国产午夜亚洲精品一级在线 | 日韩欧美亚洲国产高清在线 | 欧美日本一二三区 | 国产成人在线网站 | 精品一区二区三区高清免费观看 | 久久成人黄色 | 视频在线色 | 伊人狼人在线 | 日韩欧美一区二区三区免费看 | 一区二区免费在线观看 | 精品在线一区二区三区 |