- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-21 05:28 AM
How to merge four words to one value?
I get an INT64 value, through Modbus TCP from a power meter, in four %IW (%IW68, %IW69, %IW70, %IW71).
My question is how could I merge these four input words to a value? I have seen here that LWORD type exists, but I couldn't find a function, like WORD_AS_DWORD, to merge my input values into a value. How could I do this?
I am using a TM251MESE PLC.
Many thanks in advance!
- Labels:
-
Efficiency
-
Modicon M2xx
- Tags:
- english
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-21 06:24 AM . Last Modified: 2021-05-21 06:25 AM
Hi @jhonut ,
I believe you could try to create a %ML variable type LWORD to overlap those registers. Something like this:
And you can use in your program the %ML variable created.
I am not sure if inside Machine Expert we have function WORD_AS_LREAL or similar 🤔
Best regards,
- Tags:
- english
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-21 06:36 AM
Thanks for reply, @LeTomas!
I have searched in LibraryManager for WORD_AS_LREAL or DWORD_AS_LREAL, but I didn't find anything. I will try to use LWORD as you suggested.
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-21 02:32 PM . Last Modified: 2021-05-21 02:38 PM
You could do it with localized variables %MW and %ML however you have to be careful about the position of the variables and that it's not used anywhere else.
I would typically use pointers instead. I do it in 2 lines of structured text. You could also embed that in a custom function that you would call in your program in any language.
Here is the function that you can import:
I declare a variable that is the array of 4 words and a variable that will be the destination 64bit LINT.
I also declare a pointer to LINT that will be the address location of my LINT variable. This location is automatically calculated at the time the project is built.
With this line " pLint := ADR(arWord1); " , I grab the address location of the word array and move it to my long int pointer.
In the next line " liLongInt1 := pLint^; " , I dereference the pointer with the ^ symbol. It extracts the value from the address location contained in the pointer.
VAR
arWord1 : ARRAY[0..3] OF WORD;
liLongInt1 : LINT;
pLint : POINTER TO LINT;
END_VAR
pLint := ADR(arWord1);
liLongInt1 := pLint^;
- Tags:
- english
Link copied. Please paste this link to share this article on your social media post.
