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
TYPE U_RealForCanBus :
UNION
rValue : REAL;
arrbyBytes : ARRAY[1..REAL_BYTE_SIZE] OF BYTE;
END_UNION
END_TYPE
If you declare a
uRealToSendOverCan : U_RealForCanBus;
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:
rValue : REAL;
arrbyToSend : ARRAY[1..REAL_BYTE_SIZE] OF BYTE;
MEMCPY(ADR(arrbyToSend ),ADR(rValue),REAL_BYTE_SIZE);
Or you can always use a pointer to interpret the memory in a different way:
rValue : REAL;
parrbyToSend : POINTER TO ARRAY[1..REAL_BYTE_SIZE] OF BYTE;
parrbyToSend := ARD(rValue); //Initialize pointer
parrbyToSend^[2] ... //Second Byte of rValue