Try using ComPort.Read and get the readed data buffer, after you can parse it according at all that you need.
TDataPacket and TComPort wait until receiving packet
-
30-05-2022 - |
Question
i'm working on ecr software.
This software talks with hardware that has com port.
I'm programming in delphi and i'm using TComPort and TDataPacket component.
I have a problem (i think, or maybe i don't understand how tdatapacket works).
For printing a receipt i have to send to the hardware some string formatted by protocol rules.
The protocolo for printing is this:
Me: ENQ
HW: ACK
Me: STX + string + checksum(string) + ETX
HW: ACK
Me: STX + string + checksum(string) + ETX (closing string)
HW: ACK and print the receipt
I wrote this code:
procedure TForm1.Button4Click(Sender: TObject);
var
snd, ckSum: String;
checkSum : Byte;
begin
if ack = #$06 then
begin
snd := '5/1/0.00//1.000000/SALDO/';
checkSum := calcCheckSum(snd);
ckSum := formatfloat('00',checkSum);
ComPort.WriteStr(#$02 + snd + ckSum + #$03);
end;
end;
and on the datapacket on packet event this:
procedure TForm1.ComDataPacket1Packet(Sender: TObject; const Str: string);
begin
ack := Str;
end;
But if i try to print the value of ack i always have empty string, what i'm doing wrong?
No correct solution
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow