PLUS+1 User Forum
PLUS+1 Software => Code sharing => Topic started by: AlbertMilani 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
-
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
-
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.
-
This is much better and now I can see how to use other "STRING related PLC functions" in the GUIDE Manual.
Thanks!
Albert
-
This seems to be working great except if I have any other error, I also get this warning:
*** 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
-
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
-
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