unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, OleCtrls, MSCommLib_TLB;
type
TForm1 = class(TForm)
MSComm1: TMSComm;
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Label1: TLabel;
Timer1: TTimer;
Label2: TLabel;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
output:variant;
volt:byte;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if button1.caption='开始'
then
begin
timer1.Interval :=strtoint(edit1.Text);
volt:=0;
timer1.Enabled :=true;
button1.Caption :='停止';
end
else
begin
timer1.Enabled :=false;
button1.Caption :='开始';
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
output:= VarArrayCreate([1,2], varbyte);
output[1]:=0;
output[2]:=volt;
mscomm1.Output :=output;
volt:=volt+1;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
output:= vararraycreate([1,2],varbyte);
output[1]:=00;
output[2]:=strtoint('$'+edit2.Text );
mscomm1.Output:=output;
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var
input:array of byte;
i:integer;
begin
//showmessage('aaaa');
input:=mscomm1.Input;
//showmessage(inttostr(high(input)));
begin
for i:=0 to high(input)
do
memo1.lines.add(inttostr(input));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if not mscomm1.PortOpen
then mscomm1.PortOpen :=true;
end;
end.