Example Code

How to Change VBAI Step Limits Programmatically Using LabVIEW

Code and Documents

Attachment

Download All

Overview


This program programmatically changes the limits of steps in Vision Builder for Automated Inspection during the inpection. To do so, this program uses access to Modbus through VBAI as well as LabVIEW.

There are two major pieces to this example; the VBAI inspection which accesses the Modbus, and the LabVIEW Modbus library.  In order to run this program you need to:

  1. Open the VBAI inspection and run it once to ensure that the image is available.  There may be an initial warning concerning the Modbus which is covered the next step.
  2. Open <code>Tools » Communication Device Manager</code> and click New Device.
  3. Set the device to Modbus TCP, and it will automatically be set to Master.  Click OK.
  4. In the Communication Device Manager window your Modbus should now appear, set to the default Modbus port, 502.  Make sure to press the Start Server button for the Modbus Server before clicking OK to return to the inspection.
  5. At this point you can start the inspection, it will most likely fail until the LabVIEW portion is set up.
  6. Open the Modbus Library, NI Modbus.llb.  Open the main VI, MB Set VBAI Limits.vi.
  7. Press run.  This VI will automatically connect to your computer (via the local host IP address 127.0.0.1) and send the listed intensity limits to the Modbus.  It will also read the current inspections intensity and status from the Modbus and display it.
  8. Edit the Min and Max Intensity levels and view how it changes the status of the inspections based on the incoming Intensity levels.

The VBAI inspection, Dynamic Tolerances.vbai, contains several steps, most of which are just inspection steps.  The steps vital to dynamically changing the inspections limits are the two Modbus steps, Read Tolerances and Write Data.  If you double click on the Read Tolerances step it will open its configuration.  Notice that it is reading two registers, 0x0 and 0x1 to get the intensity limit data that LabVIEW has placed in those locations.  Click Cancel to close the configuration.  Now double click on the Compute Status step.  This step takes the two values read from the Modbus, and compares the intensity reading from the Check Cap Presence step to the limits.  If it is above the minimum and below the maximum it passes, otherwise it fails.  If you double click on the Write Data step it will open its configuration.  Notice that it is writing two pieces of data to the Modbus, the current intensity reading from the Check Cap Presence step, and the success or failure of the Compute Status step.  These are then read by the LabVIEW VI.

The Modbus Library, NI Modbus.llb controls all of LabVIEW's interactions with the Modbus.  The main VI we are using, MB Set VBAI Limits.vi, indicates all communication with the Modbus.  First, it connects to the TCP Modbus at the listed IP.  This is defaulted to your own computer, but it can be edited for remote computers.  Also, the communication can be changed to serial if need be in both LabVIEW and the VBAI inspection.  For more information on Modbus over serial, see these two tutorials concerning Modbus on touchscreens with LabVIEW and VBAI.

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