I'm trying to send a 32-Bit Real across a CAN communications (IFM) but the CAN comms only accepts a 16-Bit value.
If the value I'm trying to send goes above 255, it resets back to 0 and continues in that pattern. I therefore need to split the 32-Bit Real value in to two 16-Bit values and then reassemble on the other side of the comms.
I just can't seem to get my head around how to do it in structured text.
Any help would be appreciated
First. I have no experience with CAN and I don't know which FBs you use to send them. But if it resets over 255 it seems like you can only send 8bit-values (bytes) instead of 16bit.
Second. I would suggest an UNION Solution (REAL_BYTE_SIZE = 4):
The variables in an UNION share the same memory. Therefore they can be interpreted in different ways
If you declare a
you can set uRealToSendOverCan.rValue and read uRealToSendOverCan.arrbyBytes
Or you could just do MEMCPY if you don't want the variables to share the memory:
Or you can always use a pointer to interpret the memory in a different way:
I know I am a little late to the party but wanted to add this as a solution.
This is similar to Felix Keil's answer but it makes use of 2
pointer
variables and aword array
to retrieve the information directly.