Example Code

Convert a String Which Describes a HEX Value to an Arbitrary String That is The HEX 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

Overview

This example demonstrates using the Hexadecimal String to Number and Type Cast functions to convert an ASCII string to a binary string.

 

 

Description

When communicating with instruments through VISA commands, the instrument may respond to ASCII commands, or HEX commands. Since VISA only uses the string datatype, we often change the string display to be the "HEX Display" in order to pass in specific HEX codes to an instrument. If you need to store these HEX commands inside of a text file to automate the commands, it can be difficult to translate the strings of HEX description into a string that has the binary value defined by the HEX. The process is often more difficult than expected. This example code provides a somewhat elegant method to generate the string which is the hex value in binary.

 

 

Requirements

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code

1. Download the attached VI "ASCII String To HEX String_LV2012_NI Verified"

2. Enter the ASCII HEX value

3. Run the VI

 

 

Additional Information or References

Note that this example will only convert an ASCII HEX description that translates into a 32 bit binary representation. In order to convert larger or smaller data sizes, change the numeric constant's representation on the block diagram to another appropriate unsigned integer size. For a more flexible implementation, look at the following example.

 Convert a HEX Value String to a String With The Hex Value

 

You will need to integrate this code into your application with file IO and VISA commands to make a meaningful application.

 

BD.PNG

 

 

 

 

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

Asa Kirby
CompactRIO Product Marketing Manager
________________
Sail Fast!

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