Tuesday, July 19, 2011

Going Cellular with LXI

Test and measurement instruments with the LAN eXtensions for Instrumentation or LXI standard use LAN or Ethernet for remote connectivity (click here for more info on LXI). The Ethernet standard is widely used all over the globe and because of its wide use there is a wide array of low cost off the shelf networking products that make connecting to LXI instruments from anywhere at any time with various types of computing devices possible. The wide array of off the shelf LAN compatible network products available today provides a major advantage for LXI in long distance testing, long duration testing, distributive testing, and various DAQ applications because of the low cost and connection flexibility they provide. In this blog post we are going to look one such off the shelf networking device, a cellular router, and the benefits it provides for testing.

The router you use at home uses an Ethernet connection to access the internet. A cellular router on the other hand uses a cellular provider’s network to access the internet. This means if you connect an LXI instrument to the cellular router that instrument can now be accessed from any cellular network or WiFi network or Ethernet network that is connected to the internet. This provides four big test advantages:
  1. It gives you the ability to easily setup long distance remote testing sites from almost anywhere around the globe as long as it is in range of a cellular tower. 
  2. It gives you the ability to run a distributed test with one remote controller.
  3. It allows you to access measurement data or control instruments from almost anywhere around the globe with various computing devices such as a laptop, smart phone, or server.
  4. It allows you to perform remote testing in a moving vehicle as long as the vehicle remains in the range of cellular network towers. 
As explained above and illustrated in the figure below, cellular routers make LXI instrument access almost totally ubiquitous.

No cellular provider is going to let you use their network for free so you do need to purchase a mobile broadband USB stick or a WiFi broadband tethering device along with a monthly data plan. The USB broadband device can be connected directly to the cellular router or the WiFi broadband tethering device can be connected over WiFi. Of course with the WiFi broadband tethering device you could just use a basic WiFi router that has a bridge mode.

There are some security hurdles and concerns you should be aware of when using any router. Consumer routers, including cellular routers, in default mode assume all the devices connected directly to them are client devices and not servers. Because of this they block all external connection requests from client devices outside of their local network. This is a big problem because LXI instruments are servers (that is how they host a web page) so computers or controllers external to the router's network that try to connect to them will be blocked by the router. To overcome this you need to access the router's port forwarding feature or DMZ feature. Port forwarding allows you to specify certain network ports to allow connection requests to come in on and which IP address on the router’s local network to forward them to. You can also use the router's DMZ feature which allows you to forward all incoming connection requests, regardless of port, to a specified local IP address. Using port forwarding and DMZ features also opens up security concerns. Any opening you make into the router to access an instrument is open to anybody on the internet. This can be especially troublesome to LXI instrument running a Window's based PC operating system because they are vulnerable to cyber attacks. The port forwarding method is more secure than DMZ because it allows you to use obscure port numbers that are not used by the general public and then forward the connection request or message to a more commonly used port on the instrument such as port 80 or 5025. For more information on increasing security when accessing instruments through a router shot me an email.

When purchasing a cellular router you want to pay attention to its list of compatible broadband devices. Also be aware that the cellular provider that you purchase the broadband device from probably does not guarantee that their device will work on a cellular router so if you need support help go to the manufacturer of the router. Currently the largest cellular or broadband router maker is cradlepoint, you can check them out at http://www.cradlepoint.com/

Click here to check out the first ever LXI instrument control app for the iOS

Wednesday, July 13, 2011

Fetching Large Amounts of Instrument Data with Matlab

Matlab is a great tool for handling and analyzing measurement data, but you can run into problems when trying to read or fetch large amounts of measurement data from an instrument. Problems range from timeouts, to memory errors, to only a portion of the measurement data being returned. In this post we will look at an easy to implement Matlab code example for fetching and storing large amounts of measurement data.

