频道分类

DELPHI 脉搏波9808血压计读取测试程序

作者:admin 来源: 日期:2019/4/13 11:02:01 人气: 标签:

 
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, SPComm,StrUtils;

type
  TForm1 = class(TForm)
    Comm1: TComm;
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Comm1ReceiveData(Sender: TObject; Buffer: PAnsiChar;
      BufferLength: Word);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  s:tstringlist;
  j:integer;
  function HexToDec(const AHexString: String): Integer;
implementation

{$R *.dfm}
function HexToDec(const AHexString: String): Integer;
begin
Result := StrToInt('$' + AHexString);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
comm1.StartComm;
if comm1.Handle>0 then
showmessage('打开成功')
else
showmessage('打开失败');

end;

procedure TForm1.Button2Click(Sender: TObject);
var
sbuf: array [1..8] of byte;
i:integer;
begin
 sbuf[1]:=byte($CC);
 sbuf[2]:=byte($80);
 sbuf[3]:=byte($03);
 sbuf[4]:=byte($03);
 sbuf[5]:=byte($01);
 sbuf[6]:=byte($01);
 sbuf[7]:=byte($00);
 sbuf[8]:=byte($00);      //异或校验

for i := 1 to 8 do
 if not comm1.WriteCommData(@sbuf[i],1) then
  showmessage('失败'+inttohex(sbuf[i]));
 j:=8;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
sbuf: array [1..8] of byte;
i:integer;
begin
 sbuf[1]:=byte($CC);
 sbuf[2]:=byte($80);
 sbuf[3]:=byte($03);
 sbuf[4]:=byte($03);
 sbuf[5]:=byte($01);
 sbuf[6]:=byte($02);
 sbuf[7]:=byte($00);
 sbuf[8]:=byte($03);      //异或校验

for i := 1 to 8 do
 if not comm1.WriteCommData(@sbuf[i],1) then
  showmessage('失败'+inttohex(sbuf[i]));
 j:=8;
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: PAnsiChar;
  BufferLength: Word);
var
temp:Ansistring;
i:integer;
begin
temp:=buffer;
if j>0 then
  begin
    j:=j-1;
    exit;
  end;
 for i := 1 to length(temp) do
   begin
       s.Add(inttostr(ord(temp[i])));
       memo1.Text:=memo1.Text+IntTohex(ord(temp[i]))+' ';
    end;

if s.Count=17 then
  begin
    try
    edit1.Text:=s[13];
    edit2.Text:=s[14];
    edit3.Text:=s[15];
    finally
       s.Clear;
    end;
  end
else
  if s[0]<>'170' then
    s.Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 memo1.Text:='';
 s:=tstringlist.Create;
end;

end.