教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 政务民生 >

delphi7串口通信(spcomm控件)实例

来源:网络收集 时间:2026-07-22
导读: Delphi7串口通信(spcomm控件)实例 最近在用delphi7做串口通信,网上找了很多例程,复制粘贴运行就没有能通过的,再次鄙视一下列位先行者,你们帮人倒是帮到底啊,没一个是拿过来能用的,太坑了,在N天的努力下(鄙人比较笨)终于通过串口接收到数据,希望

Delphi7串口通信(spcomm控件)实例

最近在用delphi7做串口通信,网上找了很多例程,复制粘贴运行就没有能通过的,再次鄙视一下列位先行者,你们帮人倒是帮到底啊,没一个是拿过来能用的,太坑了,在N天的努力下(鄙人比较笨)终于通过串口接收到数据,希望给后来人予以帮助,程序如下: 功能简介

功能比较简单,只是从串口接收单片机发送的数据,给

memo1

unit Unit1; 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;

procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject);

procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;BufferLength: Word);

procedure Comm1ModemStateChange(Sender: TObject; ModemEvent: Cardinal); private

{ Private declarations } public

{ Public declarations } end; var

Form1: TForm1; viewstring:string; i:integer;

rbuf,sbuf:array[1..16] of byte;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject); begin

Comm1.OnReceiveData:=Comm1ReceiveData; comm1.StartComm; end; //打开串口

procedure TForm1.Button2Click(Sender: TObject); begin

comm1.StopComm; end; //关闭串口 procedure

TForm1.Comm1ReceiveData(Sender:

Buffer: Pointer;BufferLength: Word);

TObject;

var i:integer; begin viewstring:='' ;

move(buffer^,pchar(@rbuf)^,bufferlength); for i:=1 to bufferlength do

viewstring:=viewstring+ inttohex(rbuf[i],2)+'' ; viewstring:='接收'+ viewstring; memo1.lines.add(viewstring); memo1.lines.add(''); end;

//接收数据 procedure TObject;

ModemEvent: Cardinal); begin end;

TForm1.Comm1ModemStateChange(Sender:

end.

运行测试,顺利通过,接收到单片机发送的数据,感谢百度好友的帮助。

delphi7串口通信(spcomm控件)实例.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/447865.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)