I have a string that is in a codesys variable
which is selected by a macro
GetData(Name[0], “Weintek Built-in CODESYS”, “Application.PersistentVars.Channels[0].Title”, 16)
and stored in a LW internal variable
SetData(Name[0], “Local HMI”, “String”, 16)
So if my codesys variable contains ‘12121212’
the LW variable has ‘1111’
it is then displayed in a text display
As ‘1111’
I can imagine why this is , but cannot fix it
what the soulition.
I 1mport the tags as 2 chr$ per word, and have tried it the other way around.
Due to the specification of Macro, Macro uses WORD to calculate and map string data of a Codesys PLC. When using Macro to transfer string data from or to a Codesys PLC device, the variable must be defined as SHORT, so it can map every character with PLC correctly.
The method @TimWusa described is a shortcut for remapping the char sequence to a word array. The reason this is necessary is that tag-based PLCs like CODESYS require STRING types to be written using 16-bit arrays. To remap this in code, it would look like:
char Name[32]=""
macro_command main()
StringCopy("XH2 TANK Pressure(PSIG)",Name[0])
short sName[16], tmp = 0
// To convert data to word format from byte
short i[3] = {0,0,0}
for i[0] = 0 to 15
i[1] = i[0] * 2
i[2] = i[1] + 1
tmp = Name[i[2]] << 8
sName[i[0]] = tmp + Name[i[1]]
next
SetData(sName[0], "CODESYS V3 (Ethernet)", "Application.PLC_PRG.sData", 16)
end macro_command
The method Tim outlined is a shortcut that uses HMI registers as placeholders such that the char (byte) data is first set within the HMIs register and then re-read as a short (word) prior to transfer: