Working with the UNI-T UTG962E signal generator using the VISA interface
This example discusses working with external equipment from Engee, the UTG962E signal generator using the VISA specification and SCPI commands. Connection settings, memory polling, reset, and configuration of the generator output port are performed. The basic techniques for automating work with a signal generator in Engee are shown.
Introduction
Engee has built-in capabilities for working with external hardware, including interacting with a computer via VISA.
Preparation for work
First of all, you need to install the external hardware support package and establish a connection from the host program. Detailed step-by-step instructions are provided in Engee documentation and Community examples.
The next step is to connect the UT962E signal generator and make sure that the device drivers are installed.
After completing the preparatory steps, we will proceed to establish a connection between Engee and the signal generator, first connecting the necessary support package module.:
using Main.EngeeDeviceManager.Devices.VISA
Connection Setup
Creating a VISA object:
visa = VISA.Visa()
After that, we will create a session for working with VISA tools.:
VISA.create_session(visa, "@py")
Getting a list of available physical ports:
ports = VISA.get_ports(visa)
The last port from the list corresponds to our signal generator. Let's save its ID separately.:
port = last(ports)
Let's create an abstraction of the tool on the specified port for working with VISA:
VISA.create_instrument(visa, port)
The connection to the device is established, you can proceed directly to work.
Executing simple commands
The programming of the VISA signal generator is carried out using SCPI commands specific to the device. The full list is available in manufacturer's documentation.
Team *IDN? returns data about the device:
- Manufacturer's name,
- Device model,
- Serial number,
- the firmware version.
To send commands and receive information from the device, use the function VISA.writeread(), which transmits the previously created VISA object, the port identifier, the SCPI command, and the waiting time to receive information from the device.
VISA.writeread(visa, port, "*IDN?", 1.2)
Reset the signal generator settings to factory settings using the command *RST and lock his push-button keyboard with the command :SYSTEM:LOCK OFF.
You can send both commands at the same time, using a separator. ; using the command recording function  VISA.write().
VISA.write(visa, port, "*RST;:SYSTEM:LOCK OFF");
Changing the shape of the generated signal
We will find out the current shape of the generated signal on the first channel of the device. To do this, write the command to it :CHAN1:BASE:WAV?.
VISA.writeread(visa, port, ":CHAN1:BASE:WAV?", 1.2)
Please note that this function should only send commands to the device that require responses to be sent to the programmer. Such commands can be easily identified by the question mark that ends them.
Answer SINe indicates that the current waveform is sinusoidal. Let's change the shape to triangular (RAMP) using the command :CHAN1:BASE:WAV RAMP
VISA.write(visa, port, ":CHAN1:BASE:WAV RAMP");
VISA.writeread(visa, port, ":CHAN1:BASE:WAV?", 1.2)
Another check of the waveform returns a message to us RAMP This means that the waveform has been successfully changed. Now we will write commands to the generator to alternately change the waveform for all available options.:
FORMS = ["SIN","SQU","PULS","RAMP","ARB","NOIS","DC"];
The next cycle will allow us to switch the shape of the generated signal, after which the device settings will be reset.
for form in FORMS
    VISA.write(visa, port, ":CHAN1:BASE:WAV $form");
    sleep(1);
end
VISA.write(visa, port, "*RST");
 
As can be seen from the recording, the generator correctly processes the transmitted commands, changing the shape of the generated signal.
Graphical interface in the Engee script
To write a set of commands to the device for the full configuration of the generated signal, it is convenient to write them into a vector Vector{String} and pass, for example, to the following auxiliary function:
"""
Функция для записи в UTG962 SCPI команд, записанных в вектор
"""
function UTG962_write(command::Vector{String})
    for com in command
        VISA.write(visa, port, com);
        sleep(1);
    end
end;
The ability to add a code cell mask to the Engee script allows you to implement a simple graphical interface for the generator:
Канал = "1" # @param ["1","2"]
Форма = "RAMP" # @param ["SIN","SQU","PULS","RAMP","ARB","NOIS","DC"]
Частота_Гц = 271423 # @param {type:"slider",min:1,max:1000000,step:1}
Фаза_град = 0 # @param {type:"slider",min:-360,max:360,step:1}
Амплитуда = 3.587 # @param {type:"slider",min:0.002,max:20,step:0.001}
message = [
    ":CHANnel$Канал:MODe CONTinue",
    ":CHANnel$Канал:BASE:WAVe $Форма",
    ":CHANnel$Канал:BASE:FREQuency $Частота_Гц",
    ":CHANnel$Канал:BASE:HIGH $Амплитуда",
    ":CHANnel$Канал:BASE:LOW 0",
    ":CHANnel$Канал:BASE:PHAse $Фаза_град",
    ":CHANnel$Канал:OUTPut ON"
]
UTG962_write(message)
# VISA.write(visa, port, message);
# sleep(1);
# VISA.write(visa, port, ":CHAN$Канал:BASE:FREQ $Частота_Гц");
# sleep(1);
# VISA.write(visa, port, ":CHAN$Канал:BASE:PHAS $Фаза_град");
# sleep(1);
# VISA.write(visa, port, ":CHAN$Канал:BASE:AMPL $Амплитуда");
# sleep(1);
# VISA.write(visa, port, ":CHAN$Канал:OUTP ON");
 
From the recording, you can see how using the code cell mask and the Engee script, you can implement full-fledged control of the signal generator.
An example from the manufacturer
The manufacturer's documentation provides an example of programming a sawtooth signal using SCPI commands. It can also be reproduced in Engee.:
Sawtooth = [
    ":CHANnel1:MODe CONTinue",
    ":CHANnel1:BASE:WAVe RAMP",
    ":CHANnel1:BASE:FREQuency 30000",
    ":CHANnel1:BASE:HIGH 2",
    ":CHANnel1:BASE:LOW 0",
    ":CHANnel1:BASE:PHAse 90",
    ":CHANnel1:RAMP:SYMMetry 20",
    ":CHANnel1:OUTPut ON"
]
UTG962_write(Sawtooth)
After executing these commands, the generator will set the following expected signal settings:
 
Completion of work
To complete the operation correctly, it is necessary to release the tire for the tool.:
VISA.close_instrument(visa, port)
And close the session with the tool:
VISA.close_session(visa)
Conclusion
In the example, we examined the capabilities of Engee to work with external equipment - the UTG962 signal generator according to the VISA specification. Using the SCPI command, you can program the device and get the current parameter values. Engee allows you not only to automate work with the device, but also to implement a user-friendly and simple graphical interface without additional tools.