Programming Environment for Numerical Computing

Modules for Instrumentation

Solis includes modules related to instrumentation using the lvisa and lserial interfaces:

lvisa module to control instruments through GPIB, USB, Serial, Ethernet, etc. This module works with the interface VISA drivers (tested with NI and Agilent/Keysight GPIB cards. The drivers can be freely downloaded from the company site).
Using lvisa is straightforward: load module, initialize, open visa connection, communicate and finally close connection.
Below an exemple of using lvisa:

Example:

Copy the following script in the editor...

cls()
local vi = require("lvisa") -- load the lvisa module
vi.load("visa32.dll") -- load the driver DLL
v = vi.open("GPIB::8::INSTR") -- open GPIB connection
vi.write(v, "*IDN?") -- send command to device
time.sleep(50) -- sleep during 50 ms
r,n = vi.read(v,100) -- read device IDN
print(r) -- print it
vi.close(v) -- close connection
print(vi.status()) -- print status

... and click Run (or press F12 on Windows and Linux)

 

lserial module to control instruments through the serial interface. To use lserial: load module, initialize, open lserial connection, communicate and finally close connection. Below an exemple of using lserial:

Example:

Copy the following script in the editor...

cls()

-- load the serial C module
local lserial = require("lserial")

-- print out info about the serial C module release
print(lserial.version())

-- open the serial port and configure it
-- port_handle = lserial.open(port_num, settings, verbose)
-- port_num: usually 1 (COM1) or 2 (COM2)
-- settings has the same meaning than in the Windows BuildCommDCB
-- function except that BuildCommDCB has no 'timeout' parameter
-- that is specific to this Solis module
-- verbose (optional): true to show detailed messages
-- returns the port handle
p = lserial.open(1, "baud=4800 parity=n data=8 stop=2 timeout=1000", true)

-- write to the serial port
-- lserial.write(port_handle, command)
-- port_handle: the port handle, as returned by lserial.open
-- command to send to the device
-- returns the number of bytes written
lserial.write(p, "*IDN?\n")

-- read from the serial port
-- r,n = lserial.read(port_handle, bytes)
-- port_handle: the port handle, as returned by lserial.open
-- bytes: number of bytes to read
-- returns the string read and the number of bytes read
r,n = lserial.read(p, 128)
io.write("\n recv = ", r, " ; bytes read = ", n)

-- close the serial port
-- lserial.close(port_handle)
-- port_handle: the port handle, as returned by lserial.open
lserial.close(p)

... and click Run (or press F12 on Windows and Linux)

 

 Copyright(C) 2010-2023 Sidi HAMADY