BBN-Q / Instruments.jl

Instrument control in Julia
Other
39 stars 23 forks source link

Instrument control by SCPI command via telnet server for instruments with ethernet interface #6

Open lecagot opened 8 years ago

lecagot commented 8 years ago

Currently Instruments.jl requires NI-VISA to control the instruments. However, all(? at least most) instruments complying to the SCPI standard with an ethernet interface run a telnet server on ports 5024/5025. That way it is possible to control the instrument by SCPI commands without using the NI-VISA library, which circumvents the cumbersome driver installation (on 64-bit Linux):

  1. open telnet connection to instrument on port 5024/5025
  2. send SCPI command
  3. (optional) read reply
  4. close telnet connection

Are there any plans to implement this as an alternative to using NI-VISA? In that case the NI-VISA library could be optional.

Additionally: that method could also easily be used with the PROLOGIX GPIB-Ethernet Controller, which also runs a telnet server and is a cheap alternative to provide access to GPIB instruments via ethernet.

This should maybe be handled as a feature request. I'm completely new to Julia and first have to dig my head in, so I won't be able to implement that myself in the beginning.

caryan commented 8 years ago

@lecagot we'd certainly like to move to a back-end that doesn't require NI-VISA. At the same time we'd like to keep it compatible with NI-VISA as a backup for interfaces or OSs that are difficult to support. e.g. we have a number of USB instruments and we need to support Windows. I really like the way the PyVISA folks have done it with pyvisa-py. It's straightforward to imagine how to use Julia's network I/O and SerialPorts.jl to get most of this working and we'll slowly get there.

GPIB is another issue. We have a couple of the PROLOGIX in the lab and they work just fine in Julia. Below I've got a SR830 lock-in and a Keithley 230 hooked up on addresses 9 and 12 respectively

cryan@cryan-Precision-5510 ~ $ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.2 (2015-12-06 21:47 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-linux-gnu

julia> sock = connect("192.168.5.200", 1234)
TCPSocket(open, 0 bytes waiting)

julia> println(sock, "++addr 9")

julia> println(sock, "*IDN?")

julia> readline(sock)
"Stanford_Research_Systems,SR830,s/n54564,ver1.07 \n"

julia> println(sock, "++addr 12")

julia> println(sock, "*IDN?")

julia> readline(sock)
"NDCV+0.0000E+0,I+2.0000E-3,W+3.0000E-3,L+1.0000E+0\r\n"

julia> close(sock)

julia>

The annoying thing about wrapping the Prologix is that we'll have to inject the appropriate ++ commands to demux between the different instruments for GPIB address and potentially line termination characters.

lecagot commented 8 years ago

I understand the reasoning to keep NI-VISA, however this should be optional for people who don't need GPIB/USB support from the VISA library and only use ethernet-connected devices. Instruments.jl is so far not installable/buildable via Pkg.add("Instruments") if the NI-VISA library is not found on the system.

Communicating and controlling via port 5025 is very simple and straightforward. Example with scpi function:

ip = "192.168.0.33"
port = 5025

instr = connect(ip, port)

function scpi(instr, cmd)
    # clear status data
    println(instr, "*CLS")
    println(instr, cmd)
    if cmd[end] == '?'
        # get rid of newline character
        response = readline(instr)[1:end-1]
        return response
    end
end

println(scpi(instr, "*IDN?"))
$ julia instr.jl
Keysight Technologies,E36106A,MYx,0.3.8-0.36

Using a socket connection to port 5025 - which most, but not all LXI-compliant manufacturers offer - eliminates the necessity to use VISA/VXI-11/LXI to remote control the instrument (as with the Prologix adapter).