Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84488members
353708posts

How to merge four words to one value?

Machine Automation Forum

A forum addressing machine automation solutions for the complete machine lifecycle. Including offers like Machine Advisor, Modicon PLC/PacDrive, Lexium or Preventa. Discuss and share knowledge on offers relating to cloud-based service platforms, machine localization and monitoring, industrial operations control, motion products as well as safety function!

jhonut
Ensign
Ensign
0 Likes
3
1121

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!

 

 

 

Tags (1)
3 Replies 3
LeTomas
Lieutenant Lieutenant
Lieutenant
0 Likes
2
1115

Re: How to merge four words to one value?

Hi @jhonut ,

 

I believe you could try to create a %ML variable type LWORD to overlap those registers. Something like this:

 

Address.PNG

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 (1)
jhonut
Ensign
Ensign
0 Likes
1
1107

Re: How to merge four words to one value?

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.

SimA
Ensign Ensign
Ensign
0
1105

Re: How to merge four words to one value?

 

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:

Download link 

 

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 (1)