Massimo.Milluzzo hat geschrieben:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
e.kislov hat geschrieben:
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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
e.kislov hat geschrieben:
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 ```
``` 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??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
e.kislov hat geschrieben:
Which 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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: Massimo.Milluzzo
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...
There is no problem, just use WSTRING type and byte ordermark.
Library writes not ANSI or Unicode or something else, library just writes data.
Thanks a lot for this solution!
Well, that was for writing. But what would I do if i want to read unicode from the file?
If I do ```
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??
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.
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.