Lorne,
I pass strings back and forth between Weintek HMIs and TRI PLCs. Weintek uses arrays of integers to store strings and packs 2 8-bit characters in each 16 bit value.
This is the code that I use to convert a PLC string variable into an array of registers that can be accessed via Modbus. The HMI reads/writes 16 sequential registers in the PLC to read/write string data. I picked an array size of 16 16-bit integers. This will support strings up to 32 characters.
' Copy Installation Name String from a$ to DM[] so that it can be accessed by the
' Weintek HMI as an array of 16-bit Modbus registers
'
n = InstallationName ' starting word in DM[] to build the data for the HMI
' SizeInWords is defined as 16. 16 sequential DM[] locations.
'
for i = 1 to SizeInWords step 2
' Two 8-bit ASCII characters are packed into each 16-bit DM value
'
' The Weintek HMI expects strings to be packed into sequential 16-bit words.
' The first character in a string is in the LSB of the first word
' The second character will be in the MSB of the frist word.
'
' The rest of the bytes are filled with 0x00. This keeps the HMI string object
' sane.
'
' Please note that asc() is spec'd to return 0x00 when index is beyond
' the end of the string, A$. It seems to do this in test. This
' usage ensures that the entire DM[] array is 0 filled beyond the end
' of the string characters.
'
DM[n] = asc(A$,i+1) * 256
DM[n] = DM[n] + asc(A$,i)
n = n + 1 ' next word in DM[]
next
Gary Dickinson