Jump to content

Cominbing two 16 bits to get a 32 bit


Jamie123

Recommended Posts

Hello,
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?

TIA

 

Jamie

Link to comment
Share on other sites

Hi,

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

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
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.