The Labview instrument driver includes subVIs and type definitions that make it easy to start controlling Zaber devices with Labview. It also comes with several examples that demonstrate how to use the library.
You can download the driver in Labview from the Help menu: Find Instrument Drivers.... Search for the keyword Zaber, select the driver and it will be installed automatically. You can also download it directly from the Instrument Driver Network or from our web site and follow these installation instructions. If you have trouble finding the driver or installing it, please contact us or National Instruments.
VIs included in the driver
Now that you've installed the instrument driver, here's a list of the most important VIs that come with it. To see them in action, look at the examples section below. To see the inner details of how one of these VIs works, add it to a diagram and double click on its icon. When the VI opens, switch to the wiring diagram to find more documentation and to see how it works.
- Initialize VI
- Configures a serial port to communicate with a Zaber device. Call this VI before calling other instrument driver VIs for this instrument. Generally, you need to call the Initialize VI only once at the beginning of an application. The Initialize VI gives the serial port an infinite timeout by default, because some Zaber Device commands can take a long time to complete. You can change this timeout if you want to check for disconnected devices or other timing problems. See the example VI, Expert - Change Timeout.
- Close VI
- Terminates the software connection to the instrument. If you don't use the Close VI, Labview won't complain but other applications won't be able to use the COM port.
- Request Command VI
- Sends a command and waits for a response. If the response is an error, sets error code -1074001617 and includes the Zaber error code in the message. This is the VI you should use most often. The only time to use the Read and Write VI's is when you want to send more requests while a move is still executing. To create the request cluster, right click on the Request input, and choose Create: Constant.
- Read Response VI
- Reads a response packet from the serial port. If no response is waiting, Response just returns zeroes and Responses out equals Responses in.
- Blocking Read Response VI
- Reads a response packet from the serial port. If no response is waiting, this blocks until a response is received. See the Read Response VI for one that doesn't block.
If you installed the instrument driver, you can find all of these examples from the Help menu: Find Examples.... Search for examples with the keyword "Zaber". If you downloaded the zip file, the examples are in the examples folder.
In addition to these examples, we've also posted some questions and answers on StackOverflow.com.
Beginner - Send a List of Commands
|The simplest VI you can write is just a list of commands with no logic. The block diagram makes a request, waits for the response, and then makes the next request until it gets to the end of the list.
Connect your Zaber device to power and a serial port, then select the serial port on the front panel. Click the Run arrow, and the device will take 5 steps backwards, and then extend back to where it started. The device has to start at least 50000 microsteps away from the home position, so if you receive error response 21, just extend the device before running the VI. All commands are sent to Zaber device number 1.
Beginner - Send Commands in a Loop
|You can repeat commands using for loop or while loop structures. This example shows how to use a for loop to replace the five
Note that the error line needs to use a shift register in the loop, so that an error will get carried forward through later iterations.
Now that you've seen two, here are some features common to most of our examples:
Intermediate - Read Input from User and Display Responses
|By default, this example behaves the same as the previous one, but now it asks the user how many moves to make, how big each move should be, and which device to use. It also displays all the responses from the device.
The block diagram shows how to read input from controls and display output in indicators. It also shows how to build a request cluster using the Bundle function and then change it using the Bundle By Name function. It uses a self test to make sure that the device is connected before we start sending move commands. In addition to the error and COM port wires, we now have a Responses wire flowing along the bottom of the diagram. We wire the responses indicator inside the loop so that the response list will get updated after each command finishes.
Intermediate - Read Response Data
|Most commands return some kind of data, and you can use that data. In this example, we check that there is room for the movement before starting. This example introduces the Unbundle By Name function.
Note that not all commands are included in the drop down list. This example uses command 53: Return Setting with command 45: Set Current Position as the data value. To use a command that's not in the drop down list, select <Other>... and then type the command number. See your user manual for a complete list of all commands.
Expert - Change Timeout
|Connect your Zaber device to power and a serial port, then select the serial port below. Click the Run arrow above, and this will send an Echo
command to device number 1 to make sure it's connected, then send a home command.
If you disconnect the power and then Click the Run arrow, you'll get a timeout error. If you run one of the beginner examples with disconnected power, it just waits for a response forever and never finishes.
Timeouts are disabled by default because some movement commands can take a long time to execute. Most will finish in a few seconds, but a large device executing a slow move could take hours.
However, timeouts can be useful for detecting things like a disconnected device. This shows you how to set the timeout before a command, and then set it back to its original value.
Although movement commands can vary widely in how long they take to complete, any command that changes or reads a setting will respond in less than a second.
Expert - Enter a List of Commands
|This example is more general purpose than the previous ones. It lets you enter a list of commands and then executes them, waiting for responses before sending the next command. If you send any commands to device 0 (All devices) or any group aliases, be sure to tell each command how many responses to wait for. This example is similar to the script editor in the Zaber Console.
Labview features demonstrated here include autoindexed input from the Requests array, and a case structure around the Request (doesn't send after the quit button is clicked).
Expert - Simultaneous Requests
|This example sends the same requests to two devices simultaneously. It sends a request to each device, and then waits for two responses before sending the next pair of requests.
The block diagram demonstrates using multiple writes with blocking reads to send simultaneous requests to two devices, instead of waiting for the first device's command to complete before sending the second one.
Expert - Write Commands and Read Responses
|Another general purpose example. It lets you send one command at a time and displays any responses that come back from the device. This is useful if you want to see responses that aren't caused by requests from the computer, such as manual control or joystick control. This example is similar to the command grid in the Zaber Console.
The block diagram is an example of the state machine pattern. It starts in the "Select Port" state and waits until you select a port. Then it opens the port in "Open" and goes to "Read". It stays in "Read" and checks for responses until you click a button. "Write" sends the command and then goes right back to "Read". "Close" exits.
The diagram screenshots shown here are for the "Read" state and the "Write" state.
Custom Error Codes
Our instrument driver defines these custom error codes:
- error response from device
- partial response packet
- failed self test
Any other error codes must be coming from somewhere else. One common error is "VISA: (Hex 0xBFFF0015) Timeout expired before operation completed." or error code -1073807339. This occurs if you've set a timeout on the serial port and no response is received. If you get this error from the self-test, be sure that you've selected the right device number, and that the device is turned on and connected to the computer.