Lazarus

Free Pascal => General => Topic started by: Mossie on August 01, 2022, 05:44:25 pm

Title: PLCString reverse letters
Post by: Mossie 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.
Title: Re: PLCString reverse letters
Post by: Handoko 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 (https://en.wikipedia.org/wiki/Endianness)
Title: Re: PLCString reverse letters
Post by: Mossie 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?
Title: Re: PLCString reverse letters
Post by: Handoko 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/ (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 (https://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Endianess)
Title: Re: PLCString reverse letters
Post by: Mossie on August 01, 2022, 08:21:12 pm
Thx Handoko,
Just what I needed. Be Blessed Man!!!!!!
TinyPortal © 2005-2018