I am using the VaComm component to generate simulated data from a hardware datalogger. This outputs numbers in a hex format. When I try to generate the hex value 00 the VaComm component writes 20 (a space).
The integer 342 is output by the datalogger as 56 01 00 00 in hex. I can generate this using the IntToHex command which returns the string "00000156" in this case.
I then extract the pairs of digits and use hextobin(pchar()) to convert the substrings to a binary value.
This works fine for the 56 and 01 values but the 00 values actually appear as 20 (spaces) when I monitor the output. i.e. I see 56 01 20 20
Can anyone tell me what I am doing wrong? Is there a simpler (or at least better) way to do this?
procedure TForm1.OpVal(value, digits : LongInt);
var
midstr, opstr : string;
i, x : integer;
sBuffer : char;
begin
opstr := inttohex(value,digits);
for i := digits div 2 downto 1 do
begin
midstr := copy(opstr,(i * 2)-1,2);
hextobin(pchar(midstr),sbuffer,2);
vacomm1.WriteBuf(sbuffer,1);
end;
end;