type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; function com_init(com:Integer; baud:Dword):Boolean;stdcall;external 'api_com.dll'; function com_rest:Boolean;stdcall;external 'api_com.dll'; function com_send(buf:PChar; len:Integer):Boolean;stdcall;external 'api_com.dll';
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin Com_init(1,2400); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Com_rest; end;
procedure TForm1.Button2Click(Sender: TObject); var PDStr:string; begin PDStr:=Chr(27)+Chr(81)+Chr(65)+'1234.56'+Chr(13); if com_send(Pchar(PDStr),Length(PDStr)) then begin Label1.Caption :='已经发送命令'; end else begin Label1.Caption :='发送失败'; end;
PDStr:= Chr(27)+Chr(115)+'2'; if com_send(Pchar(PDStr),Length(PDStr)) then begin Label1.Caption :='已经发送命令'; end else begin Label1.Caption :='发送失败'; end;