I'm building a SCPI programmable Lab switch with a Raspberry Pi and PiFace Digital.
Communication is over TCP/IP.
In this post: the LabVIEW drivers
What is this Lab Switch?
This is a lab instrument. A switch that can be controlled via commands, over the network.
The switch hardware is a combination of two off-the-shelf components: a and a .
All inputs and outputs of the PiFace Digital are accessable via commands. You can read the inputs and set the outputs. All on the 3V3 logic level.
Two of the outputs are connected to a relay. You can use them to switch in and out signals or devices in your automated lab setup.
What is this LabVIEW Driver?
The driver is a library of controls that help you to talk to the Lab Switch.
You use these controls in your LabVIEW process flows. They allow you to make a connection, control the hardware, then close the used resources.
The LabVIEW blocks that are finished are the Open and Close block to start and finish communication with the Pi, and the Switch control.
The Read component to retrieve the status of both inputs and outputs is on the todo list.
Here's an example that shows how these blocks can fit in a process.
I'm using a GUI here to talk to the instrument, because it's helpful to show visibly that the drivers work.
In an automated flow the inputs will very likely be some logic.
This video shows the example in action:
The article builds upon the previous posts. They explain what software needs to run.
You'll need to run the SCPI and Instrument service on your Pi. You can find the sources in previous posts.
(they are not attached I see. I'll do that if there's interest in this subject)
Here are the commands to execute them. No sudo needed on ubuntu.
./linux_piface_digital_service_cpp 2223 & ./linux_scpi_socket 2222 2223 &
In this block you set the connection parameters. At runtime, LabVIEW will use these to initiate the communication with your instrument.
It will verify that the ID of the instrument is what's expected (if you switch on the ID Query button).
On exit, you have an active instrument connection (VISA resource in LabVIEW lingo) that can be used to send commands and get info.
The three blocks that are surrounded by a structure have different subflows based on the conditions.
The first block queries the instrument ID if the ID Query is set to true, as shown above.
When you switch ID Query off, the structure does nothing:
If you make a GUI for your automation, you typically copy the Visa Name in control and paste it on your flow's screen. Then connect that control to the init block.
For a flow without a GUI, you would put the connection string in a constant or property, then pass it on.
It's not recommended to change the setting in the Init block's GUI itself, because that can be shared across projects and flows.
This block, typically the last one in a process, nicely closes the instrument resources. It releases the connection.
I'm not showing the GUI for this one because all inputs are expected to come from the process flow.
Switch Control block
This block controls the outputs of the PiFace.
There are controls for Enable and Pin. In your flow, you either copy them to your GUI orfeed them the info from other flow elements.
Like in the other blocks, please do not alter these elements in the Switch Control GUI themselves. It's a shared object.
This block will send the requested state and pin number to the Pi. It forms a SCPI command string and shoots that over the network.
A typical string would be like this:
You can use this block anytime you need to control one of the instrument's outputs.
The outputs 0 and 1 on the PiFace are linked to the two relays on that hat. Very useful to switch in and out some components or circuits in your setup.
Let's have a look at the example from the begin again.
I've coloured the controls that are copied from the library building blocks orange. The ones added for this flow are in a purple rectangle.
In the beginning of the flow, there's an init block that gets the connection parameters from the GUI element we copied from that init's block GUI.
We then enter a set of while loops that allow us to keep on controlling the process until you check the Exit button.
The values for Enable and Pin are retrieved, and sent to the Switch Control when you press Apply.
If you have the exit check button on, this will also cause the flow to go to the Close block and stop.
As long as you keep that checkbox off, you can keep on controlling the instrument.
Check the video above to see how it works.
The LabVIEW library is attached to this post.