+1
Convert individual bytes to 32 bit float
Hello,
I am working with a device that sends multiple frames using the same message ID. Often times there is a parameter that contains data from two different frames, for instance, Parameter "X" (32 bit float pt) data can be found in Byte 6 & Byte 7 of Frame 01 and Byte 1 & Byte 2 in Frame 02. I'm able to use the paged/mask filter successfully to capture the multiple frames but am stuck with how to take the individual bytes and convert them to 32 bit float. I've noticed a Generic Parameter In Channel handles it automatically when assigned "real" and is pointing to the 4 Bytes but this only works when the data (4 bytes) are packed into the same frame, not spread across two different frames. Thank you!
Duplicates
1
Customer support service by UserEcho
Hello, yes I agree we need more string functions. See this entry as well.
Convert Machine ID to numbers? / Software / IQAN
There needs to be a 'concatenate' function and other string functions for working with bytes and packets.
The only work around we've found is to leverage multiple PLCs. You can SEND the packet as TWO different packets, and then READ them as one packet, merging the bytes together.
If I'm understanding your problem correctly, you need to convert multiple JPIN channels (potentially from different JFIN channels) into a 32-bit float.
I had a slightly different problem, but I think maybe a similar solution.
In the below examples, each "JI OODRB#" is a different JPIN channel. No other external variables.
Converting multiple channels into a uint32:
A := JI OODRB4 SHR 1
B := JI OODRB5 SHL 7
C := JI OODRB6 SHL 15
D := JI OODRB7 SHL 23
E := (JI OODRB8 BAND 1) SHL 31
Result := A + B + C + D + E
Converting multiple channels into a int32
A := JI OODRB4 SHR 1
B := JI OODRB5 SHL 7
C := JI OODRB6 SHL 15
D := JI OODRB7 SHL 23
E := (JI OODRB8 BAND 1) SHL 31
F := A + B + C + D + E
Polarity := F SHR 31
if (Polarity = 1) then
Result := bnot(F) + 1
else
Result := F
endif
Converting multiple channels into a Float32
Sign := JI OODRB8 BAND 1
if (Sign = 1) then
Sign := -1
else
Sign := 1
endif
Exponent := JI OODRB7 - 127
A := JI OODRB4 SHR 1
B := JI OODRB5 SHL 7
C := JI OODRB6 SHL 15
D := 1 SHL 23
Mantissa := A + B + C + D
Mantissa := Mantissa / PowerOf(2,23)
Mantissa := Mantissa * PowerOf(2,Exponent)
Result := Sign * Mantissa
Maybe that will help or get you on the right track. Use the binary operators to build the number and then there's just annoying exponent/mantissa math to get a float.