Engee documentation

Working with external equipment via VISA in Engee

Page in progress.

VISA (Virtual Instrument Software Architecture) is a specification designed to unify the interaction with measurement instruments.

VISA provides an abstraction for communicating with different types of hardware such as USB, Ethernet, GPIB and other interfaces. In the context of Engee, VISA is used to integrate third-party instrumentation and allow it to be controlled via Julia code without leaving Engee.

To start working with VISA in Engee it is necessary to connect the external equipment support package, start the client programme and insert in it the URL for the server operation on the Engee side, for more details see engee-hardware/integration-with-hardware.adoc#hardware-installation.

After that it is necessary to create a VISA object, which will be used for interaction with measuring instruments:

visa = VISA.Visa()

Basic methods of working with VISA

The following methods are used to work with devices connected via VISA specification:

  • VISA.close_instrument - frees the bus for the device connected via VISA specification.

  • VISA.close_session - closes the VISA operation session.

  • VISA.create_instrument - creates an instance of an instrument connected via the specified port.

  • VISA.create_session - creates a session for working with VISA.

  • VISA.flush - clears I/O buffer of the device.

  • VISA.get_ports - gets the list of available physical ports.

  • VISA.read - reads data from the device.

  • VISA.readbinblock - reads binary data from the device.

  • VISA.visatrigger - provides interrupt commands to the device.

  • VISA.write - writes messages to the device.

  • VISA.writebinblock - writes binary data to the device.

  • VISA.writeread - writes to the device and reads the response.

For a detailed description of each method, see the article VISA software control.

Step-by-step example of working with VISA

Let’s consider an example in which a session is created, a list of ports is obtained, a device is created, a command is written to the device and the response is read:

  1. Create a session to work with VISA appliances - create a session by specifying a hardware implementation (e.g. @py):

    VISA.create_session(visa, "@py")
    Read more about the hardware implementation at link.
  2. Get the list of available physical ports - get the list of available ports and select the last one:

    ports = VISA.get_ports(visa).data
    port = last(ports)
  3. Create an instrument abstraction on the specified port - create an instrument to work with the selected port:

    VISA.create_instrument(visa, port)
    If you need to work with more than one instrument, repeat the VISA.create_instrument(visa, port) command with the port of another device.
  4. Send a message to reset the instrument - send a command to reset the instrument:

    VISA.write(visa, port, "*RST;:SYSTEM:LOCK OFF", "")
  5. Write data to the instrument and read the response with delay - send a command and read the response with a delay of 1.2 seconds:

    writeread_result = VISA.writeread(visa, port, ":CHAN1:BASE:WAV?", 1.2).data
  6. Read message from the instrument - read data from the instrument (make sure that the instrument sends data):

    read_result = VISA.read(visa, port, "").data
  7. Write binary data to the instrument - write two bytes to the instrument:

    VISA.writebinblock(visa, port, [0x01, 0x00])
  8. Read binary data from the instrument - read 8 bytes of data from the instrument:

    bytes = VISA.readbinblock(visa, port, 8).data
  9. Initiate an interrupt in the device - send an interrupt command (may not be available on some devices):

    VISA.visatrigger(visa, port)
  10. Clear I/O write buffer in the device - clear the write buffer (may not be available on some devices):

    VISA.flush(visa, port, "flush_write_buffer")
  11. Clearing the bus for an instrument - clear the bus to allow other instruments to use the port:

    VISA.close_instrument(visa, port)
  12. Close instrument session - close the VISA session:

    VISA.close_session(visa)

Possible problems and their solutions

  1. Port mapping problem - if the VISA.get_ports method does not return available ports, make sure that the measurement equipment is available on the user side:

    • In Linux, interacting with the equipment may require running an installed client program with sudo privileges or adding a user to the dialout group.

    • In Windows, check that all required drivers are installed and run the client program as administrator if necessary.

  2. Problem with Ethernet devices - To work with an Ethernet connection, make sure the interfaces are configured correctly. If the port is returned in "TCPIP::INSTR" format, use it to create an instrument using the VISA.create_instrument function:

    VISA.create_instrument(visa, "TCPIP::INSTR")
  3. Blocking the transfer bus - if after calling VISA.write the next call fails, the transfer bus is probably blocked. Free up resources with VISA.read.

  4. Driver conflicts - if the instrument drivers and VISA implementation drivers conflict, check the user-side instrument logs for missing drivers.