Hidden Hidden Hidden Hidden
 
 

Connect MATLAB directly to Sensors via
USB Data Acquisition Hardware
SOFTWARE > MATLAB SOFTWARE >

 

 

MATLAB and instruNet

instruNet ≥ v3.6 is compatible with 64bit MATLAB ≥ R2012a running on 64bit Windows ≥ 7 computers. MATLAB communicates with instruNet via object instruNet_Class defined in file instruNet_Class.m. This interface file and several MATLAB examples are placed on one's computer when one installs instruNet ≥ v3.6 software. instruNet_Class methods communicate with instruNet via functions exported by the 64bit native version of the windows/ system32/ iNet32.dll file (not 32bit version version at windows/ SysWOW64/ iNet32.dll). For more details on the DLL routines, see Programming.

Installation
To get started, please do the following steps:

  1. Install MATLAB software.
  2. Install instruNet hardware and ≥ v3.6 software as described here.
  3. Create a directory on your computer named ../Documents/ instruNet-to-matlab/ and COPY the files in ../Documents/ instruNet/ matlab/.. into this new directory. We copy so you can make changes and still refer to the originals. You will make changes to the files in the ../Documents/ instruNet-to-matlab/ mycode/.. folder, yet will probably not change ../Documents/ instruNet-to-matlab/ interface/ instruNet_Class.m (which contains the glue between instrunet and MATLAB).
  4. View the "C:\Windows\System32\" folder with Windows Explorer and make sure it is not hidden. Right-click Properties in Windows Explorer to view the Hide/Unhide status and Unhide if Hidden. If Hidden, Matlab LoadLibrary(C:\Windows\ System32\ iNet32.dll) might fail.
  5. Run instruNet World software and make sure it sees your instruNet hardware. For details on how to use instruNet, click here.
  6. Run MATLAB and add your new instrunet files: Select Set Path command (Home tab, Environment group), click Add With Subfolders, and then select your new directory (i.e. ../Documents/instruNet-to-matlab/).

Tutorial: Scalar I/O
To demonstrate reading and writing channels with single values, please do the following steps:

  1. Open file ../Documents/ instruNet-to-matlab/ mycode/ instrunet.m from within MATLAB and place a breakpoint at line: inet = instruNet_Class(..).
  2. Execute the following from the MATLAB Command window: instrunet(true). If the first optional argument is set to true (which is what we are doing), then an i555 hardware device is simulated and we receive random numbers instead of real a/d values. Otherwise, if you execute instrunet(false), we run instruNet normally with real hardware.

    Alternatively, one can enable simulation by changing file name ..Documents/ instruNet/ End User/ iNet32 Demo Off.txt   to   ..iNet32 Demo On.txt. To later disable simulation, one would rename the file back to "..Off". Simulation still requires instruNet software to be installed on the computer, which one can do for free via instruNet download.

    The 2nd optional argument to the instrunet() command is the name of an instruNet .prf settings file. One can run instruNet World software, set up sensors, set up a digitization, digitize to test it, and then press the SAVE button in the NETWORK page to save the settings in a .prf file. If this file is placed in one of the following locations:

      ../documents/instrunet/matlab/settings/yourFile.prf
      ../documents/matlab/instrunet/settings/yourFile.prf

    then one can pass the name of the .prf file to the instrunet() function in the 2nd argument, and these settings will load when instrunet is initialized.

    If one does not want to use one of these pre-defined directories, they can pass an absolute path/filename.

    The ".prf" suffix and the path are optional in this 2nd parameter. For example, if you save your settings to one of the two previously mentioned directories in file "abc.prf", you can call instrunet(false, "abc") to run instruNet and load your abc file.

    This is a powerful feature since it is easier to set up instruNet using instruNet World software then to explicity set each parameter with MATLAB code.
  3. You will stop at your inet = instruNet_Class(..) breakpoint. This line of code will create an instruNet object named inet and initialize the instruNet interface. This could take up to 15 seconds due to calibrating instruNet hardware. Step over this function and check that the inet object is loaded with multiple structs.
  4. Step over gNumOfDiVinChannels = inet.ain_di.qty and look at gNumOfDiVinChannels. This is set to the number of differential analog input channels (e.g. 8 when working with i555 hardware). Shown below this row are several useful variables stored inside the instruNet_Class object, and available to the end user.
  5. Step into instrunet_scalar_io(inet), which resides inside ../Documents/ instruNet-to-matlab/ mycode/ instrunet_scalar_io.m. This file shows how to read and write scalar values to and from instruNet. From here, Step through the code and observe the next few functions.

    Load_Channel_Address() loads a MATLAB struct with 4 values which define a channel's address in netNum, devNum, modNum, and chNum form. The instruNet World Network page shows these values in the first few columns.

    The channel address is passed to GetChannelValue(), which returns the channel's value in engineering units (e.g. degrees °C with temperature sensors). Channels are typically set up with instruNet world software, and saved in a .prf files as discussed above.
  6. An alternative way to refer to a channel is via an index into the inet.ain_di.list() array, which contains a list of all instruNet differental analog input channels attached to your computer. index set to 1 refers to Ch1 of the i430 card within the i555 system, for example. Type inet.ain_di.report into the command window to see a description of the channels in this list. inet.ain_se and inet.aout are similar. The former is a list of single-ended input channels and the later is a list of analog output channels.
  7. Continue stepping through the code and notice the SetField() and GetField() routines. These read and write parameters shown in the instruNet World Network page (e.g. set analog low pass filter to 6Hz).
  8. Notice the Load_Prf_Settings_File() routine which loads a .prf settings file. This is an alternative to loading a .prf file when one first initializes the instruNet system.
  9. The Press_instruNet_Button() routine enables one to press any of the buttons shown in instruNet world. The last two words in the last parameter refer to the page name and button name. For example, iNet_ButtonID_Network_Save refers to the Save button in the Network page.
  10. One can open an instruNet World window from within MATLAB. open_network_page() opens the Network page and open_record_page() opens the Record page. To return to MATLAB, one clicks the instruNet World upper-right close box.
  11. Step out of instrunet_scalar_io() and return to instrunet(). Next, we will step into instrunet_digitize() to digitize waveforms.

    One can modify or copy instrunet_scalar_io.m, instrunet_digitize.m and instrunet.m as needed. For more details on programming, click here.

