Package jisa.visa
Class VISADevice
- java.lang.Object
-
- jisa.visa.VISADevice
-
- All Implemented Interfaces:
Instrument
- Direct Known Subclasses:
ADRelay
,AgilentE3644A
,AgilentSPA
,ArroyoTEC
,CryoCon22C
,ILM200
,IPS120
,ITC503
,K2182
,K2200
,K236
,K2600B
,KeithleySCPI
,LS331
,LS336
,MercuryITC
,Pegasus
,SR560
,SR830
,TSX3510P
public class VISADevice extends java.lang.Object implements Instrument
Generic instrument encapsulation via VISA
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jisa.devices.interfaces.Instrument
Instrument.AutoQuantity<S>, Instrument.OptionalQuantity<S>, Instrument.Parameter<S>, Instrument.Setter<S>, Instrument.TableQuantity
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
C_IDN
static int
CR_TERMINATOR
static int
CRLF_TERMINATOR
static int
DEFAULT_EOI
static int
DEFAULT_EOS
static int
DEFAULT_TIMEOUT
static int
EOS_RETURN
static int
LF_TERMINATOR
-
Constructor Summary
Constructors Constructor Description VISADevice(Address address)
VISADevice(Address address, java.lang.Class<? extends Driver> prefDriver)
Opens the device at the specified address
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAutoRemove(java.lang.String... phrases)
protected void
checkLimit(java.lang.String valueName, java.lang.Number value, java.lang.Number lower, java.lang.Number upper)
protected void
checkLimit(java.lang.String valueName, java.lang.Number value, java.lang.Number lower, java.lang.Number upper, java.lang.String unit)
Method to check limits of instruments values, throws DeviceException exceeded.void
clearBuffers()
void
close()
Close the connection to the deviceAddress
getAddress()
Returns the address used to connect to the deviceConnection
getConnection()
java.lang.String
getIDN()
Sends the standard identifications query to the device (*IDN?)java.lang.String
getName()
Returns the name of the instrument or channel.void
manuallyClearReadBuffer()
Continuously reads from the read buffer until there's nothing left to read.java.lang.String
query(java.lang.String command, java.lang.Object... args)
Write the given string, then immediately read the responsedouble
queryDouble(java.lang.String command, java.lang.Object... args)
Write the given string, then immediately read the response as a doubleint
queryInt(java.lang.String command, java.lang.Object... args)
Write the given string, then immediately read the response as an integerjava.lang.String
read()
Read a string from the devicejava.lang.String
read(int attempts)
Read a string from the devicebyte[]
readBytes(int numBytes)
double
readDouble()
Read a double from the deviceint
readInt()
Read an integer from the devicevoid
setIOLimit(int interval, boolean read, boolean write)
Sets whether this VISADevice object should wait a minimum amount of time between successive read/write operations.void
setReadBufferSize(int bytes)
What default number of bytes should we expect to get when reading from the device?void
setReadTerminator(long term)
void
setReadTerminator(java.lang.String term)
void
setRetryCount(int count)
void
setTimeout(int msec)
Sets the timeout for read/write operations to this instrument (if applicable).void
setWriteTerminator(java.lang.String term)
Set a termination character to tell the device when we've stopped talking to itvoid
write(java.lang.String command, java.lang.Object... args)
Write the given string to the devicevoid
writeBytes(byte[] bytes)
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jisa.devices.interfaces.Instrument
getConfigurationParameters, getConfigurationParameters, getLockObject
-
-
-
-
Field Detail
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_EOI
public static final int DEFAULT_EOI
- See Also:
- Constant Field Values
-
DEFAULT_EOS
public static final int DEFAULT_EOS
- See Also:
- Constant Field Values
-
EOS_RETURN
public static final int EOS_RETURN
- See Also:
- Constant Field Values
-
LF_TERMINATOR
public static final int LF_TERMINATOR
- See Also:
- Constant Field Values
-
CR_TERMINATOR
public static final int CR_TERMINATOR
- See Also:
- Constant Field Values
-
CRLF_TERMINATOR
public static final int CRLF_TERMINATOR
- See Also:
- Constant Field Values
-
C_IDN
public static final java.lang.String C_IDN
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VISADevice
public VISADevice(Address address) throws java.io.IOException
- Throws:
java.io.IOException
-
VISADevice
public VISADevice(Address address, java.lang.Class<? extends Driver> prefDriver) throws java.io.IOException
Opens the device at the specified address- Parameters:
address
- Some form of InstrumentAddress (eg GPIBAddress, USBAddress etc)prefDriver
- Preferred driver to try first- Throws:
java.io.IOException
- Upon communications error
-
-
Method Detail
-
getConnection
public Connection getConnection()
-
clearBuffers
public void clearBuffers() throws java.io.IOException
- Throws:
java.io.IOException
-
manuallyClearReadBuffer
public void manuallyClearReadBuffer() throws java.io.IOException
Continuously reads from the read buffer until there's nothing left to read. (Clears the read buffer for the more stubborn of instruments). Do not use on GPIB instruments programmed to respond to TALK requests (it will never terminate).- Throws:
java.io.IOException
- Upon communications error
-
setIOLimit
public void setIOLimit(int interval, boolean read, boolean write)
Sets whether this VISADevice object should wait a minimum amount of time between successive read/write operations.- Parameters:
interval
- The minimum interval, in milliseconds (0 will disable this feature)read
- Whether this wait should apply to read operationswrite
- Whether this wait should apply to write operations
-
setReadBufferSize
public void setReadBufferSize(int bytes)
What default number of bytes should we expect to get when reading from the device?- Parameters:
bytes
- The number of bytes, yikes.
-
addAutoRemove
public void addAutoRemove(java.lang.String... phrases)
-
setRetryCount
public void setRetryCount(int count)
-
setTimeout
public void setTimeout(int msec) throws java.io.IOException
Description copied from interface:Instrument
Sets the timeout for read/write operations to this instrument (if applicable).- Specified by:
setTimeout
in interfaceInstrument
- Parameters:
msec
- Timeout, in milliseconds- Throws:
java.io.IOException
- Upon communications error
-
getAddress
public Address getAddress()
Returns the address used to connect to the device- Specified by:
getAddress
in interfaceInstrument
- Returns:
- Address object
-
setWriteTerminator
public void setWriteTerminator(java.lang.String term)
Set a termination character to tell the device when we've stopped talking to it- Parameters:
term
- The character to use (eg "\n" or "\r")
-
setReadTerminator
public void setReadTerminator(java.lang.String term) throws VISAException
- Throws:
VISAException
-
setReadTerminator
public void setReadTerminator(long term) throws VISAException
- Throws:
VISAException
-
write
public void write(java.lang.String command, java.lang.Object... args) throws java.io.IOException
Write the given string to the device- Parameters:
command
- The string to writeargs
- Any formatting arguments- Throws:
java.io.IOException
- Upon communications error
-
writeBytes
public void writeBytes(byte[] bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public java.lang.String read() throws java.io.IOException
Read a string from the device- Returns:
- The string returned by the device
- Throws:
java.io.IOException
- Upon communications error
-
read
public java.lang.String read(int attempts) throws java.io.IOException
Read a string from the device- Parameters:
attempts
- Number of failed attempts to read before throwing an exception- Returns:
- The string returned by the device
- Throws:
java.io.IOException
- Upon communications error
-
readBytes
public byte[] readBytes(int numBytes) throws java.io.IOException
- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
Read a double from the device- Returns:
- The number returned by the device
- Throws:
java.io.IOException
- Upon communications error
-
readInt
public int readInt() throws java.io.IOException
Read an integer from the device- Returns:
- Integer read from the device
- Throws:
java.io.IOException
- Upon communications error
-
queryDouble
public double queryDouble(java.lang.String command, java.lang.Object... args) throws java.io.IOException
Write the given string, then immediately read the response as a double- Parameters:
command
- String to writeargs
- Formatting arguments- Returns:
- Numerical response
- Throws:
java.io.IOException
- Upon communications error
-
queryInt
public int queryInt(java.lang.String command, java.lang.Object... args) throws java.io.IOException
Write the given string, then immediately read the response as an integer- Parameters:
command
- String to writeargs
- Formatting arguments- Returns:
- Numerical response
- Throws:
java.io.IOException
- Upon communications error
-
query
public java.lang.String query(java.lang.String command, java.lang.Object... args) throws java.io.IOException
Write the given string, then immediately read the response- Parameters:
command
- String to writeargs
- Formatting arguments- Returns:
- String response
- Throws:
java.io.IOException
- Upon communications error
-
getIDN
public java.lang.String getIDN() throws java.io.IOException
Sends the standard identifications query to the device (*IDN?)- Specified by:
getIDN
in interfaceInstrument
- Returns:
- The resposne of the device
- Throws:
java.io.IOException
- Upon communications error
-
getName
public java.lang.String getName()
Description copied from interface:Instrument
Returns the name of the instrument or channel.- Specified by:
getName
in interfaceInstrument
- Returns:
- Name
-
close
public void close() throws java.io.IOException
Close the connection to the device- Specified by:
close
in interfaceInstrument
- Throws:
java.io.IOException
- Upon communications error
-
checkLimit
protected void checkLimit(java.lang.String valueName, java.lang.Number value, java.lang.Number lower, java.lang.Number upper, java.lang.String unit) throws DeviceException
Method to check limits of instruments values, throws DeviceException exceeded.- Parameters:
valueName
- parameter to be checked (e.g. Voltage range)value
- value to setlower
- lower limitupper
- upper limitunit
- unit of value- Throws:
DeviceException
-
checkLimit
protected void checkLimit(java.lang.String valueName, java.lang.Number value, java.lang.Number lower, java.lang.Number upper) throws DeviceException
- Throws:
DeviceException
-
-