Jump to content

Cominbing two 16 bits to get a 32 bit


Recommended Posts

I'm currently trying to read an encoder value from a drive via ModBus. The encoder value is split into higher 16 bit and lower 16 bit, hence I have to read two registers.

Is there an easy way to combine the two values to get the single 32 bit value I'm after?




Link to comment
Share on other sites


for example...you have 2 variables Uint16 (A = higher, B = lower) and 1 variable Uint32 (C)... you have to multiply the A for 65536 and store the result in C...after you have to add B in C.

I think that also you can use some buffer functions...but with first only 2 actions are needed.

Link to comment
Share on other sites

You can also just put a 32 bit tag in your modbus operation, and the PLC will read 2 registers instead, (if you give it address 0, then it will read both 0 and 1).

Then, assuming that order of the high and low on the encoder (the endianess of the numbers) is the same as in the PLC, then it would work fine (if not, them the high and low 16 bits numbers will be flipped, and then you could better have to read them separately, and do what ORSO suggested)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...