CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Write file in unicode
https://forum.codesys.com/viewtopic.php?f=11&t=7717
Page 1 of 1

Author:  Massimo.Milluzzo [ Tue Mar 28, 2017 10:15 am ]
Post subject:  Write file in unicode

Hi all,
I'm trying to write a file with the SysFile library. How can I write unicode characters? It seems the library writes only in ANSI.

Thank you,
Regards.
Massimo

Author:  cerminek [ Sun Dec 09, 2018 4:05 pm ]
Post subject:  Re: Write file in unicode

Massimo.Milluzzo wrote:
Hi all,
I'm trying to write a file with the SysFile library. How can I write unicode characters? It seems the library writes only in ANSI.

Thank you,
Regards.
Massimo

Hi, I'm intereste in this too. I've made a lot research on it and no CoDeSys based device were able to save file in unicode. Only ANSI... But I've used Festo PLC, which uses Linux RT and the files saved on SD card by SysLibFile were in UTF-8...

Author:  e.kislov [ Mon Dec 10, 2018 6:05 am ]
Post subject:  Re: Write file in unicode

There is no problem, just use WSTRING type and byte ordermark.
Library writes not ANSI or Unicode or something else, library just writes data.

Attachment:
uni1.png


Attachment:
uni2.png

Author:  cerminek [ Mon Dec 10, 2018 9:04 am ]
Post subject:  Re: Write file in unicode

e.kislov wrote:
There is no problem, just use WSTRING type and byte ordermark.
Library writes not ANSI or Unicode or something else, library just writes data.

uni1.png

uni2.png


Thanks a lot for this solution!

Author:  alm [ Tue Jun 25, 2019 11:45 am ]
Post subject:  Re: Write file in unicode

e.kislov wrote:
There is no problem, just use WSTRING type and byte ordermark.
Library writes not ANSI or Unicode or something else, library just writes data.

uni1.png

uni2.png


Well, that was for writing. But what would I do if i want to read unicode from the file?
If I do
Code:
SysFileRead(hFile:=FileHandle, pbyBuffer:=ADR(wsData), 2 * TO_DWORD(Standard64.WLEN(wsData)), pResult:=pResult);
my wsData => WSTRING(255) gets totally wrong numbers. ex. for the letter 'h'(hex 68) i get something like 20 thousand which can't be converted back to the letter 'h' from ASCII ... what am I doing wrong??

Author:  e.kislov [ Tue Jun 25, 2019 2:49 pm ]
Post subject:  Re: Write file in unicode

Which exact value? ("something like 20 thousand...")

Author:  alm [ Tue Jun 25, 2019 3:12 pm ]
Post subject:  Re: Write file in unicode

e.kislov wrote:
Which exact value? ("something like 20 thousand...")


Well I already found the problem but the exact value was 26721(WORD). I found out that it was utf-8 so it was reading it 1 byte at a time but into a WSTRING of which every char is a 16bit WORD and it also was not utf-8, the encoding was ISO 8859-1 / latin1, which means all the other chars than the ascii (0-127) are not encoded correctly. 26721 in hex is 6861 which corresponds to the letters h(68) a(61).

So my problem still stands, I can't display those characters. 0-127 works just fine.

Author:  e.kislov [ Tue Jun 25, 2019 3:20 pm ]
Post subject:  Re: Write file in unicode

So you have file with UTF8 charset?
Try to use StringUtils library, function ConvertUTF8ToUTF16.

Author:  alm [ Wed Jun 26, 2019 7:58 am ]
Post subject:  Re: Write file in unicode

e.kislov wrote:
So you have file with UTF8 charset?
Try to use StringUtils library, function ConvertUTF8ToUTF16.


I didn't know that such a thing existed.
I'm going to try it later.
Thanks.

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/