Reputation: 19
My app sends NMEA strings terminated with [CR]+[LF]. The NMEA standard specifies this format (example is heading info from a gyro compass): '$HEHDT,2.0,T*2D[CR][LF]'. At the receiving end the string is discarded as incomplete. How do I append and send these characters?
Sending is straight forward with only a few lines of code (Object is Cp1tx: TIdUDPServer;):
...
Cp1tx.Active:= true;
Cp1tx.Broadcast(InStr,8051,'',IndyTextEncoding_8Bit);
Cp1tx.Active:= false;
...
Btw, I am using Delphi 10.1 Berlin.
Upvotes: 0
Views: 2530
Reputation: 19
Thanks to all of you. I think I made a fool of myself. It runs ok now no matter how I add the CRLF chars.
A historical comment: CRLF (and in that order!) was invented for use in the old, mechanical telex machines powered by a 1/2 HP motor. It took time to move the carriage back to the left position. That's why CR is send first and then LF, so all the mechanics have time to align and get ready to print the first character on the new line.
Novice telex operators learned it the hard way. Sending LF and CR and then typing text trapped the carriage on its way to the left, the type arms tangled and often the drive axle jammed or broke. Remember this was high speed transmission on astonishing 50 Baud! I spend endless hours in my service repairing broke telex machines. Well, things are different and better nowadays, but we still stick to the old CRLF convention.
Upvotes: 0
Reputation: 122
When I need to send CR+LF often I declare a Const and refer to it as needed.
Const
CRLF = #13+#10;
{ To use this do the following }
MyString := 'This string ends with a Carriage Return / Line Feed'+CRLF;
You can also add Carriage Return / Linefeed using Chr(10)+Chr(13);
For example;
MyString := 'This string also ends with a CRLF' + Chr(10) + Chr(13)
+ 'But it could equally end with an Escape Code' + Chr(27) // or #27
I have edited my answer because it was pointed out I had the CR LF in the wrong order.
Upvotes: -1
Reputation: 597941
There are different ways to express CRLF:
Instr := '$HEHDT,2.0,T*2D'#13#10;
Instr := '$HEHDT,2.0,T*2D'#$D#$A;
// CR and LF are defined in the IdGlobal unit
Instr := '$HEHDT,2.0,T*2D'+CR+LF;
// EOL is defined in the IdGlobal unit
Instr := '$HEHDT,2.0,T*2D'+EOL;
Upvotes: 0
Reputation: 12059
Assumming that the InStr is the string you want to send it would be :
Cp1tx.Broadcast(InStr + #13#10, 8051, '', IndyTextEncoding_8Bit);
Upvotes: 5