Jamie123 Posted May 2, 2018 Report Share Posted May 2, 2018 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 More sharing options...
ORSO2001 Posted May 2, 2018 Report Share Posted May 2, 2018 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 More sharing options...
Saragani Posted May 2, 2018 Report Share Posted May 2, 2018 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 More sharing options...
Saragani Posted May 2, 2018 Report Share Posted May 2, 2018 Anyway with buffers it's 3 actions: Copy tag to buffer: From low, offset 0 to buffer Copy tag to buffer: From high, offset 2 to buffer Copy buffer to tag: From buffer, offset 0, length 4, to Int32 or UInt32 Link to comment Share on other sites More sharing options...
Jamie123 Posted May 2, 2018 Author Report Share Posted May 2, 2018 Thanks for the replies. ORSO2001's method worked fine1. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now