Customizing a C Series Example Program for Wireless Data Acquisition

Publish Date: Sep 28, 2012 | 1 Ratings | 5.00 out of 5 | Print | Submit your review

Overview

This example will focus on implementing best-practice programming techniques for wireless data acquisition with the NI WLS-9163 Wi-Fi C Series Single Module Carrier.

Table of Contents

Background

One of the value multipliers of the WLS-9163 is its compatibility with the DAQmx Application Programming Interface (API).  The same C Series application can be used to acquire data from the 9215 analog input module when it's in a USB adapter, Compact DAQ chassis or Wi-Fi carrier.

Note: For C Series Module compatibility information see the Developer Zone Tutorial: C Series Module Compatibility Chart

Data transfer across wireless Ethernet is different than across USB.  There are three programming considerations that can be made to compensate for less than ideal wireless networks.  This example will implement these considerations in LabVIEW's DAQmx API.

  1. DAQmx Read Timeout
  2. DAQmx Input Buffer
  3. Programmatic Error Handling

In addition to these considerations, this example makes use of the conditional disable structure to make the application more scalable and maintainable.

Preliminary

These preliminary steps make use of shipping examples to save development time and code validation.  This example is based around the NI 9215 4-Channel, 100 kS/s, 16-bit, ±10 V Simultaneous Sampling Analog Input Module.  Your application will most likely vary, but the concepts will remain valid.

Find Shipping Example

  • From the LabVIEW Getting Started screen click Help»Find Examples...
  • From the Hardware drop-down on the Browse tab select Add Device...
  • From the Hardware tab, highlight NI 9215 and click the right-pointing arrow to add the device to the Devices to find examples for list.
  • Click OK.
  • Enable the Limit results to hardware checkbox in the NI Example Finder.
  • Select NI 9215 from the Hardware drop-down box.
  • Double-click Hardware Input and Output»DAQmx»Analog Measurements»Voltage»Acq&Graph Voltage-Int Clk.vi.

 
Figure 1: Browsing for Hardware Examples in the NI Example Finder

Create a New Project

  • From Acq&Graph Voltage-Int Clk.vi click File»Save As...»Substitute copy for original»Conntinue...
  • Save the VI in a working directory, such as LabVIEW WLS Projects.
  • From Acq&Graph Voltage-Int Clk.vi click File»New...»Project»Empty Project»OK»Add.
  • Save the Project in the working directory.  In this example, the name of the LabVIEW project file is WLSDAQBestPractices.

Create Carrier Condition

We will use Conditional Disable symbols in the LabVIEW Project to create a scalable and maintainable application.  The application will behave differently depending on the carrier type of the C Series module.

  • In the Project Explorer Window, right click Project:WLSDAQBestPractices.lvproj»Properties»Conditional Disable Symbols.
  • In the New Symbol text box, enter CARRIER_TYPE.
  • In the New Value text box, enter WLS.
  • Click Add»OK.

Open Acq&Graph Voltage-Int Clk and read the code comments in the free labels.  When you have an understanding for the operation of the VI, delete the free labels.  For more information, see NI LabVIEW 8.6 Help: Conditional Disable Symbols Page (Project Properties Dialog Box).

  • From the Project Explorer click File»Save All.

DAQmx Read Timeout 

A DAQmx input task will timeout with error -50405 if N samples are not streamed to the host computer within the timeout period.  To adjust for network latency, the timeout value can be increased.  It must be increased in two places: the Windows registry and the DAQmx Task.

  1. For more information on changing the NI-DAQmx network timeout in the Windows registry, see KnowledgeBase 4R49MMD2: Error 50405: Connection timed out with a WLS/ENET-9163.
  2. To change the DAQmx Task read timeout, use the following equation as a rule of thumb.

DAQmx Read Timeout = 12MB / (Number of Channels * Scan Rate * Number of Bytes Per Scan)
Equation 1: Calculate the DAQmx Read Timeout for a Particular Acquisition

The quantity (Number of Channels * Number of Bytes Per Scan) is available in the DAQmx Read Property called Raw Data Width.

  • Break the wire between the DAQmx Create Channel and the DAQmx Timing VIs.
  • Insert a DAQmx Read Property Node.
  • Select the Advanced»Raw Data Width property.
  • Surround the property node with a Conditional Disable Structure.
  • Right-click the border of the Conditional Disable Structure and select Edit Condition For This Subdiagram...
  • Select CARRIER_TYPE from the Symbol(s) drop-down and enter WLS into the Value(s) field.
  • Click OK.


Figure 2: Configuring the Conditional Disable Structure

  • Reroute the Rate control into the Conditional Disable Structure and multiply Rate by RawDataWidth using a multiply function.
  • Divide the constant 12000000 by the result of the multiply using a divide function.
  • Break the wire from the timeout constant to the DAQmx Read function, and wire the result of the divide function into the timeout terminal of the DAQmx Read.
  • Wire the Rate control to the rate terminal of the DAQmx Timing VI.
  • Wire the Reference Out of the DAQmx Read Property Node to the task/channels in terminal of the DAQmx Timing VI.


