我用idtcpserver组件接受传入的信息,但是bRecBuffer的信息如果字节比较多(比如184个字节),就会出现数据不准的现象(184个字节总是中间缺少2个字节)。代码如下:
procedure TfrmNetCopyGPRS.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t:string;
ilen:integer;
bRecBuffer : TrecBuffer;
i:integer;
p:pointer;
dataarr:tDataarr;
begin
aThread.Connection.ReadFromStack;
ilen := AThread.Connection.InputBuffer.Size; if ilen<>0 then
begin
//memo1.Lines.Add('刚刚接收了'+inttostr(ilen)+'个数据'); AThread.Connection.ReadBuffer(bRecBuffer,ilen);
UnitGPRSProtocol.ConvertRecBuffer(brecbuffer,dataarr,ilen);
if (bRecBuffer[8]=5) and (bRecBuffer[10]=$20) then
begin
if(UnitGPRSProtocol.CompareCheckCode(dataarr,13)) and
UnitGPRSProtocol.LeaderCharRight(dataarr,13) then AThread.Connection.WriteBuffer(bRecBuffer,13);
addToActiveCenterlist(bRecBuffer[9],AThread);
exit; //退出来
end
else
begin
UnitGPRSProtocol.TreateRetData(iProtocoltype,G_FunctionCode,dataarr,self.edtValue.Text);
end;
end后来我发现问题了,但是不知道怎么解决,我发现我收到的字节是08(退格键的ascii是08)的时候,08的前一个字节和08就会消失,例如 发送的是 01,00,08,00,00,00,00但是我接受的却是01,00,00,00,00,我接受的是单片机通过gprs模块发送的信息,请问我如何解决整个问题
procedure TfrmNetCopyGPRS.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t:string;
ilen:integer;
bRecBuffer : TrecBuffer;
i:integer;
p:pointer;
dataarr:tDataarr;
begin
aThread.Connection.ReadFromStack;
ilen := AThread.Connection.InputBuffer.Size; if ilen<>0 then
begin
//memo1.Lines.Add('刚刚接收了'+inttostr(ilen)+'个数据'); AThread.Connection.ReadBuffer(bRecBuffer,ilen);
UnitGPRSProtocol.ConvertRecBuffer(brecbuffer,dataarr,ilen);
if (bRecBuffer[8]=5) and (bRecBuffer[10]=$20) then
begin
if(UnitGPRSProtocol.CompareCheckCode(dataarr,13)) and
UnitGPRSProtocol.LeaderCharRight(dataarr,13) then AThread.Connection.WriteBuffer(bRecBuffer,13);
addToActiveCenterlist(bRecBuffer[9],AThread);
exit; //退出来
end
else
begin
UnitGPRSProtocol.TreateRetData(iProtocoltype,G_FunctionCode,dataarr,self.edtValue.Text);
end;
end后来我发现问题了,但是不知道怎么解决,我发现我收到的字节是08(退格键的ascii是08)的时候,08的前一个字节和08就会消失,例如 发送的是 01,00,08,00,00,00,00但是我接受的却是01,00,00,00,00,我接受的是单片机通过gprs模块发送的信息,请问我如何解决整个问题
一块去食堂吧,
要不吃包子,
呵呵!