Skip to content
Advertisement

How to convert byte array into various LREAL(double) values in TwinCAT3

I’m right now trying to convert my original python socket reading code into structure text in TwinCAT3. The following is the original python code that unpacks the read_data = socket.recv(1116) data into different things:

JavaScript

According to the python code, I’ve written a socket connection and read function block in TwinCAT3. However, I’m right now facing some problem doing data encoding:

JavaScript

And in the body part:

JavaScript

The problem I’ve encountered is that I’m not sure how to write conversion between byte array and LREAL. Furthermore, the array indexing of DataReceived[(i+204)..(i+212)] seems to have some errors. Can anyone teach me how to index specific part like (204 to 212) in ARRAY[0..1115]? And also the tramsformation between byte array and LREAL.

Thanks!

Advertisement

Answer

You can memcopy the bytes to the LREAL.
ADR() is the function that gets the memory address of the variable:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement