Z
zzs3842
Unregistered / Unconfirmed
GUEST, unregistred user!
功能:
向服务端发送指令,收到正确的数据,就继续发指令,收到正确的数据就继续发指令,。。。。。。 直到返回的数据为某一个数据 就结束。
问题: 中间有时发送指令后 没有数据返回。不知怎么处理。
源代码如下:请指点
procedure TForm1.Button1Click(Sender: TObject);
begin
tcpclient1.RemoteHost := '192.168.0.178';
tcpclient1.RemotePort := '3003';
sendcommand('15', '');
end;
procedure TForm1.sendcommand(command, data: string);
begin
try
if tcpclient1.Connected = false then tcpclient1.Connect;
if tcpclient1.Connected then
begin
TcpClient1.Sendln(HexStrToStr('06' + leijiahe('00', command, data) + '07'));
memo1.Lines.Add(HexStrToStr('06' + leijiahe('00', command, data) + '07'));
tcpclient1.Receiveln;
end;
finally
//tcpclient1.Disconnect;
end;
end;
procedure TForm1.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
var DataLen: Integer);
var str: string;
k, i: integer;
begin
str := strtohexstr1(Buf);
memo1.Lines.Add(str);
k := hexstrtoint(copy(str, 11, 4));
case k of
48 + 51: begin
tcpclient1.Disconnect;
showmessage('读取刷卡记录结束!');
end;
48 + 48:
begin
i := hexstrtoint1(copy(str, 7, 4));
case i of
49 * 100 + 53: begin
memo1.Lines.Add(str);
sendcommand('15', '');
end;
end;
end;
end;
end;
procedure TForm1.TcpClient1Error(Sender: TObject; SocketError: Integer);
begin
// TcpClient1.Disconnect;
memo1.Lines.Add('错误:' + inttostr(SocketError));
end;
向服务端发送指令,收到正确的数据,就继续发指令,收到正确的数据就继续发指令,。。。。。。 直到返回的数据为某一个数据 就结束。
问题: 中间有时发送指令后 没有数据返回。不知怎么处理。
源代码如下:请指点
procedure TForm1.Button1Click(Sender: TObject);
begin
tcpclient1.RemoteHost := '192.168.0.178';
tcpclient1.RemotePort := '3003';
sendcommand('15', '');
end;
procedure TForm1.sendcommand(command, data: string);
begin
try
if tcpclient1.Connected = false then tcpclient1.Connect;
if tcpclient1.Connected then
begin
TcpClient1.Sendln(HexStrToStr('06' + leijiahe('00', command, data) + '07'));
memo1.Lines.Add(HexStrToStr('06' + leijiahe('00', command, data) + '07'));
tcpclient1.Receiveln;
end;
finally
//tcpclient1.Disconnect;
end;
end;
procedure TForm1.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
var DataLen: Integer);
var str: string;
k, i: integer;
begin
str := strtohexstr1(Buf);
memo1.Lines.Add(str);
k := hexstrtoint(copy(str, 11, 4));
case k of
48 + 51: begin
tcpclient1.Disconnect;
showmessage('读取刷卡记录结束!');
end;
48 + 48:
begin
i := hexstrtoint1(copy(str, 7, 4));
case i of
49 * 100 + 53: begin
memo1.Lines.Add(str);
sendcommand('15', '');
end;
end;
end;
end;
end;
procedure TForm1.TcpClient1Error(Sender: TObject; SocketError: Integer);
begin
// TcpClient1.Disconnect;
memo1.Lines.Add('错误:' + inttostr(SocketError));
end;