public class UsbConnection extends ConnectionA implements com.zebra.sdk.comm.internal.ConnectionI
Constructor and Description |
---|
UsbConnection(String symbolicName)
Initializes a new instance of the
UsbConnection class. |
UsbConnection(String symbolicName,
int maxTimeoutForRead,
int timeToWaitForMoreData)
Initializes a new instance of the
UsbConnection class. |
Modifier and Type | Method and Description |
---|---|
int |
bytesAvailable()
Returns number of bytes currently read from printer.
|
void |
close()
Closes this connection and releases any system resources associated with the connection.
|
ConnectionReestablisher |
getConnectionReestablisher(long thresholdTime)
Returns a
ConnectionReestablisher which allows for easy recreation of a connection which may have
been closed. |
String |
getManufacturer()
Returns the printer's manufacturer.
|
int |
getMaxTimeoutForRead()
Returns the maximum time, in milliseconds, to wait for any data to be received.
|
String |
getSerialNumber() |
String |
getSimpleConnectionName()
Return a human-readable description of the connection.
|
void |
open()
Opens the connection to a device.
|
byte[] |
read(int maxBytesToRead)
Reads up to maxBytesToRead into byte array
Performing reads using DriverPrinterConnection and UsbConnection concurrently could cause indeterminate reads |
int |
readChar()
Reads the next byte of data from the connection, similar to a Java InputStream.
|
void |
setMaxTimeoutForRead(int maxTimeoutForRead)
Set the maximum time, in milliseconds, to wait for any data to be received
|
String |
toString()
Returns the Connection Builder name of the USB device.
|
void |
write(byte[] data)
Writes
data.length bytes from the specified byte array to this output stream. |
void |
write(byte[] data,
int offset,
int length)
Writes
length bytes from data starting at offset . |
addWriteLogStream, getMaxDataToWrite, getTimeToWaitForMoreData, isConnected, read, read, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxDataToWrite, setReadTimeout, setTimeToWaitForMoreData, waitForData, write
getMaxDataToWrite, read, setMaxDataToWrite, setReadTimeout
getTimeToWaitForMoreData, isConnected, read, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setTimeToWaitForMoreData, waitForData, write
public UsbConnection(String symbolicName) throws ConnectionException
UsbConnection
class. This constructor will attempt a connection to
the printer specified in the symbolic name.symbolicName
- the USB symbolic name for the device returned by the UsbDiscoverer.getZebraUsbPrinters()
member function.ConnectionException
- if the system is not running the Windows operating system or if the device cannot be
found.public UsbConnection(String symbolicName, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException
UsbConnection
class. This constructor will attempt a connection to
the printer specified in the symbolic name.symbolicName
- the USB symbolic name for the device returned by the UsbDiscoverer.getZebraUsbPrinters()
member function.maxTimeoutForRead
- Maximum time to wait for read datatimeToWaitForMoreData
- maximum time to wait for more data after initial data is sent from printerConnectionException
- if the system is not running the Windows operating system or if the device cannot be
found.public void open() throws ConnectionException
Connection
open
method is called when this connection has already been
opened, this call is ignored. When a handle to the connection is no longer needed, you must call Connection.close()
to free up system resources.open
in interface Connection
open
in class ConnectionA
ConnectionException
- if the connection cannot be established.ConnectionA.open()
public void close() throws ConnectionException
Connection
close
in interface Connection
close
in class ConnectionA
ConnectionException
- if an I/O error occurs.ConnectionA.close()
public void write(byte[] data) throws ConnectionException
Connection
data.length
bytes from the specified byte array to this output stream. The connection must be
open before this method is called. If write
is called when a connection is closed, a
ConnectionException
is thrown.write
in interface Connection
write
in class ConnectionA
data
- the data.ConnectionException
- if an I/O error occurs.ConnectionA.write(byte[])
public void write(byte[] data, int offset, int length) throws ConnectionException
Connection
length
bytes from data
starting at offset
. The connection must be
open before this method is called. If write
is called when a connection is closed, a
ConnectionException
is thrown.write
in interface Connection
write
in class ConnectionA
data
- the data.offset
- the start offset in the data
.length
- number of bytes to write.ConnectionException
- if an I/O error occurs.ConnectionA.write(byte[], int, int)
public int readChar() throws ConnectionException
Connection
int singleCharacter = printerConnection.readChar();
readChar
in interface Connection
readChar
in class ConnectionA
ConnectionException
- if an I/O error occurs.Connection.readChar()
public byte[] read(int maxBytesToRead) throws ConnectionException
read
in interface com.zebra.sdk.comm.internal.ConnectionI
read
in class ConnectionA
maxBytesToRead
- number of bytes to readConnectionException
- if an I/O error occurs.public int bytesAvailable() throws ConnectionException
bytesAvailable
in interface Connection
bytesAvailable
in class ConnectionA
ConnectionException
- if an I/O error occurs.Connection.bytesAvailable()
public String getSimpleConnectionName()
Connection
getSimpleConnectionName
in interface Connection
Connection.getSimpleConnectionName()
public String getSerialNumber()
public String toString()
toString
in interface Connection
toString
in class Object
public ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException
Connection
ConnectionReestablisher
which allows for easy recreation of a connection which may have
been closed.
getConnectionReestablisher
in interface Connection
getConnectionReestablisher
in class ConnectionA
thresholdTime
- how long the Connection reestablisher will wait before attempting to reconnection to the
printerConnectionException
- if the ConnectionReestablisher could not be created.ConnectionA.getConnectionReestablisher(long thresholdTime)
public void setMaxTimeoutForRead(int maxTimeoutForRead)
Connection
setMaxTimeoutForRead
in interface Connection
setMaxTimeoutForRead
in class ConnectionA
maxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received.ConnectionA.setMaxTimeoutForRead(int)
public int getMaxTimeoutForRead()
Connection
getMaxTimeoutForRead
in interface Connection
getMaxTimeoutForRead
in class ConnectionA
ConnectionA.getMaxTimeoutForRead()
public String getManufacturer()
ConnectionA
getManufacturer
in interface com.zebra.sdk.comm.internal.ConnectionI
getManufacturer
in class ConnectionA
ConnectionI.getManufacturer()
© 2017 ZIH Corp. All Rights Reserved.