1

I'm using Delphi 10.3 Community Edition and Add TComPort, but my problem is that when I'm sending 9E I see 17E

 msg : String;


 msg := #$40+#$03+#$00+#$00+#$00+#$00+#$00+#$00+#$00+#$00+#$9E+#$E1+#$0A;
 SendFPMessage(msg);

 procedure TForm1.SendFPMessage(s: String);
 begin
    Comport1.WriteStr(s);
    Memo1.Lines.Add('SND:['+trim(String2Hex(s))+']');
 end;

I'm verifing the communcation with Serial Port Monitor

  My Programm: SND:[40 03 00 00 00 00 00 00 00 00 17E E1 0A]
  SPM: 40 03 00 00 00 00 00 00 00 00 7e e1 0a            @.........~á.   

I tryied AnsiString (28591) and UTF8String and created new collateral damage.

  • 3
    Character literals in the `#$80..#$FF` range (which includes `#$9E`) are subject to different interpretations depending on whether the [`{$HIGHCHARUNICODE}`](http://docwiki.embarcadero.com/RADStudio/en/HIGHCHARUNICODE_directive_(Delphi)) directive is `ON` or `OFF`. In your case, it is likely `OFF` (which is the default). But you should not be using `String` (aka `UnicodeString`) for binary data to begin with, use `TBytes` instead. – Remy Lebeau Apr 06 '21 at 20:36
  • I took {$HIGHCHARUNICODE ON} and everything is OK. I cannot use TBytes because I have to send string because TComport has only string to send. – Wellington Telles Cunha Apr 06 '21 at 20:55
  • @Wellington Telles Cunha Which TComport do you mean? There are some libraries with such component name. For example, TComport from CPort of Dejan Crnila has method `Write(const Buffer;...` to write arbitrary data. And `string` means `ansistring` there (library is from pre-Unicode era) – MBo Apr 07 '21 at 05:10
  • I got this one: +-------------------------------------------------+ | ComPort Library version 4.11f | | for Delphi 5, 6, 7, 2005, 2006, 2007, 2010, XE10| | and C++ Builder 3, 4, 5, 6 , XE10 | | | | by Dejan Crnila 1998-2002 | | maintained by Lars Dybdahl and Paul Doland | | maintained by Brian Gochnauer Nov 2010 | +-------------------------------------------------+ – Wellington Telles Cunha Apr 08 '21 at 23:53

1 Answers1

0

I don't if I found the best option: Changed #$9E to char(158)