Display Unicode as WSTRING

2020-06-29
2020-06-30
  • rasmus-houtved - 2020-06-29

    I have an application that needs to support multiple languages therefor I need to be able to display special letters.
    I will receive each letter as an utf-16 as 2 bytes via CAN messages.
    If I do this:

    WStr:="$0400" I get the visualization Π€ Which is correct.

    My challenge here is that the data I receive via CAN will only be 04 00.
    I can simply not get the application to show the result I need.

    Can anyone help on a good solution or just a solution.

    I am running Codesys 3.5 and the application is running on an IFM terminal.
    I would also like to be able to do this in Codesys 2.3

     
  • i-campbell

    i-campbell - 2020-06-29

    Maybe you need to try byteswapping.
    MemUtils.MemCpy() can copy the bytes from where they are to your WSTRING
    You then need to find a byteswap function somewhere if required. Maybe MemUtils.Swap or MemForceSwap

     
  • rasmus-houtved - 2020-06-29

    It is more a question about getting the $ into my Wstring so it can be seen as a Unicode.

     
  • i-campbell

    i-campbell - 2020-06-30

    $ is just an escape character. "$0400" means 'a two byte character, lowbyte is 00, high byte is 04'
    Might be easier to do:
    Wstr[0] := %IW0;
    Wstr[1] := %IW1;
    etc.

     
  • rasmus-houtved - 2020-06-30

    @i-campbell
    Thanks but my Russian is not my strong side :-)

    But I think I need to clarify my problem a bit better.

    A simple example
    I will receive 2 CAN frames with each 2 databytes.
    Can message 1 databyte = 00 48 (H)
    Can message 2 ddatayte = 00 49 (I)

    I will need these two can messages to become the word "Hi" in a wstring.

     
  • i-campbell

    i-campbell - 2020-06-30

    Can you access these (00 48 00 49) as a byte array or word array already?

     
  • rasmus-houtved - 2020-06-30

    They will be in a USINT Array
    Since this is the datatype for the CAN messages used by IFM

     

    Last edit: rasmus-houtved 2020-06-30
  • i-campbell

    i-campbell - 2020-06-30

    Add the CAA Memory library.

    VAR
        Wstr : WSTRING;
        usintarray : ARRAY [0..3] OF USINT := [16#00, 16#47, 16#0, 16#49];
    END_VAR;
    Wstr[0] := MEM.PackBytesToWord(byHighByte := usintarray[0], byLowByte:= usintarray[1]);
    Wstr[1] := MEM.PackBytesToWord(byHighByte := usintarray[2], byLowByte:= usintarray[3]);
    Wstr[2] := 16#0000; //Terminating character
    
     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3

  • rasmus-houtved - 2020-06-30

    Thanks

    It works as I would like it to work.

     

Log in to post a comment.