Q
qngshn
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FormCreate(Sender: TObject);
begin
//Mscomm1.PortOpen:=False;
//Mscomm2.PortOpen:=False;
Mscomm1.PortOpen:=true;
Mscomm2.PortOpen:=true;
Mscomm1.InputLen:=0;
Mscomm1.RThreshold:=5;
MsComm1.InputMode:=comInputModeText;
// ReData:='';
end;
//发送数据
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s:string;
begin
Mscomm1.InBufferCount:=0;
mscomm1.InputMode:=1; // binary
mscomm2.InputMode:=1; // binary
mscomm2.RThreshold:=1;
While True do
begin
s:=edit1.Text;
MsComm1.Output:=s;
sleep(360);
Application.ProcessMessages;
end;
end;
//接收数据
procedure TForm1.MSComm2Comm(Sender: TObject);
var
s: array of string;
b: array of Byte;
v: Variant;
i: Integer;
begin
Case MsComm2.CommEvent of
2:
begin
v:=MsComm2.Input;
b:=v;
for i:=0 to length(v) do
begin
s:=b;
end;
richedit1.Lines.Add(s) ;
end;
end;
end;
begin
//Mscomm1.PortOpen:=False;
//Mscomm2.PortOpen:=False;
Mscomm1.PortOpen:=true;
Mscomm2.PortOpen:=true;
Mscomm1.InputLen:=0;
Mscomm1.RThreshold:=5;
MsComm1.InputMode:=comInputModeText;
// ReData:='';
end;
//发送数据
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s:string;
begin
Mscomm1.InBufferCount:=0;
mscomm1.InputMode:=1; // binary
mscomm2.InputMode:=1; // binary
mscomm2.RThreshold:=1;
While True do
begin
s:=edit1.Text;
MsComm1.Output:=s;
sleep(360);
Application.ProcessMessages;
end;
end;
//接收数据
procedure TForm1.MSComm2Comm(Sender: TObject);
var
s: array of string;
b: array of Byte;
v: Variant;
i: Integer;
begin
Case MsComm2.CommEvent of
2:
begin
v:=MsComm2.Input;
b:=v;
for i:=0 to length(v) do
begin
s:=b;
end;
richedit1.Lines.Add(s) ;
end;
end;
end;