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.StringC_IDNstatic intCR_TERMINATORstatic intCRLF_TERMINATORstatic intDEFAULT_EOIstatic intDEFAULT_EOSstatic intDEFAULT_TIMEOUTstatic intEOS_RETURNstatic intLF_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 voidaddAutoRemove(java.lang.String... phrases)protected voidcheckLimit(java.lang.String valueName, java.lang.Number value, java.lang.Number lower, java.lang.Number upper)protected voidcheckLimit(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.voidclearBuffers()voidclose()Close the connection to the deviceAddressgetAddress()Returns the address used to connect to the deviceConnectiongetConnection()java.lang.StringgetIDN()Sends the standard identifications query to the device (*IDN?)java.lang.StringgetName()Returns the name of the instrument or channel.voidmanuallyClearReadBuffer()Continuously reads from the read buffer until there's nothing left to read.java.lang.Stringquery(java.lang.String command, java.lang.Object... args)Write the given string, then immediately read the responsedoublequeryDouble(java.lang.String command, java.lang.Object... args)Write the given string, then immediately read the response as a doubleintqueryInt(java.lang.String command, java.lang.Object... args)Write the given string, then immediately read the response as an integerjava.lang.Stringread()Read a string from the devicejava.lang.Stringread(int attempts)Read a string from the devicebyte[]readBytes(int numBytes)doublereadDouble()Read a double from the deviceintreadInt()Read an integer from the devicevoidsetIOLimit(int interval, boolean read, boolean write)Sets whether this VISADevice object should wait a minimum amount of time between successive read/write operations.voidsetReadBufferSize(int bytes)What default number of bytes should we expect to get when reading from the device?voidsetReadTerminator(long term)voidsetReadTerminator(java.lang.String term)voidsetRetryCount(int count)voidsetTimeout(int msec)Sets the timeout for read/write operations to this instrument (if applicable).voidsetWriteTerminator(java.lang.String term)Set a termination character to tell the device when we've stopped talking to itvoidwrite(java.lang.String command, java.lang.Object... args)Write the given string to the devicevoidwriteBytes(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.IOExceptionContinuously 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.IOExceptionDescription copied from interface:InstrumentSets the timeout for read/write operations to this instrument (if applicable).- Specified by:
setTimeoutin 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:
getAddressin 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.IOExceptionWrite 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionRead 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.IOExceptionWrite 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.IOExceptionWrite 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.IOExceptionWrite 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.IOExceptionSends the standard identifications query to the device (*IDN?)- Specified by:
getIDNin interfaceInstrument- Returns:
- The resposne of the device
- Throws:
java.io.IOException- Upon communications error
-
getName
public java.lang.String getName()
Description copied from interface:InstrumentReturns the name of the instrument or channel.- Specified by:
getNamein interfaceInstrument- Returns:
- Name
-
close
public void close() throws java.io.IOExceptionClose the connection to the device- Specified by:
closein 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 DeviceExceptionMethod 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
-
-