unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SPComm;
const
LabSpliter=3;
ResultSpliter=3;
type
TForm1 = class(TForm)
Comm1: TComm;
Memo1: TMemo;
btOpen: TButton;
btClose: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
Edit1: TEdit;
Edit2: TEdit;
Label6: TLabel;
Label7: TLabel;
Edit3: TEdit;
Label8: TLabel;
Label9: TLabel;
Edit4: TEdit;
Label10: TLabel;
Edit5: TEdit;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure btOpenClick(Sender: TObject);
procedure btCloseClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Comm1ReceiveData(Sender: TObject
Buffer: Pointer;
BufferLength: Word);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
Test : boolean;
Lab_num,Assay,Result : String
// 实验号 , 实验项目 , 结果
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
viewstring:string;
sbuf:array[0..16] of byte;
rbuf:array[0..1000] of byte;
implementation
{$R *.dfm}
procedure senddata;
var
i:integer;
commflg:boolean;
begin
viewstring:= '';
commflg:=true;
for i:=1 to 6 do begin
if not Form1.comm1.writecommdata(@sbuf,1) then begin
commflg:=false;
break;
end;
//发送时字节间的延时
sleep(2);
viewstring:=viewstring + inttohex(sbuf,2) +'' ;
end;
viewstring:='发送' + viewstring;
Form1.memo1.lines.add(viewstring);
Form1.memo1.lines.add('');
if not commflg then messagedlg('发送失败 !' ,mterror,[mbyes],0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.ItemIndex := 0;
ComboBox2.ItemIndex := 6;
ComboBox3.ItemIndex := 2;
ComboBox4.ItemIndex := 3;
ComboBox5.ItemIndex := 0;
Memo1.Text := '';
Test := False;
Lab_num := '';
Assay := '';
Result := ''
// 实验号 , 实验项目 , 结果
end;
procedure TForm1.btOpenClick(Sender: TObject);
begin
comm1.BaudRate := StrToInt(ComboBox2.items.Strings[ComboBox2.ItemIndex]);
comm1.CommName := ComboBox1.items.Strings[ComboBox1.ItemIndex];
case ComboBox5.ItemIndex of
0:comm1.StopBits := _1;
1:comm1.StopBits := _2;
end;
case ComboBox4.ItemIndex of
0:comm1.ByteSize := _5;
1:comm1.ByteSize := _6;
2:comm1.ByteSize := _7;
3:comm1.ByteSize := _8;
end;
case ComboBox3.ItemIndex of
0:comm1.Parity := Even;
1:comm1.Parity := Mark;
2:comm1.Parity := None;
3:comm1.Parity := Odd;
4:comm1.Parity := Space;
end;
comm1.StartComm;
btOpen.Enabled := False;
btClose.Enabled := True;
edit4.Text := '';
end;
procedure TForm1.btCloseClick(Sender: TObject);
begin
comm1.StopComm;
btOpen.Enabled := True;
btClose.Enabled := False;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
begin
sbuf[1]:=byte($f0)
//帧头
sbuf[2]:=byte($01)
//命令号
sbuf[3]:=byte($ff);
sbuf[4]:=byte($ff);
sbuf[5]:=byte($01);
sbuf[6]:=byte($f0)
//帧尾
senddata;//调用发送函数
end;
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject
Buffer: Pointer;
BufferLength: Word);
var
ss:string;
i,j,l:integer;
begin
move(buffer,pchar(@rbuf)^,bufferlength);
sbuf[0]:=byte($55)
//帧头
comm1.writecommdata(@sbuf[0],1);
setlength(ss,bufferlength);
move(buffer^,pchar(ss)^,bufferlength);
memo1.lines.add(ss);
memo1.lines.add('');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Text := '';
end;
procedure TForm1.Button3Click(Sender: TObject);
var
ss:string;
i,j,l,k:integer;
begin
j := 0;
l := 0;
ss:='4R|1|^^^hCG65664jhkhj|83.5|mIU/mL|1/1^5000/5000|N|N|F||h|20030927211337|20030927215438|C2';
for i:= 1 to length(ss) do begin
if copy(ss,i,1)='^' then begin
l:= l+1;
j:=i+1;
end;
if (l=3) and (copy(ss,i,1)='|') then
break;
end;
end;
end.