Author Topic: Generating unicode symbols in C POUs (DM430E)  (Read 8924 times)

Offline williamk

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +1/-0
Generating unicode symbols in C POUs (DM430E)
« on: August 17, 2022, 08:43:57 PM »
I'm attempting to generate some strings from within a POU that include unicode symbols like the Degree symbol and the Greater-Than-Equal symbol.

I've tried a few different things so far, but nothing has worked.

Basically, I want to take the output of a POU and than insert that into a Screen Definition as a STRING.  Is this possible?

Offline Matt_Eng

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +10/-0
Re: Generating unicode symbols in C POUs (DM430E)
« Reply #1 on: August 18, 2022, 02:29:23 PM »
I've done this before with a POU, there are two ways I've used.

1. Use a Structured Text POU to work with strings as it is a supported data type, although string/wstring is referred to as a char/wchar. This signal should be able to be directly connected to a screen definition.
2. If you use a C POU, then you need to use an array as the output of the POU instead of a string. After the POU the signal then needs to have a retype to string before it can be connected to a screen definition.

-Matt

Offline williamk

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +1/-0
Re: Generating unicode symbols in C POUs (DM430E)
« Reply #2 on: August 18, 2022, 04:34:59 PM »
I'm actually able to work with STRINGs in C-POUs, but run into issues when I try to use WSTRINGs which would support characters that are outside of the base ASCII set.

Using STRING to try to print the degree symbol gives me the following warning and will compile but won't print correctly once it's installed and running on the display.
   - illegal character encoding in string literal In: wDiagSignals Line: 282 Column: 38 Category: Lexical or Preprocessor Issue

Using WSTRING and running the output of the POU directly to the Screen Definition gives me the following compile-time error.
   [CHPARGU1] Unsupported POU Call: {POU: wDiagSignals cannot be called directly from GUIDE code because it is using unsupported interface item(s): wstring, }.


Can WSTRINGs be used this way with ST-POUs?  It seems like it's specifically a limitation of the graphical portion of the environment rather than a C-POU vs ST-POU thing.  I will do some testing with ST-POUs today.

Offline Matt_Eng

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +10/-0
Re: Generating unicode symbols in C POUs (DM430E)
« Reply #3 on: August 18, 2022, 09:25:54 PM »
I think it may be a limitation of the Graphical environments data types. Since GUIDE is limited to UTF-8 encoding for strings and it has to be converted from an array to a string.
I did get it working in C using the UTF-8 encoding and then converting it to a string like in the image I've attached.


I think the ST POU has an advantage then since it can directly handover a WString to the VBSE interface. The String Examples page in the help makes it seem like it should be nicer.

Offline Matt_Eng

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +10/-0
Re: Generating unicode symbols in C POUs (DM430E)
« Reply #4 on: August 18, 2022, 09:52:57 PM »
Well, I tried routing a WSTRING across from the ST POU without success. So I guess that won't work.
Using the function to converting it to a string worked though.

FUNCTION ST_GetString : DINT
VAR_OUTPUT
  sMyString : STRING[20];
END_VAR
VAR
  sTempString : WSTRING[10];
END_VAR

sTempString := "°Test 12 %";
sMyString := WSTRING_TO_STRING(sTempString);

Offline williamk

  • PLUS+1 Developer
  • ***
  • Posts: 21
  • Karma: +1/-0
Re: Generating unicode symbols in C POUs (DM430E)
« Reply #5 on: August 19, 2022, 03:13:34 AM »
I finally just found success using a ST-POU to generate the string using the same method as the string section in the help menu showed.  It's not the perfect solution because all the other code in my program is in C, but it will do for now.


FUNCTION WSTRING_TEST : DINT
VAR_OUTPUT
  wFault_X : STRING;
END_VAR

wFault_X := 'TEST$C2$B0';


This successfully prints "TEST°" on the display.

Thanks for the help!