Skip to content

OpcUA handling of swedish characters

Is there anyway to get swedish characters to work when sending alarms via OPCua?


As you see here in UaExpert, i'missing some characters:

the message text in PLCnext Engineer is correct:

I saw that the ALARM_STATE datatype, has a string variabel called LANG, can i use that somehow?


BR

Mike

Comments

  • Out of interest, which library is that function block from?

    What is the data type of the "MESSAGE" parameter? If it's not WSTRING, then it will not be possible to display characters from the extended ASCII set.

  • This library is from the PLCnext Controller library:

    And the message is defined as STRING, so i also realize the issue, with it not being a WSTRING. Could i use some other library which would be better for this?

  • This is a quite interesting problem that we have been discussing here in our team.

    The basic problem is that PLCnext Engineer treats STRING variables as a set of individual bytes, with each byte representing a single Unicode character (hexadecimal 00 to FF), while the OPC UA specification treats string variables as UTF8, where each character can be represented by up to four bytes.

    I'm not sure if this will work with the existing ALM_* function blocks, but it's possible to construct a UTF8 string in PLCnext Engineer, that is displayed correctly by UaExpert.

    Here is a very simple, and very ugly example:


    In this case the character ä is constructed in UTF8 format by injecting the two bytes c3 a4 into the middle of the string. In the Watch window (at the bottom of the screen shot) the string is not displayed correctly, because PLCnext Engineer is trying to display c3 and a4 as two separate Unicode characters.

    However, if you mark that STRING variable with the OPC attribute, then in UaExpert the string looks like this:

    ... which is what we want to see.

    If this method also works for the ALM_* function blocks, then you could consider creating a Unicode-to-UTF8 function to convert strings to UTF8 format, by replacing each Unicode character in a STRING with the corresponding UTF8 characters. In fact I'd be surprised if someone in the Community hasn't created a function like this already. An existing function that might help is the StringReplaceAll function in the PLCnextBase library:


    It would be very useful if PLCnext Engineer had some support for UTF8 strings, which would be compatible with (among other things) the OPC UA specification, but I think this is the only solution at the moment.

    I hope this helps.

  • To clarify my previous answer:

    It would be very useful if PLCnext Engineer had some support for UTF8 strings

    PLCnext Engineer does have support for UTF16 strings (using WSTRING variables), so this will help with most applications. The problem in this specific case is the ALM_* function blocks, which only take STRING messages at the moment. There has also been a discussion here about supporting WSTRING alarm messages in a future version of the ALM_* function blocks, as a longer-term solution to this problem.

Sign In or Register to comment.