delphi7 indy10怎么发送十六进制字符串中带的#$00 15
procedureTForm1.Button5Click(Sender:TObject);varbuf:array[0..3]ofChar;beginIdUDPClien...
procedure TForm1.Button5Click(Sender: TObject);
var
buf:array[0..3] of Char;
begin
IdUDPClient1.Host:=IPEdit5.IPString;
IdUDPClient1.Port:=StrToInt(Edit8.Text);
buf[0]:=#$11;
buf[1]:=#$05;
buf[2]:=#$00;
buf[3]:=#$11;
IdUDPClient1.send(buf);
end;
这样发送buf[2]的#$00就认为字符串结束了,怎么发送指定长度的字符串? 展开
var
buf:array[0..3] of Char;
begin
IdUDPClient1.Host:=IPEdit5.IPString;
IdUDPClient1.Port:=StrToInt(Edit8.Text);
buf[0]:=#$11;
buf[1]:=#$05;
buf[2]:=#$00;
buf[3]:=#$11;
IdUDPClient1.send(buf);
end;
这样发送buf[2]的#$00就认为字符串结束了,怎么发送指定长度的字符串? 展开
2个回答
展开全部
一般来说,一个长报文,首先用ASCII码编写内容,然后将至转化为HEX报文,而且HEX的内容要与ASCII一致。如ASCII报文’00 10 20 01 00 0C 00 0B 00 00 00 00 ',用INDY发送后抓包HEX显示的内容要一致,’00 10 20 01 00 0C 00 0B 00 00 00 00 ',这样报文就可以用STRING区编写了。最后转换为一致的TIDBYTES,就可以用SENDBUFFER发送。
function TForm1.get_bytes(SHEX: string): TIdBytes;
var
iByte: Byte;
sTemp: String;
hexBuf:array[0..1023] of byte;
iStart, iCount, idex: Integer;
begin
idex := 0;
iStart := 1;
fillchar(hexBuf, sizeOf(hexBuf), #0);
iCount := length(SHEX) + 1;
while iStart < iCount do
begin
sTemp := SHEX[iStart];
iStart := iStart + 1;
if iStart >= iCount then Break;
sTemp := sTemp + SHEX[iStart];
iByte :=HexStrToByte(sTemp);
// ShowMessage(IntToHex(iByte, 2));
hexBuf[idex] := iByte;
idex := idex + 1;
iStart := iStart + 1;
end;
// Move(hexbuf[0],hexbufidbytes[0],SizeOf(hexBuf));
// Move();
result:=RawToBytes(hexbuf,12);
end;
function TForm1.HexStrToByte(HesStr: String): Byte;
var
iLen: Integer;
begin
Result := 0;
iLen := length(HesStr);
if iLen <> 2 then Exit;
If not (HesStr[1] in ['0'..'9', 'A', 'B', 'C', 'D', 'E', 'F',
'a', 'b', 'c', 'd', 'e', 'f']) Then Exit;
If not (HesStr[2] in ['0'..'9', 'A', 'B', 'C', 'D', 'E', 'F',
'a', 'b', 'c', 'd', 'e', 'f']) Then Exit;
Result := StrToInt('$' + HesStr);
end;
function TForm1.get_bytes(SHEX: string): TIdBytes;
var
iByte: Byte;
sTemp: String;
hexBuf:array[0..1023] of byte;
iStart, iCount, idex: Integer;
begin
idex := 0;
iStart := 1;
fillchar(hexBuf, sizeOf(hexBuf), #0);
iCount := length(SHEX) + 1;
while iStart < iCount do
begin
sTemp := SHEX[iStart];
iStart := iStart + 1;
if iStart >= iCount then Break;
sTemp := sTemp + SHEX[iStart];
iByte :=HexStrToByte(sTemp);
// ShowMessage(IntToHex(iByte, 2));
hexBuf[idex] := iByte;
idex := idex + 1;
iStart := iStart + 1;
end;
// Move(hexbuf[0],hexbufidbytes[0],SizeOf(hexBuf));
// Move();
result:=RawToBytes(hexbuf,12);
end;
function TForm1.HexStrToByte(HesStr: String): Byte;
var
iLen: Integer;
begin
Result := 0;
iLen := length(HesStr);
if iLen <> 2 then Exit;
If not (HesStr[1] in ['0'..'9', 'A', 'B', 'C', 'D', 'E', 'F',
'a', 'b', 'c', 'd', 'e', 'f']) Then Exit;
If not (HesStr[2] in ['0'..'9', 'A', 'B', 'C', 'D', 'E', 'F',
'a', 'b', 'c', 'd', 'e', 'f']) Then Exit;
Result := StrToInt('$' + HesStr);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询