Tutorial: Digitize & Process Waveforms in Realtime
To demonstrate how to digitize waveforms from within MATLAB, please do the following steps:

  1. Step into instrunet_digitize(inet), which resides inside ../Documents/ instruNet-to-matlab/ mycode/ instrunet_digitize.m. This file shows how to digitize multiple waveforms from instruNet in realtime. From here, step through the code and observe the next few functions.
  2. If load_prf_settings_file is set to true, a .prf settings file is loaded from disk in a manner similar to that done with the 2nd parameter to instrunet(), described previously. The name of this .prf file is specified in variable instrunet_prf_settings_filename.
  3. If define_list_of_digitize_channels_in_this_routine is set to true, this routine defines a list of channels to be digitized. Otherwise, if set to false, the list of digitize channels is specified in the loaded .prf file (i.e. channels with red rectangle in instruNet World Network page).
  4. If set_timing_parameters is set to true, the timing parameters (e.g. sample rate) are set in this routine; otherwise, they are specified in the loaded .prf file (i.e. Setup button in Record page).
  5. If plot_digitized_data_in_new_window is set to true, we plot realtime data in a MATLAB graph.
  6. If calculate_average_value is set to true, we calculate the average value of each channel, to show doing realtime analysis on digitized data.
  7. If processOneScanAtATime is set to true, we analyze whole scans one at a time; otherwise we analyze little segments of data as they become available. The size of a scan is in units of points-per-scan-per-channel and is one of the timing parameters.
  8. Digitize__Allocate_2x2_Data_Matrix() allocates a MATLAB 2x2 array to hold the digitized data. This 2x2 array is named inet.digitize.data.value(1:ptsPerScan, 1:numOfDigitizeChannles).
  9. DigitizeListOfChannels() processes all channels and is continuously called inside a while() loop. One then calls GetDigitizedSegment() to access new data for each channel.
  10. Function plot() plots data in a MATLAB graph, as shown the the right.
  11. if open_record_page_to.. is set to true, the instruNet World Record page is opened when digitizing stops, to display the data and the settings.

Related Material