com.agilent.android.io
Class IO

java.lang.Object
  extended by com.agilent.android.io.IO

public class IO
extends java.lang.Object

Allows you to control a LAN instrument using a Socket connection.


Nested Class Summary
static class IO.BinaryBlockDataType
          Specifies the type of data that makes up the IEEE Block Data.
 
Field Summary
 int connectTimeout
          The number of milliseconds to wait for a connection to connect.
 boolean isConnected
          Specifies whether a connection has been made to the instrument.
 java.lang.String newLineToken
          This string sequence (typically \n) specifies the value that will terminate a Scan call be appended to the end of the data on a Print call Defaults to "\n".
 int printTimeout
          The number of milliseconds to wait for an instrument to accept data.
 int scanTimeout
          The number of milliseconds to wait for an instrument to return data.
 
Constructor Summary
IO()
           
 
Method Summary
 void close()
          Close the connection to the instrument.
 void deviceClear()
          Sends a device clear command to the instrument.
 void openWithAddress(java.lang.String address, int port)
          Open a connection to the instrument.
 void print(java.lang.String message)
          Sends a string of data to the instrument, automatically appending the newLineToken.
 void print(java.lang.String message, boolean appendNewLine)
          Sends a string of data to the instrument
 void printBuffer(byte[] buffer, int size)
          Sends a byte array of data to the instrument.
 void query(java.lang.String query, java.lang.StringBuffer response)
          Send a string of data to the instrument, then reads a string of data from the instrument
 void queryDeviceClearPort(java.lang.String query)
          Queries the instrument for the port that should be used when doing a deviceClear.
 double[] readList()
          Reads a list of data values from the instrument.
 void scan(java.lang.StringBuffer response)
          Reads a string of data from the instrument, automatically removing the newLineToken from the end of the data
 void scan(java.lang.StringBuffer response, boolean trimNewLine)
          Reads a string of data from the instrument
 double[] scanBinaryDefiniteSizeBlocks(IO.BinaryBlockDataType dataType)
          Reads an IEEE Binary Block of data from the instrument
 void scanBuffer(byte[] buffer, int sizeToRead)
          Reads a byte array of data from the instrument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectTimeout

public int connectTimeout
The number of milliseconds to wait for a connection to connect. Default is 5000.


scanTimeout

public int scanTimeout
The number of milliseconds to wait for an instrument to return data. Default is 5000.


printTimeout

public int printTimeout
The number of milliseconds to wait for an instrument to accept data. Default is 5000.


isConnected

public boolean isConnected
Specifies whether a connection has been made to the instrument.


newLineToken

public java.lang.String newLineToken
This string sequence (typically \n) specifies the value that will Defaults to "\n".

Constructor Detail

IO

public IO()
Method Detail

openWithAddress

public void openWithAddress(java.lang.String address,
                            int port)
                     throws AAIoException
Open a connection to the instrument.

Parameters:
address - the IP address (e.g. 156.140.113.207) or hostname of the instrument
port - number the instrument is connection on, usually 5025
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following 2 values
  • ErrorType.CONNECT_ERROR if there was some exception thrown by the underlying socket library, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the connection could be made

close

public void close()
Close the connection to the instrument. If you fail to close the connection to the instrument, you will eventually be unable to open a new connection. Instruments typically allow 1-6 concurrent connections.


queryDeviceClearPort

public void queryDeviceClearPort(java.lang.String query)
                          throws AAIoException
Queries the instrument for the port that should be used when doing a deviceClear. This method MUST be called before deviceClear() is called.

Parameters:
query - the command that is issued to the instrument to query for its control port. Defaults to:
system:communicate:tcpip:control?
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading from the instrument, check the inner exception
  • ErrorType.WRITE_ERROR if there was some exception thrown by the underlying socket library while writing to the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be sent/received

printBuffer

public void printBuffer(byte[] buffer,
                        int size)
                 throws AAIoException
Sends a byte array of data to the instrument.

Parameters:
buffer - the data to be sent. Last byte should be the newLineToken (typically \n)
size - number of bytes in the buffer to send
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.WRITE_ERROR if there was some exception thrown by the underlying socket library while writing to the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be sent

print

public void print(java.lang.String message)
           throws AAIoException
Sends a string of data to the instrument, automatically appending the newLineToken.

Parameters:
message - the data to be sent
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.WRITE_ERROR if there was some exception thrown by the underlying socket library while writing to the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be sent

print

public void print(java.lang.String message,
                  boolean appendNewLine)
           throws AAIoException
Sends a string of data to the instrument

Parameters:
message - the data to be sent
appendNewLine - true to append the newLineToken, false to not append the newLineToken
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.WRITE_ERROR if there was some exception thrown by the underlying socket library while writing to the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be sent

scanBuffer

public void scanBuffer(byte[] buffer,
                       int sizeToRead)
                throws AAIoException
Reads a byte array of data from the instrument

Parameters:
buffer - array where the data should be stored
sizeToRead - number of bytes to be read from the instrument
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading data from the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read

scan

public void scan(java.lang.StringBuffer response)
          throws AAIoException
Reads a string of data from the instrument, automatically removing the newLineToken from the end of the data

Parameters:
response - where the data should be stored
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading data from the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read

scan

public void scan(java.lang.StringBuffer response,
                 boolean trimNewLine)
          throws AAIoException
Reads a string of data from the instrument

Parameters:
response - where the data should be stored
trimNewLine - true to remove the newLineToken from the end of the buffer, false to not remove the newLineToken from the end of the buffer
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading data from the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read

readList

public double[] readList()
                  throws AAIoException
Reads a list of data values from the instrument. This method assumes the list separator is a comma

Returns:
the data values converted to double's
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading data from the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read

scanBinaryDefiniteSizeBlocks

public double[] scanBinaryDefiniteSizeBlocks(IO.BinaryBlockDataType dataType)
                                      throws AAIoException
Reads an IEEE Binary Block of data from the instrument

Parameters:
dataType - the type of data that should be read
Returns:
the data values converted to double's
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading data from the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read

query

public void query(java.lang.String query,
                  java.lang.StringBuffer response)
           throws AAIoException
Send a string of data to the instrument, then reads a string of data from the instrument

Parameters:
query - the data to be sent to the instrument
response - where the data should be stored
Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.READ_ERROR if there was some exception thrown by the underlying socket library while reading data from the instrument, check the inner exception
  • ErrorType.WRITE_ERROR if there was some exception thrown by the underlying socket library while writing to the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read

deviceClear

public void deviceClear()
                 throws AAIoException
Sends a device clear command to the instrument. This method should be called if a send/read fails, in order to clear the I/O buffers on the instrument

Throws:
AAIoException - the ErrorType property of the thrown exception can have the following values:
  • ErrorType.CONNECT_ERROR if there was some exception thrown by the underlying socket library, check the inner exception
  • ErrorType.WRITE_ERROR if there was some exception thrown by the underlying socket library while writing to the instrument, check the inner exception
  • ErrorType.TIMEOUT_ERROR if the timeout lapsed before the data could be read