Let's start out by looking at a high level overview of the easy way to write a quick matlab script for making and fetching measurements with a remote instrument:

  1. Setup and open a connection to the instrument. One of the steps here is setting up the size of the input buffer for reading measurement data.
  2. Configure the instrument for the measurement.
  3. Trigger the measurement.
  4. Fetch the measurement data from the instrument using the query() method and store it in one huge string
  5. Convert the string of data to a number format array like double for post processing and analysis
This method is easy to implement but can lead to problems when dealing with large amounts of data. There are a couple of reasons for this. The first being it does not use memory very efficiently. Notice between the input buffer allocation, the long string that the data is read to, and the final numerical array there are three large chunks memory being allocated for one set of data. This can lead to "Out of memory" errors. Especially in Windows machines where RAM is fragmented between a number of processes and Matlab needs contiguous memory to store a numerical array. Another reason is the various protocol layers that are used in an IO operation can be unstable when reading a large contiguous chunk of data. 

A better and still easy to implement way to fetch large amounts of data is to format it as binary data (versus ASCII) over the IO and to break the data into smaller blocks and reassemble the blocks in Matlab. Lets demonstrate with example Matlab code. For this demonstration we will make 1M double format timing measurements on a 2 GHz oscillator using the Agilent 53230A universal counter. Below we will look at only the code portions that involve reading the measurement data. If you would like a full version of the "Lots_of_Data.m" script used here just email me. 

%The Lots_of_Data script makes 1M timestamp measurements on 
%a 2GHz oscillator using the 53230A. The measurements are read 
%from the instrument in binary form. The measurements are read
%and handled in 500 reading block sizes set the input buffer 
%size in bytes.We want to read in 500 readings per block each 
%reading is 23 bytes including comma. 'obj1' is the handle to the 
%53230A object
buffer = 23 * 500;
set(obj1, 'InputBufferSize', buffer);
%Perform measurement settings and trigger 
%Here we send readings to 53230A output buffer 
%fread()will be used to read all measurements as binary data 
%instead of ASCII characters to cut down on overhead
%get prescale value first and convert to string then to double
prescale = fread(obj1,5);
%allocate double array for faster performance
arrayDouble = zeros(1,1e6);
%read blocks of 500 readings from the 53230A at a time. 
%Convert the binary values to doubles and add to the array 
%of doubles. This method conserves memory versus reading all 
%the data in at once
for i=1:2e3,
tempBin = fread(obj1,(23*500));
 %replace string commas with spaces so we can convert to double array
tempChar = char(tempBin)';
tempChar = strrep(tempChar, ',', ' ');
%replace array of string values to array of doubles
  if i ~= 1
        arrayDouble((((i-1)*500)+1):(i*500)) = strread(tempChar);
      arrayDouble(1:500) = strread(tempChar);

In the above example the 'fread' method was used to fetch the data in binary form instead of ASCII data. This reduces the size of the data being passed over the IO. Also the 1M readings were collected in blocks of 500 that were later reassembled in a numerical array for post processing and analysis. This means we only had to allocate one large chunk of memory instead of three like we did in the first example.

If you know of a better more efficient way to fetch large amounts of measurement data and store it in Matlab please share with a comment below or an email to me. If you are working with extremely large sets of data and get out memory errors check out Matlab's video on optimizing memory usage from the link below. You can also track your Matlab memory usage for optimization purposes using the free Memory Monitor program (link below).

Wednesday, July 6, 2011

Using PXI Chassis Monitoring Tools to Ensure Reliable and Repeatable Results

Below is a video demonstrating Agilent's M9018A PXI Monitoring Tools. The monitoring tools allow you to easily monitor and control things like power rail voltages, individual module slot temperatures, and fan speeds inside the mainframe. These chassis monitoring tools give you the ability to ensure reliable and repeatable results in your PXI testing environment. The monitoring tools features can be accessed via a rich set of IVI commands allowing you to take advantages of the tools in almost any programming environment including C#, Matlab, and Labview.