+ -
当前位置:首页 → 问答吧 → 利用MSCOMM与单片机通讯,调不通

利用MSCOMM与单片机通讯,调不通

时间:2011-11-12

来源:互联网

哪位高手帮看一下
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, MSCommLib_TLB, StdCtrls;

type
  TForm1 = class(TForm)
  Memo1: TMemo;
  Button1: TButton;
  Button2: TButton;
  MSComm1: TMSComm;
  procedure Button1Click(Sender: TObject);
  procedure FormCreate(Sender: TObject);
  procedure Button2Click(Sender: TObject);
  procedure mscomm1comm(Sender: TObject);
  private
  { Private declarations }
  public
  { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
mscomm1.PortOpen:=true;
button1.Enabled:=false;
button2.Enabled:=true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
mscomm1.InBufferCount:=0;
{mscomm1.InBufferCount:=1; }
mscomm1.InputLen:=0;
mscomm1.RThreshold:=1;
mscomm1.CommPort:=2;
mscomm1.Settings:='9600,n,8,1';
button2.Enabled:=false;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
mscomm1.portopen:=false;
button1.Enabled:=true;
button2.Enabled:=false;
end;

procedure TForm1.mscomm1comm(Sender: TObject);
var
  restr:olevariant;
begin
  memo1.text:='1200';
  if mscomm1.commevent=2 then
  begin
  restr:=mscomm1.input;
  memo1.text:=memo1.text+restr;
  end;
end;
end.

作者: WYS_2000   发布时间: 2011-11-12

调试不通是指没反应?

作者: wangwei244157887   发布时间: 2011-11-13

热门下载

更多