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

Offline AlbertMilani

  • PLUS+1 User
  • **
  • Posts: 7
  • 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 User
  • **
  • Posts: 7
  • 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: 225
  • 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 Helpdesk team

Offline AlbertMilani

  • PLUS+1 User
  • **
  • Posts: 7
  • 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 User
  • **
  • Posts: 7
  • 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