Adding WORD values in a STRING

estam

Member
Join Date
Nov 2014
Location
nwh
Posts
10
Hello I'm intermediate programmer who is wondering if somebody is able to point me in the right direction in getting a few values in a readable fashion within a string.

sCompleteMessage := '<L><PA><FA><MA><WA><FK>'+HMI_AantalPerUur+'<AC>/h <CF>'+HMI_BosAantal ;

HMI_AantalPerUur: WORD
HMI_BosAantal: WORD
sCompleteMessage: STRING

How do you get these combined??
This is a part of the programming I can't get right, I need to combine these to send it to a LED screen but have to calculate the CRC of this string.
That part I have found now to get it all together:D

So just a little guidance would be appreciated, Just for the record I need just a example to point me back on track again.
 
Welcome to the Forum !

What controller platform are you using ? The syntax and instructions for one may be different from another.
 
SoMachine V4.1 so basically CoDeSYS.

I may have written it down in the wrong way due to the fact it's partly copied from a C++
written piece of software.
I normally do not work with strings and so that's why I'm in limbo at this moment :)
 
Is there nobody who can point me in the right direction??
It maybe something obvious but I fail to see it.
 
I have not used CoDeSYS but a quick look at an instruction manual shows that there are conversion instructions - possibly WORD_TO_STRING. You will have to create strings for the two WORD values. Then you will concatenate these with literal strings of the other two sections. But don't ask me for a detailed example.
 
had found WORD_TO_STRNG and ANY_TO_STRING.
got me a lot off errors I could not lose.

have been a bit further at my problem and just need to figure out on how to get all segments together as one string.
It seems that this is holding me back.
The + sign does not work and the , is also giving me problems.
Give me inputs and outputs any time but working with strings is freaking me out.

sCompleteMessage := '<L><PA><FA><MA><WA><FK>'+AantalPerUur+'<AC>/h <CF>'+BosAantal ;

AantalPerUur : STRING
BosAantal : String

This is now the new problem :)
 
Googling about the concatenate command in CoDeSys seems to be CONCAT and takes two arguments. So you will probably have to invoke it a few times to build the complete string. This is an example line in the link I referenced -

INTEGER_STRING := CONCAT (BEFORE_DOT, AFTER_DOT);

Obviously 'BEFORE_DOT' and 'AFTER_DOT' are two strings. They get combined and stored into 'INTEGER_STRING'
 
Thanks Bernie,
gone try that one tomorrow.

As said working text and displays are new for me so I need to learn new tricks.
Where are the days gone for only a light as a indicator :)

Nah just joking, HMI's are a great thing these days but when you have to it all again after 10 years of not programming your just lost.
 
Thanks Bernie,
gone try that one tomorrow.

As said working text and displays are new for me so I need to learn new tricks.
Where are the days gone for only a light as a indicator :)

Nah just joking, HMI's are a great thing these days but when you have to it all again after 10 years of not programming your just lost.
Hi,

Here is a solution :

sCompleteMessage := CONCAT ( WORD_TO_STRING(HMI_AantalPerUur) ,WORD_TO_STRING(HMI_BosAantal));
 
I think this should be it, if I use ever tip I got

sCompleteMessage := CONCAT ('<L><PA><FA><MA><WA><FK>, WORD_TO_STRING(HMI_AantalPerUur)) ;
sCompleteMessage := CONCAT ( sCompleteMessage, '<AC>/h <CF>');
sCompleteMessage := CONCAT ( sCompleteMessage ,WORD_TO_STRING(HMI_BosAantal));

I'm not able to edit the project at this time but will update this post if all goes well.

Thanks for the pointing out of a even better shortcut.
 
Hi,

Here is a solution :

sCompleteMessage := CONCAT ( WORD_TO_STRING(HMI_AantalPerUur) ,WORD_TO_STRING(HMI_BosAantal));

Just a question regarding the WORD_TO_STRING instruction.
Can you give it a string lenght limitation??
Or a way to add lenght to the string when you need spaces to get a uniform apperance when it's longer or shorter.
have tried some variations but none gave a error free result.

And by the way the example above does work so thanks again for that.
 
Again, I am not a CoDeSys expert but here's a method from other languages to 'left pad' a string (let's call it short_String).

I establish a string (let's call it space_string) with as many spaces as the desired length. Then

Temp_String = CONCAT(space_string, short_String)
Result_String = RIGHT(Temp_String, desired_Length)

Similarly if you wanted leading zeroes after a WORD_TO_STRING then CONCAT with a string made up of zeroes and then take the RIGHT portion.
 
Well i'm no expert either on CoDeSys:D
I do find it a interesting way to program.
After a period of at least 10 years i got on with it quite fast but found that I lack some skills on dealing with text based problems.
But then again we now have the internet and you can ask people if they may know a way to solve a problem.

But to come back on your answer i will try that, but i do believe it can be done in a other way.
Google gave a few suggestions but strangly they did not work.

At least we got something on the led display :)
 
Just a question regarding the WORD_TO_STRING instruction.
Can you give it a string lenght limitation??
Or a way to add lenght to the string when you need spaces to get a uniform apperance when it's longer or shorter.
have tried some variations but none gave a error free result.

And by the way the example above does work so thanks again for that.
Download the OSCAT basic library. OSCAT = Open Source Community for Automation Technology

http://www.oscat.de/downloadmanager/viewdownload/3-oscatbasic/44-oscat-basic-331-codesys3.html


Then install the library and there are tons of STRING functions that you can use.
 

Similar Topics

Hi Everyone, Currently we have three plants running with Controllogix PLCs (L72, L73, L74). In each of these plants we have 2 FTView SE...
Replies
0
Views
54
Hello, Im building project with 1756-L82ES controller and 1756-IB16S card but i cant find it when trying to add the card to IO configuration...
Replies
3
Views
135
Hello, I have a pair of redundant 1756-L71 controllers rev 24. These controllers currently have produced and consumed tag interfaces to 3 other...
Replies
2
Views
158
I'm adding an IAI Gateway with 2 axes connected to it. To an ethernet network on my PLC. So, I think the math is correct on the Input and Output...
Replies
0
Views
143
Hi Folks. I am gearing up to add a 2nd identical HMI to a project. This 2nd HMI will basically be an exact clone of the 1st one. The equipment...
Replies
3
Views
258
Back
Top Bottom