首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

spcomm发送接收数据有关问题

2012-03-01 
spcomm发送接收数据问题Delphi(Pascal) codeprocedure TForm1.Comm1ReceiveData(Sender: TObject Buffer:

spcomm发送接收数据问题
Delphi(Pascal) code
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
 var
  RecData: string;
begin
  SetLength(RecData, BufferLength);
  move(Buffer^, PChar(@RecData[1])^, BufferLength);
  memo2.Lines.Add('已接收'+ inttostr(BufferLength)+'字节数据');
  memo2.Lines.Add(RecData);//添加接收到的内容
  memo2.Invalidate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Comm1.StartComm;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  Comm1.WriteCommData(Pchar(Memo1.Text),Length(Memo1.Text));
 if Comm1.WriteCommData(Pchar(Memo1.Text), 3) then
  memo1.Lines.Add(Pchar(Memo1.Text))
  else
  memo1.Lines.Add('数据发送错误!')
end;


为什么接收不了数据,由于没有物理硬件,我用的是SUDT SerialNull,打开了10个虚拟端口 ,自发自收
COMMNAME 是COM3

单步调试跟本就没能进入ReceiveData中,进入了TComm.CommWndProc,是哪出了问题

[解决办法]
我对串口通讯还算熟悉。

分,已经成为回答你贴子的障碍。
[解决办法]
我也不懂,帮顶吧。
[解决办法]
用实际的COM1口来测试看看

将COM1口的2,3号针跳线(联在一次)

COM1口发 COM1口收

触发了TComm.CommWndProc,你发送也是COM的一个消息

热点排行