Sign in to follow this  
Followers 0
dipen_95

Packing two USint into an INT

3 posts in this topic

I am currently using TIA Portal V14 and S7-1217 Plc and I am stuck as all I get from my remote IO is USint and then I need it to pack it to the INT or DINT respectively. Is there any function where I can pack my low and high byte into an INT and be done with it.

I know one of the more unconventional way is to multiply high byte by 256 and add low byte to it but what happen when i need to convert to DINT i have to multiply and add some weird number.

Can somebody save me from myself??

Share this post


Link to post
Share on other sites

 

In the Siemens world, words and doubles are divided up into bytes. Here's a little cheat-sheet I made up a while ago to keep it straight in my head (Least significant bits/bytes are to the right):

SiemensBytePattern.PNG.8b744890adaee3106

So, if your information in integer X needs to be stored inside the higher-order bytes of DB10.DBD8, you would simply move it into DB10.DBW8. If the information in integer Y needs to be in the lower-order bytes of DB10.DBD8, you would move Y into DB10.DBW10. If you're using "M" memory instead of DBs, you can just substitute "M" for "DB10.DB" above. IOW, if your destination is MD100, you would move X into MB100 and Y into MB102.

Disclaimer: I've only just gotten TIA Portal, so I can't post an example for you, but the data structure should be the same.  As with everything "weird" like this, you will want to use a test PLC to make sure this works the way you expect it to. If you don't have a test PLC, you can test it out with unused memory in your main PLC.

 

 

Share this post


Link to post
Share on other sites

Thanks Joe,

It worked. I just created a function to transfer my bytes to INT and DINT respectively and off I go. As I am transferring information back and forth with the remote IO and have way too many bytes to do individual move I had no choice but to create a function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0