Example Code

Swap Words 32-bit Single Floating Point value

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Description

Overview
This example wires 32-bit Single value into input of Swapped Value

 


Description
LabVIEW provides the Swap Words Function that swaps the high-order 16 bits and the low-order 16 bits for every long integer input to the function. This function does not work for floating point numbers though. To get around this you can use the Type Cast function to cast the value to a 1D array of bytes. Then use the Reverse 1D Array function and type cast it back to a floating-point number. This is relavant when working with Modbus because 32-bit single values are stored in two 16-bit registers. The issue is discussed in this KB. The picture below shows what the subVI will be performing.

 


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Download the attached folder to your computer
  2. In the block diagram of your top-level VI, right-click select Select VI
  3. Navigate to "Word Swap Single 2012 NIVerified.vi" click OK.
  4. Run this VI

 

Additional Information or References
VI Block Diagram

  Block Diagram.PNG

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

Danny Funk -- Senior Group Manager -- Software R&D -- NI

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
DJ0777
Member
Member
on

hi i am getting data from my power meter EMS6400 but while fetching the WH reading it's shows difference of 106 and same time while checked with mod bus test tool showing same as on meter. please fine my codes as below. data on register 3123 and swapped float value

 
DJ0777_1-1577109350208.png