SSK

NX PLC Sysmac Studio Flaoting point Conversion Format Issue

6 posts in this topic

I am using a Omron NX102-9000 PLC programming through Sysmac studio software, I have a Data received in 2 words Hex 4453 7FE0. i need to convert this to Float format and result supposed to be 845.998 but when i combine and convert it to real it give result 1146322944.Need help to get correct format data.

 

// Shift High_Word to the upper 16 bits and combine with Low_Word
Combined_Value := (SHL(TO_DWORD(Pos_XWord), 16)) OR TO_DWORD(Pos_XWord2);

// Convert the combined DWORD to a REAL (float)
Float_Value1:= DWORD_TO_REAL(Combined_Value);

Screenshot 2024-11-21 170333.png

Screenshot 2024-11-21 170333.png

Share this post


Link to post
Share on other sites

See if this example helps.

ByteToFloat.png.9e1b46530689c2ce8df81fae

2 people like this

Share this post


Link to post
Share on other sites

When you need to do a bitwise conversion the normal conversion instructions won't work. They try to look at the value of the source variable and convert it into the target variable instead of just moving it bit for bit. The CopyxxxxToxxxxx instructions are what you want:

Capture.JPG

Edited by photovoltaic
2 people like this

Share this post


Link to post
Share on other sites

Thank you all for reply. Tomorrow I will introduce this instructions and check. 

Share this post


Link to post
Share on other sites

Hi My Problem solved. Now i can real time position values without any error in real time.

Thank you verymuch

 

 

Screenshot 2.png

1 person likes this

Share this post


Link to post
Share on other sites
On 22/11/2024 at 0:56 PM, SSK said:

Hi My Problem solved. Now i can real time position values without any error in real time.

Thank you verymuch

 

 

Screenshot 2.png

@SSK I know that you have a working solution, another option Instead of receiving the robot data into a byte array, would be creating a data structure of length of the byte array, then creating a variable of said type. This variable then would have all your data in correct format that align the bytes into the output data types. This would eliminate the need for any conversions within the program.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now