UltimaSerial LabView Tutorial: Step-by-Step on how to use ActiveX in Labview 9
 

Windaq add-ons
Windaq Add-ons


The following is a step-by-step tutorial on how to use ActiveX in LabView

In this lesson, we will use Ultimaserial ActiveX to develop a data acquisition application with DATAQ's Starter kit, including DI-194, DI-148U, DI-145, DI-14, DI-155, DI-158U and DI-710U. You will learn

  1. How to import an ActiveX in LabView

  2. Use its properties and methods

  3. How to convert the variant returned from the ActiveX to data array

  4. How to extract members from the converted data array

  5. Output the data array to Labview's Waveform Chart or Ultimaserial's XChart 

Before we start, please download and install UltimaSerial.

  1. Start Labview. Here we are using LabView 9 so you may notice different icon, text and/or drop-down menu location when comparing to your version of LabView. If your LabView is a much older version, please take a look at the LabView 5 and LabView 6 examples

  2. If possible, please open one of the LabView 9 Sample VI as reference. LabView 9 examples include 

    1. test.vi, created from this lesson, up to step 36

    2. test2.vi, based on test.vi, with added Waveform Chart beyond step 36

    3. us9.vi, based on test.vi, but uses dial and list box for sample rate and COM port selection

  3. Follow New->Blank VI to create a new Front Panel

  4. Right click on the grid on the Front panel

  5. When the drop down menu shows up, click on the double down arrow  at the bottom of the menu, select .NET & ActiveX->ActiveX Container and place one on the grid of the Front panel: 


  6. Right click inside the ActiveX container on Front panel, select Insert ActiveX Object...., then Ultimaserial from the list. If you need to interface to multiple Windaq Starter kits at the same time, you will need to create one ActiveX container with Ultimaserial in it for each device
  7. Repeat 3) to 5) to insert XChart 
  8. On the panel grid, follow Right-click->Buttons->Text Button to add a text button
    • Right click on the button
    • Under the Appearance tab
      • Change the On text to Stop, Off text to Start. 
      • Change Label to Start/Stop
      • Uncheck visible flag for the Label. 
    • Under Operation tab, change Button behavior to "Switch when released"
  9. On the panel grid, follow Right-click->Num Inds->Num Ind to add a numeric display
  10. Follow Right-click->Num Inds->Num Ind to add another numeric display
  11. Follow Right-click->Num Ctrls->Num Ctrl to add a numeric input. 
    • Right click on it
      • Under Appearance table
        • Uncheck "Show Increment/decrement buttons". 
        • Change Label text to Device
  12. Follow Right-click->Num Ctrls->Num Ctrl to add another numeric input. 
    • Right click on it
      • Under Appearance table
        • Uncheck "Show Increment/decrement buttons". 
        • Change Label text to "COM"
  13. Follow Right-click->Num Ctrls->Num Ctrl to add another numeric input. 
    • Right click on it
      • Under Appearance table
        • Uncheck "Show Increment/decrement buttons"
        • Change Label text to "Sample Rate"
  14. Save the vi as test.vi. Now the front panel of our vi should look like the following:


  15. From the menu bar, follow Window->Show Block Diagram to bring up the test.vi Block Diagram, which is like the following


  16. Right click on the workspace. When the drop down menu shows up, click on the double down arrow  at the bottom of the menu, select Programming->Structures->Stacked Sequences 
  17. Right click on the frame and select "Add Frame after"
  18. Inside Frame 0, add "while loop" from RightClick->DoubleDownArrow->Programming->Structure->While Loop
  19. Create a local variable for Start/Stop button, Change To Read, and connect it to loop condition


  20. Insert another stacked sequence to Frame 1 of the above stacked sequence
  21. Add five frames to the new sequence, now the block diagram is like this


  22. In Frame 0 of the inner sequence frame, RightClick->DoubleDownArrow->Connectivity->ActiveX->Automation. Connect the automation line to the icon of Ultimaserial


  23. In Frame 1 of the same sequence, right click on Ultiamserial->Create->Property  for ULTIMASERIAL....class to bring in ChannelCount, EventLevel, CommPort, Device, AcquisitionMode and SampleRate
  24. Change the above properties to Write
  25. Create three numeric constants 2, 1 and 0: RightClick->DoubleDownArrow->Mathematics->Numeric->Numeric Co.
  26. Link the appropriate inputs to the above properties. With this configuration, we enable two channels, no trigger condition, update data at highest rate.


  27. In Frame 2 of the same sequence, right click on Ultiamserial->Create->Method for ULTIMASERIAL....class to bring in Start. To demonstrate how to use XChart,  right click on XChart->Create->Method for XCHART....class to bring in Ymax (put) and Ymin (put), wire them like this to initialize them so that it takes the full range of the ADC readings


  28. In Frame 3 of the same sequence, follow the above procedure to bring in Ultmaserial.GetData, Ultimaserial.AvailableData and XChart.Chart 


  29. Added the followings
    1. Multiply from RightClick->DoubleDownArrow->Mathematics->Numeric->Multiply
    2. Division from RightClick->DoubleDownArrow->Mathematics->Numeric->Divide
    3. Decrement from RightClick->DoubleDownArrow->Mathematics->Numeric->Decrement
    4. Array Index from RightClick->DoubleDownArrow->Programming->Array->Index Array. You can resize it to show more input nodes
    5. Array Size from RightClick->DoubleDownArrow->Programming->Array->Array Size
    6. Variant to Data from RightClick->DoubleDownArrow->Connectivity->ActiveX->Variant to..., 
    7. While loop from RightClick->DoubleDownArrow->Programming->Structure->While Loop
      1. Click on the red circle to change the condition to
    8. Case Structure from RightClick->DoubleDownArrow->Programming->Structure->Case Struct..., 
    9. Array Constant from RightClick->DoubleDownArrow->Programming->Array->Array Const... 
      1. Resize it to two dimensional
      2. Create a constant zero as I16 and uncheck Adapt to entered data
      3. Add this constant to Array Constant's data basket
    10. Great than zero from RightClick->DoubleDownArrow->Programming->Comparison->Greater than...
    11. Several numeric constants , , and
  30. Wiring
    1.   connects to the data type of Variant to Data
    2. connects to the condition of case
    3. The output of Ultimaserial.GetData connects to the input of XChart.Chart.Data and the input of Variant to Data
    4. The output of Variant to Data connects to the input of Array Size and Array Index
    5. The others should be trivial.
  31. This is what you should get:


  32. Frame 4


  33. Frame 5. RightClick->DoubeArrowDown->Connectivity->ActiveX->Close Ref. Connect the Close Ref to Ultimaserial


  34. Switch back to Front Panel window, and Run it
  35. Enter device name, COM port and sample rate
  36. Click on Start button, and here is the result


  37. If you wish to plot the waveform to the Waveform Chart from Labview, read on
  38. Stop the program and switch back the Front Panel view 
  39. Resize the Panel so that we have room to add LabView's Waveform Chart to it
  40. Right click on the grid, follow Graph Indicators->Chart, and place a chart on the Front Panel
  41. Right click on the Waveform Chart and select properties
  42. Select 2 for "Plots shown"


  43. Now the Front Panel is like this


  44. Switch to Block DIagram view of the project and wire the input of Waveform Chart to the output of Variant To Data, like this


  45. Switch back to Front Panel View, right click on Waveform Chart and uncheck "Transpose Array"
  46. Run it, and here is what you will see




     

    Last update: 11/18/16

    Copyright: 2000-2005  www.UltimaSerial.com