国产毛片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
快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲综合五月 | 成都4片p高清完整版在线观看 | 国产精品久久久一区二区三区 | 一级欧美片magnet | 国产三级在线 | 亚洲高清一区二区三区久久 | 男人天堂网在线播放 | www.色.con| 天天干天天操天天爽 | 国产资源免费 | 国产黄色小视频网站 | 日本高清www视频在线观看 | 亚洲欧美在线视频 | 日韩精品一区二区三区中文字幕 | 两个人免费观看高清视频韩国 | 香蕉视频一区二区 | 家庭教师 | 人操人摸| 黄色免费网站在线观看 | 福利社区在线观看 | 麻豆md传媒新剧国产在线 | 亚洲欧美中文字幕高清在线一 | 成人香蕉 | 不卡视频在线播放 | 国产麻豆va精品视频 | 伊人青青久 | 国产美女久久 | 国产精品极品美女自在线观看免费 | 国产高清一级毛片 | 免费高清欧美大片在线观看 | 手机日韩看片 | 亚洲国内精品自在线影视 | 视频一区二区三区在线 | 欧美精品成人一区二区视频一 | 九九热re| 在线日本看片免费人成视久网 | 香蕉视频在线观看网站 | 色狠狠一区二区三区香蕉蜜桃 | 亚洲第一视频在线播放 | 日日夜操 | 四虎影视永久在线精品免费 |