Machine Automation Forum
A forum addressing machine automation solutions for the complete machine lifecycle. Including offers like Machine Advisor, Modicon PLC/PacDrive, Lexium or Preventa. Discuss and share knowledge on offers relating to cloud-based service platforms, machine localization and monitoring, industrial operations control, motion products as well as safety function!
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-10-17 12:14 PM
Hello,
I am using M251 PLC to read data of Master Pact MTZ and Compact NS breakers (both status and measurement signal). Measurement signals like current, voltage, etc. getting in word format (2 words for one signal). I need to covert this 2 word values to Float value (in 32 bit big endian format) in PLC logic to display HMI but couldn't found any block in Machine expert.
In Modscan32, I am getting correct value in swapped float.
In Machine Expert, I tried to convert values from %MW0 and %MW1 to %MD0 (as a REAL and DWORD) but not get correct result as in ModScan32.
Kindly advice how to read float value (in big endian format) in Machine expert. Thanks
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-10-17 10:41 PM
Hi,
I you could create a function like that (copied from OSCAT) (OSCAT page)
FUNCTION DW_TO_REAL : REAL
VAR_INPUT
X : DWORD;
END_VAR
VAR
pt : POINTER TO REAL;
END_VAR
(*
version 1.0 18. apr. 2008
programmer hugo
tested by tobias
this function converts a DWORD to REAL in a bitwise manner.
*)
(* @END_DECLARATION := '0' *)
pt := ADR(X);
DW_TO_REAL := pt^;
(* revision history
hm 18. apr. 2008
original version
*)
END_FUNCTION
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-10-17 11:02 PM
To convert two-word values to a float in 32-bit big-endian format in Machine Expert (M251 PLC), follow these steps:
WORD_TO_DWORD
function to merge the words, then apply TO_REAL
to convert the DWORD to a float.Ensure the byte ordering is handled correctly to get accurate results.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-10-18 04:49 AM
Hi John,
Thank for your reply on my query.
I already tried this. WORD_TO_DWORD block combining 2 word value and make DWORD. TO_REAL block only changing datatype from DWORD to REAL, not converting DWORD to FLOAT value.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-10-18 04:51 AM
Hi Bastian,
Thanks for sharing. I will test with this and let you know.
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.