求助!!用delphi实现串口通信 点击:1304 | 回复:5



woaixgll

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:3帖 | 3回
  • 年度积分:0
  • 历史总积分:13
  • 注册:2005年4月19日
发表于:2005-04-19 10:58:00
楼主
我毕设要用delphi编一个串口通信的程序,我看了好些书,编了一个,可结果出不来,我用的是mscomm控件,只要能实现简单的收发数即可。 我把我的源码法上来,希望各位高手指点一二,小妹我感激不尽!!! interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Edit2: TEdit; Button1: TButton; Memo1: TMemo; Memo2: TMemo; Label3: TLabel; Label4: TLabel; Button2: TButton; Button3: TButton; MSComm1: TMSComm; procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure MSComm1Comm(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin mscomm1.commport:=2; mscomm1.settings:='9600,n,8,1'; mscomm1.inputlen:=0; mscomm1.inbuffercount:=0; mscomm1.portopen:=true; mscomm1.rthreshold:=1; mscomm1.sthreshold:=1; mscomm1.InBufferSize :=1024; mscomm1.OutBufferSize :=1024; end; procedure TForm1.Button2Click(Sender: TObject); begin mscomm1.rtsenable:=true; end; procedure TForm1.Button3Click(Sender: TObject); begin mscomm1.dtrenable:=true; end; procedure TForm1.Button1Click(Sender: TObject); begin mscomm1.portopen:=false; mscomm1.dtrenable:=false; mscomm1.rtsenable:=false; close; end; procedure TForm1.MSComm1Comm(Sender: TObject); var re:olevariant; se:olevariant; begin case mscomm1.CommEvent of comevsend: begin se:=mscomm1.Input ; se:=memo1.Text +se; end; comevreceive: begin re:=mscomm1.Output ; memo2.Text :=memo2.Text +re; end; end; end; end. 这个程序收数部分我试了不灵,发数的没试,估计也不灵,希望大家多多指点,拜托了!!! 也可以把源码发到我的邮箱中:woaixgll@sina.com.cn 再次万分感谢!!!



wzping

  • 精华:0帖
  • 求助:0帖
  • 帖子:13帖 | 117回
  • 年度积分:0
  • 历史总积分:184
  • 注册:2001年12月07日
发表于:2005-04-19 11:07:00
1楼
采用其它的串口通讯组件啦! SPCOM不错的啊!

GaryLin

  • 精华:0帖
  • 求助:0帖
  • 帖子:4帖 | 1186回
  • 年度积分:0
  • 历史总积分:1263
  • 注册:2003年4月15日
发表于:2005-04-19 15:09:00
2楼
如何用Delphi开发串口通信程序 http://www.gjwtech.com/scomm/scdelphiserialcomm.htm Delphi中串口通信的实现 http://www.ccw.com.cn/htm/app/aprog/01_1_8_4.asp 用DELPHI开发串口通信软件 http://it.enorth.com.cn/system/2001/02/21/000007750.shtml

天下草民

  • 精华:0帖
  • 求助:0帖
  • 帖子:107帖 | 1044回
  • 年度积分:0
  • 历史总积分:1477
  • 注册:2003年10月28日
发表于:2005-04-20 10:40:00
3楼
我做过 qq:10815405 有需要的话,免费赠送

woaixgll

  • 精华:0帖
  • 求助:0帖
  • 帖子:3帖 | 3回
  • 年度积分:0
  • 历史总积分:13
  • 注册:2005年4月19日
发表于:2005-04-21 10:36:00
4楼
那几个程序在我刚开始学时就看到过,曾经原封不动的照搬过,但没一个灵的,于是我就结合了那几个程序自己编了一个,可还是不灵,唉,郁闷中!!!头疼中!!!

GaryLin

  • 精华:0帖
  • 求助:0帖
  • 帖子:4帖 | 1186回
  • 年度积分:0
  • 历史总积分:1263
  • 注册:2003年4月15日
发表于:2005-04-21 12:29:00
5楼
这有个 delphi5 写的简单 send/receive 程序, 可参考看看. 不知能放在这网上多久? 尽快去下载吧! 测试时, 请将 COM1 的 TX 与 RX 短接即可. http://www.freeuploader.com/download.php/c38bef774925d050cbf73909ce97e563.html

热门招聘
相关主题

官方公众号

智造工程师