Recent

Author Topic: PLCString reverse letters  (Read 437 times)

Mossie

  • New member
  • *
  • Posts: 5
PLCString reverse letters
« on: August 01, 2022, 05:44:25 pm »
I'm using a PLCString tag, read the string into HMIEdit.
What I get is "HP" and it should be "PH"
    Values: 50 48 07 08 ff ff ff ff 27 75
As per serial logger it does come correct, but PLCString and HMIEdit is reversing the string?
Anything I'm missing?
Somebody please can assist?
Thanks so much.

Handoko

  • Hero Member
  • *****
  • Posts: 4712
  • My goal: build my own game engine using Lazarus
Re: PLCString reverse letters
« Reply #1 on: August 01, 2022, 05:52:01 pm »
Hello Mossie,
Welcome to the forum.

I'm not sure, but maybe that has something to do with endianness:
https://en.wikipedia.org/wiki/Endianness

Mossie

  • New member
  • *
  • Posts: 5
Re: PLCString reverse letters
« Reply #2 on: August 01, 2022, 06:13:10 pm »
Hi Thx Handoko.
Any idea as to how I can address this in Lazarus? Thx.
The raw value is correct, If I use a PLCTagnumber, its correct,
so I cannot see that it is an Indianess as you suggest.
Once I use the PLCString tag it is swapped? thus. Am I
missing something here?
« Last Edit: August 01, 2022, 06:31:39 pm by Mossie »

Handoko

  • Hero Member
  • *****
  • Posts: 4712
  • My goal: build my own game engine using Lazarus
Re: PLCString reverse letters
« Reply #3 on: August 01, 2022, 07:19:34 pm »
Endianess in use is determined by the hardware/platform. If your case is endian issue, maybe there information can help:

Quote
With the correct TagType, you should set the properties SwapBytes, SwapWords to match the Endian of your controller. You will have to make trial and error to find out the correct setup of SwapBytes/SwapWords properties. I can’t help you in this with more accurate information.
Source: https://www.pascalscada.com/2016/11/22/expressions-on-all-properties-of-base-tags/

FPC has these functions for endian conversion:
SwapEndian, BEtoN (big endian to current endian), LEtoN (little endian to current endian), NtoBE (current endian to big endian) and NtoLE (current endian to little endian).
Source: https://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Endianess
« Last Edit: August 01, 2022, 07:32:02 pm by Handoko »

Mossie

  • New member
  • *
  • Posts: 5
Re: PLCString reverse letters
« Reply #4 on: August 01, 2022, 08:21:12 pm »
Thx Handoko,
Just what I needed. Be Blessed Man!!!!!!

 

TinyPortal © 2005-2018