预览加载中,请您耐心等待几秒...
1/5
2/5
3/5
4/5
5/5

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Delphi7串口通信(spcomm控件)实例 最近在用delphi7做串口通信,网上找了很多例程,复制粘贴运行就没有能通过的,再次鄙视一下列位先行者,你们帮人倒是帮到底啊,没一个是拿过来能用的,太坑了,在N天的努力下(鄙人比较笨)终于通过串口接收到数据,希望给后来人予以帮助,程序如下: 功能简介 功能比较简单,只是从串口接收单片机发送的数据,给memo1 unitUnit1; interface uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,SPComm,StdCtrls; type TForm1=class(TForm) Button1:TButton; Button2:TButton; Comm1:TComm; Memo1:TMemo; procedureButton1Click(Sender:TObject); procedureButton2Click(Sender:TObject); procedureComm1ReceiveData(Sender:TObject;Buffer:Pointer;BufferLength:Word); procedureComm1ModemStateChange(Sender:TObject;ModemEvent:Cardinal); private {Privatedeclarations} public {Publicdeclarations} end; var Form1:TForm1; viewstring:string; i:integer; rbuf,sbuf:array[1..16]ofbyte; implementation {$R*.dfm} procedureTForm1.Button1Click(Sender:TObject); begin Comm1.OnReceiveData:=Comm1ReceiveData; comm1.StartComm; end; //打开串口 procedureTForm1.Button2Click(Sender:TObject); begin comm1.StopComm; end; //关闭串口 procedureTForm1.Comm1ReceiveData(Sender:TObject;Buffer:Pointer;BufferLength:Word); var i:integer; begin viewstring:=''; move(buffer^,pchar(@rbuf)^,bufferlength); fori:=1tobufferlengthdo viewstring:=viewstring+inttohex(rbuf[i],2)+''; viewstring:='接收'+viewstring; memo1.lines.add(viewstring); memo1.lines.add(''); end; //接收数据 procedureTForm1.Comm1ModemStateChange(Sender:TObject; ModemEvent:Cardinal); begin end; end. 运行测试,顺利通过,接收到单片机发送的数据,感谢百度好友的帮助。