Figure 3: Configuring the DAQmx Read Timeout for the WLS Carrier

  • Right-click the border of the Conditional Disable Structure and select Add Subdiagram After...
  • Select CARRIER_TYPE from the Symbol(s) drop-down and enter USB into the Value(s) field.


Figure 4: Configuring the Conditional Disable Structure

  • Right-click the Conditional Disable Structure and select Make This The Default Subdiagram.
  • Move the timeout constant into the Conditional Disable Structure and connect it to the timeout tunnel.
  • Connect the reference wire through the Conditional Disable Structure.


Figure 5: Configuring the DAQmx Read Timeout for the USB Carrier

This is the complete modification for adjusting the DAQmx Read Timeout.  By itself, this modification is minimally effective at reducing the -50405 errors that sometimes occur with wireless data acquisition.  It is recommended that you also implement changes to the code that adjust the DAQmx Input Buffer.

DAQmx Input Buffer 

Adjusting the DAQmx Input Buffer size will allow the WLS RAM to stream to the host RAM without overflowing the input buffer on the host.

  • In the Conditional Disable Structure's WLS subdiagram, break the wire between the DAQmx Read Property node and the tunnel.
  • Place a DAQmx Configure Input Buffer VI between the property node and the tunnel.

The following equation is a good rule-of-thumb for calculating the input buffer size.  It is based on the situation where the RAM buffer on the WLS device completely fills before it can be sent to the host computer.

DAQmx Input Buffer = Scan Rate * Timeout
Equation 2: Calculate the DAQmx Input Buffer for a Particular Acquisition

  • Multiply the Rate control with the timeout value calculated in the last section.
  • Wire the result of the multiply function to the buffer size terminal of the DAQmx Configure Input Buffer.
  • Rewire the error cluster from the DAQmx Create Channel through the DAQmx Read Property Node and the DAQmx Configure Input Buffer and to the DAQmx Timing VI.
  • Wire the error cluster through the USB subdiagram in the Conditional Disable Structure.


Figure 6: Configuring the DAQmx Input Buffer for the WLS Carrier

This is the complete modification for adjusting the DAQmx Input Buffer.  Between this and the DAQmx Read timeout modification, you can reduce the -50405 errors that sometimes occur with wireless data acquisition.

Programmatic Error Handling 

It is difficult to predict all variables that can affect a wireless data acquisition system.  Error -50405 may pop up if the wireless network is experiencing a momentary surge in traffic.  If we would like not to abort the task on error, we can programmatically handle the exception.

  • Place a While Loop around the DAQmx Read function.
  • Break the task and error cluster wires between the DAQmx Read and the DAQmx Clear Task VIs.
  • Place a DAQmx Is Task Done VI within the While Loop.
  • Create a Stop control within the While Loop.
  • Place an Or function within the While Loop.
  • Wire the task done? output of the DAQmx Is Task Done VI and the Stop control to the inputs of the Or function.
  • Wire the output of the Or function to the conditional terminal of the While Loop.
  • Re-wire the task and error cluster wires through the While Loop.


Figure 7: Query the DAQmx Task for Finish

  • Place a General Error Handler VI within the While Loop.
  • Re-route the error cluster between DAQmx Read and DAQmx Is Task Done through the General Error Handler VI.
  • Wire a numeric constant of -50405 to the exception code terminal of the General Error Handler VI.
  • Create an enumeration constant on the exception action terminal of the General Error Handler VI.
  • Select cancel error on match from the enumeration constant.
  • Create an indicator on the error cluster going into the General Error Handler.


Figure 8: Discarding -50405 Errors Programmatically

This example discards the -50405 error and continues to read samples from the wireless device.  You can handle errors in other manners.  The following list contains some ideas for programmatically handling timeout errors.

Count the number of times the error appears and quit after a certain number.
Log the time of the error to a file and continue the acquisition.
If there's an error, ping the WLS device and abort the acquisition if the reply is too long.
Pause the task for some time and try again later.

Summary

One of the advantages of WiFi DAQ is that it uses the same DAQmx API as wired data acquisition.  There are three things that we can do to account for the uniqueness of wireless acquisition.

  1. DAQmx Read Timeout
  2. DAQmx Input Buffer
  3. Programmatic Error Handling

For more information about wireless data acquisition, please see the following links.

NI Wi-Fi Data Acquisition
NI WLS/ENET-9163 User Guide and Specifications
Developer Zone Tutorial: NI Wi-Fi DAQ Frequently Asked Questions
Developer Zone Tutorial: Wireless Data Acquisition: Range versus Throughput

Back to Top

Bookmark & Share


Downloads

Attachments:

WLSDAQBestPractices.lvproj

Requirements


Ratings

Rate this document

Answered Your Question?
Yes No

Submit