Author Topic: String Concatenate C Code POU  (Read 802 times)

Offline AlbertMilani

  • PLUS+1 Developer
  • ***
  • Posts: 12
  • Karma: +0/-0
String Concatenate C Code POU
« on: January 04, 2023, 05:52:32 PM »
Hi,

Does anyone have a C Code POU they could share with me that will concatenate one string to another or a POU that does something similar that could help me get started?  Something that would concatenate two UINT8 arrays is probably what it should do.

I could probably do it myself but I'm sure I'd make a few dumb mistakes since I'm relatively new to GUIDE and haven't made a C Code POU yet.

Thanks,
Albert

Offline AlbertMilani

  • PLUS+1 Developer
  • ***
  • Posts: 12
  • Karma: +0/-0
Re: String Concatenate C Code POU
« Reply #1 on: January 06, 2023, 06:09:21 PM »
Well, I tried it myself and it works correctly.  I'm not sure I did everything the best way; maybe someone could critique it.  I was stingy with the input string length and I couldn't think of a way of relating the output string length in the code and the length specified in the VAR_OUTPUT section.  I also would've liked to use pointers in the C Code but I couldn't get that to happen with the input type.

See the attachments for images of my Page and C code, and I also attached my SCS file.

Albert
« Last Edit: January 06, 2023, 06:12:02 PM by AlbertMilani »

Offline Tor

  • Administrator
  • PLUS+1 Guru
  • *
  • Posts: 245
  • Karma: +25/-1
Re: String Concatenate C Code POU
« Reply #2 on: January 09, 2023, 01:16:26 PM »
Hello,

A developer gave me this:
"To concatenate two strings natively in GUIDE, the preferred method is to use a standard ST (Structured Text) POU. (See example below)"

Code example in the P1P.


I hope it helps.
Best regards,
Tor
PLUS+1® SW PAE Team

Offline AlbertMilani

  • PLUS+1 Developer
  • ***
  • Posts: 12
  • Karma: +0/-0
Re: String Concatenate C Code POU
« Reply #3 on: January 10, 2023, 01:20:15 AM »
This is much better and now I can see how to use other "STRING related PLC functions" in the GUIDE Manual.

Thanks!
Albert

Offline AlbertMilani

  • PLUS+1 Developer
  • ***
  • Posts: 12
  • Karma: +0/-0
Re: String Concatenate C Code POU
« Reply #4 on: January 28, 2023, 03:24:37 AM »
This seems to be working great except if I have any other error, I also get this warning:
Code: [Select]
*** WARNING 447:1105 *** [PLC2C] PLC Code Compilation Warning {String of default length will be returned,
which may be less than expected length. Save expression into temporary variable to avoid uncertainty.}
Line: [ 1 ] in implementation of StrConcat_Native

I changed the code to do what the warning recommended, 'Save expression into temporary variable to avoid uncertainty" and that warning doesn't happen anymore.

Albert

Offline AlbertMilani

  • PLUS+1 Developer
  • ***
  • Posts: 12
  • Karma: +0/-0
Re: String Concatenate C Code POU
« Reply #5 on: April 24, 2023, 03:46:30 PM »
Hi,

I can't seem to drive a bus with this output.  I can get it to work by first connecting a constant to the bus member and then connecting the StrConcat output to the same bus member but this is disturbing.  Am I doing something wrong?

Thanks in advance for any help,
Albert

Offline Matt_Eng

  • PLUS+1 Developer
  • ***
  • Posts: 18
  • Karma: +7/-0
Re: String Concatenate C Code POU
« Reply #6 on: April 25, 2023, 10:58:28 PM »
Hi Albert,

It's possible that you haven't done anything wrong, and you're just hitting a bug.
I've noticed this "undriven" behavior when the output signals of a POU are rerouted to a new bus as you've shown.
To confirm that it is driven, if you connect a wire directly to the POU bus it should show the driven status.
I think it might be fixed in a upcoming version, but even though it shows as undriven, the signal is still able to be used from what I've noticed.

The workaround I've used is to have a retype when connecting to the new bus. Or in situations where I was trying to save resources, I would use the "Predefine Type" component from under the Manage section.

Hope this helps
Matt_Eng