Write file in unicode

Anonymous
2017-03-28
2019-06-26
  • Anonymous - 2017-03-28

    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

     
  • cerminek

    cerminek - 2018-12-09

    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...

     
  • e.kislov

    e.kislov - 2018-12-10

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

    IMG: uni1.png

    IMG: uni2.png

     
  • cerminek

    cerminek - 2018-12-10

    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!

     
  • alm

    alm - 2019-06-25

    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 ```

    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??

     
  • e.kislov

    e.kislov - 2019-06-25

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

     
  • alm

    alm - 2019-06-25

    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.

     
  • e.kislov

    e.kislov - 2019-06-25

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

     
  • alm

    alm - 2019-06-26

    e.kislov hat geschrieben:
    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.

     

Log in to post a comment.