I am working on IoT kit using Hilscher NetIOT Connect Gateway, I have a P&F Ultrasonic sensor, I am getting process data 14 bit in two bytes (attachment Received data). I want to convert it into 16bit uint starting 2-bit offset of the first byte, bit read starting from bit 2 to bit 14. So the value range from 0 to 4000mm.
Hi, firstly, you should (for the sake of consistency in your data) retrieve these as a 16bit value OR an array of 2 bytes - so that they are read from the PLC in the same scan (and therefore consistent)
Does the OPCUA server permit you to setup 16bit tags? Do you have permissions to adjust the OPCUA server config? (do so if you can)
Once you have 2 bytes, it is easy to convert to UINT16 in a function. var u16 = (msg.payload[1] << 8) + msg.payload[0]; //NOTE: might need to byteswap
once you have a 16 bit value, mask out bits 0 & 1 by shifting right twice... u16 = (u16 >> 2);