0

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.

1
  • You didn't show a statement assigning value to InStr. Are you trying to ask about literal characters? Commented Jul 8, 2016 at 10:49

4 Answers 4

5

Assumming that the InStr is the string you want to send it would be :

Cp1tx.Broadcast(InStr + #13#10, 8051, '', IndyTextEncoding_8Bit);
Sign up to request clarification or add additional context in comments.

Comments

0

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;

2 Comments

Isn't EOL platform dependent or is it CRLF on all platforms
@DavidHeffernan Indy's EOL is CRLF on all platforms, because most protocols that Indy implements use CRLF as a line delimiter. You are probably thinking of Delphi's sLineBreak, which is platform-dependant.
0

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.

Comments

-1

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.

8 Comments

It is CR+LF, in other words you've got it wrong in this answer. You mention preference, but preference does not enter into this.
@DavidHeffernan is quite right. The expression "carriage return line feed" comes from how typewriters and teleprinters, worked - they had to return the print mechanism to a known position along the platen (print roller) before the paper could be fed properly..
Actually, @MartynA, that is not quite true. I had several typewriters, and you would push the handle, then a linefeed would occur and in the meantime you would push it to the left and only when it reached the lef side, you had a carriage return. So real manual typewriters actually performed a LF+CR. But the electronic ones did it the other way around: CR+LF.
Who taught you #10+#13! CR=#13 and LF=#10, so the normal sequence is #13#10, using #10#13 may get you in to trouble. Unix systems typically use only #10, and older Mac systems used only #13 if I remember correctly. Most systems though will silently detect a sequence of these and as long as you're consistent work without much problems, except mayby show superfluous blank lines.
FYI, Indy already declares CR, LF, and EOL (CRLF) constants in the IdGlobal unit.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.