This is a sample LabVIEW .vi which uses .NET to call into Wasatch.NET, Wasatch Photonics' primary open-source library for controlling spectrometers from Windows.
As such, the API utilized by Wasatch.LV is that published by Wasatch.NET, which can be reviewed at any of the following links:
- Rendered Doxygen, e.g.:
Note that Wasatch.NET itself is simply a C# wrapper over the spectrometers' USB API, implemented in firmware and published in the following engineering specifications:
For NXG instructions, see NXG.
The LabVIEW demo requires Wasatch.NET (2.3.14 or later recommended).
Please download and run either the 32-bit or 64-bit (see below) installer for Wasatch.NET and follow the driver installation process before attempting to run the WasatchDemo.vi.
This demo has been tested on LabVIEW 2018 32-bit and LabVIEW 2018 64-bit.
If you are using 32-bit LabVIEW (the typical case, even on 64-bit Windows), then you should install the 32-bit version of Wasatch.NET.
If you are using 64-bit LabVIEW, then you should install the 64-bit version of Wasatch.NET.
When you first open the WasatchDemo.vi, it may ask you to point it to the location of WasatchNET.dll on your system. That will typically be one of the following two paths, depending on which version of the driver you installed:
- C:\Program Files\Wasatch Photonics\Wasatch.NET\WasatchNET.dll
- C:\Program Files (x86)\Wasatch Photonics\Wasatch.NET\WasatchNET.dll
Here's a quick tutorial on how to create a LabVIEW Virtual Instrument (.vi) controlling Wasatch Photonics spectrometers using our Wasatch.NET DLL.
Now you have to tell LabVIEW which DLL will provide the functionality for this .NET node, since it has no "incoming reference" from a previous node to infer such things. Fortunately you only have to do this once per .vi, and can share the reference thereafter.
Here you select the top-level class exposed by WasatchNET.dll that you wish to reference through the .NET Node. The Driver class is what we want: it's the starting point from which you can dig down into all the Wasatch.NET goodness.
These are the API docs for the WasatchNET.Driver class which we'll be using:
To actually call the Driver class's getInstance() static method, you can select it from the "Method" drop-down. Note that static methods are indicated with a leading [S].
Let's go ahead and drop several more .NET Invoke Node controls onto the block diagram. We'll wire them up shortly to step through the spectrometer initialization sequence.
Wire the output reference from Driver.getInstance() to the input reference of the next .NET Invoke Node control. This will change the previously unlabeled .NET node into a Driver node. (It will infer its .NET class from the output type of Driver.getInstance).
Select the openAllSpectrometers() method of your new Driver object.
Wire the "output" reference from the openAllSpectrometers() control into the input reference on the next unlabeled Invoke Node control. Note that we're not taking the output of the openAllSpectrometers() method (which is actually an integer count of spectrometers found), but simply re-using and "passing along" the reference to our Driver singleton.
Now that the control knows (from its reference) that it's a Driver object, select its getSpectrometer() method.
Unlike previous methods we've called, the Driver.getSpectrometer() method takes an argument: the integral index of the spectrometer we wish to control. As long as you have at least one Wasatch spectrometer connected to the computer, the first should be number 0, so we'll create an integer constant "0" to pass into the getSpectrometer() method.
Just for variety, after calling all those .NET Invoke Node controls where we were calling methods on our Wasatch.NET Driver object, let's go ahead and create a Property Node as well. We'll then wire it up with a reference just like the others, and then select a property to view (in this case, the spectrometer's serial number).
Hopefully this is enough to get you started. Feel free to browse the Wasatch.NET API documentation here, since the .NET classes, methods and properties are identical whether drawing LabVIEW .vi block diagrams or writing code in C#, MATLAB or other .NET languages.
I don't have a permanent license for LabVIEW Application Builder for regular testing, but I was able to compile an executable application (.exe) from our LabVIEWDemo.vi using a 30-day evaluation license for Application Builder 8.5.1 using this process. My .vi was saved from LabVIEW 2018 (32-bit).
First I naively used Application Builder to create an application from LabVIEWDemo.vi with no special settings, which by default it generated as “Application.exe”.
I tried running the generated Application.exe, and it reported "No spectrometers found," as customers have reported.
I then copied WasatchNET.dll, LibUsbDotNet.dll and libusb-1.0.dll into the same directory as the Application.exe file. (I’m not sure if all of those are required, but I thought I’d give it the full set of potential dependencies.)
I then re-ran the executable, and it was able to find my connected spectrometer and run normally.
I noted that the Application Builder automatically generated a "data" directory with a copy of WasatchNET.dll, which it recognized as a dependency. This suggested that the "data" folder was already internally added to the application's DLL search path, so I tried moving all the DLLs into that folder, and confirmed that it ran fine in that configuration as well.
I've posted a zipfile of the complete application folder here:
Note that LabVIEW requires all DLL dependencies to be together in the same folder. Therefore, you should probably point to the WasatchNET.dll installed in C:\Program Files (x86)\Wasatch Photonics\Wasatch.NET, which has all dependent DLLs grouped for convenience.
Make sure that after installing Wasatch.NET, you updated the device drivers for your spectrometers.
Most common reason for this seems to be trying to use a 64-bit version of Wasatch.NET with a 32-bit version of LabVIEW, or vice-versa.
WasatchNET.dll requires several other DLL dependencies. Most of these are normally installed automatically alongside WasatchNET.dll, typically in one of these two directories depending on which installer architecture you select:
- C:\Program Files\Wasatch Photonics\Wasatch.NET
- C:\Program Files (x86)\Wasatch Photonics\Wasatch.NET
Some DLLs (including LibUsbDotNet.dll) are normally installed directly to C:\Windows, which should work fine as that directory is always in the Windows executable search path (%PATH%).
If you receive FileNotFoundExceptions, please confirm that Wasatch.NET has been installed via the binary installers. Recent versions are typically available from here:
- see Changelog