The 3rd post in this Program the Device series talks about initial LabVIEW integration. An unstructured test to see if I can set up a meaningful conversation with the instrument.
In this I resume where the previous one ended, showing how to read the current frequency and close the session. In a next post, I'll break this flow up in the traditional LabVIEW Virual Instrument blocks (Init, Close, basic Read and Write, and some advanced blocks to set and get favourite values, e.g. Set Freq, Get Freq, Set Waveform, ...) |
Full LabVIEW Flow (part b)
You can see the full process in the header of the previous post. There are two remaining activities
Read Current Frequency
API function: uci_ReadX()
image: read the frequency that the instrument is currently set to
The left block is again a Call Library Function block on the right side, now configured for dll function uci_ReadX(). I will not repeat the inputs and outputs we see in each block.
The two parameters I want to highlight are the command string and return value size.
The command is a literal constant now. The same one I used in post 1, to read channel 0's frequency. When I build the driver, I will parameterise the channel number. Some UCI capable instruments have two channels.
The response size is set to 8. That's the number of bytes returned by this call, in the documentation.
On the output side, you see a construct to translate the 8 bytes reply array to a double.
First the array is flattened, so that it becomes a 4 byte string. Then the byte order is swapped for endianness.
Finally, this reversed byte string is type-cast into a double that you can show on the LabVIEW front panel.
image: front panel, with the frequency that we just read in orange
Close the Session
API function: uci_Close()
image: session and resource cleanup
The tail end of this test flow closes the session. This releases the USB handle we're using.
DLL resources are freed, and other programs can now access the instrument again.
The only input is the active session, that's been passed through the flow from the very first block on.
The session is no longer valid after this call. If you want to submit new commands, you need to reopen the instrument.
In action:
Related blog: