The unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SPComm StdCtrls;
Type
TForm1=class (TForm)
For: TButton;
Button2: TButton;
Comm1: TComm;
Memo1: TMemo;
Procedure Button2Click (Sender: TObject);
Procedure Button1Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
The end;
Var
Form1: TForm1;
Comm1: TComm;
Memo1: TMemo;
Viewstring: string;
I: integer;
Rbuf, sbuf: an array of byte [1.. 256];
Implementation
{$R *. DFM}
Procedure senddata publishes the event;
Var
I: integer;
Commflg: Boolean;
The begin
Viewstring:=';
Commflg:=true;
For I:=1 to 6 do
The begin
If not comm1. Writecommdata (@ sbuf [I], 1) then
The begin
Commflg:=false;
break;
The end;
//send time delay between the bytes
Sleep (2);
Viewstring:=viewstring + inttohex (sbuf [I], 2) + ";
The end;
Viewstring:='send' + viewstring;
Memo1. Lines. The add (viewstring);
Memo1. Lines. The add (");
If not commflg then messagedlg (' failure ', mterror, [mbyes], 0).
The end;
Procedure TForm1. Button2Click (Sender: TObject);
The begin
Sbuf [1] :=byte ($f0);//frame head
Sbuf [2] :=byte ($01); No.//command
Sbuf [3] :=byte ($ff);
Sbuf [4] :=byte ($ff);
Sbuf [5] :=byte ($01);
Sbuf [6] :=byte ($f0);//frame tail
Senddata publishes the event;//send a function called
The end;
Procedure TForm1. Button1Click (Sender: TObject);
The begin
Comm1. StopComm;
Comm1. StartComm;
The end;
End.
Just a small example
CodePudding user response:
The code itself is no problem. Want to see other places!CodePudding user response:
This error is often a pointer not allocate memory or cross-border access,CodePudding user response:
You see a serial port is already occupied by other program to openCodePudding user response: