Package com.zebra.sdk.comm
Class UsbConnection
Object
com.zebra.sdk.comm.ConnectionA
com.zebra.sdk.comm.UsbConnection
- All Implemented Interfaces:
Connection,ConnectionWithWriteLogging,com.zebra.sdk.comm.internal.ConnectionI
Establishes a direct connection to an attached Zebra USB printer without requiring the presence of a USB driver
-
Constructor Summary
ConstructorsConstructorDescriptionUsbConnection(String symbolicName) Initializes a new instance of theUsbConnectionclass.UsbConnection(String symbolicName, int maxTimeoutForRead, int timeToWaitForMoreData) Initializes a new instance of theUsbConnectionclass. -
Method Summary
Modifier and TypeMethodDescriptionintReturns number of bytes currently read from printer.voidclose()Closes this connection and releases any system resources associated with the connection.getConnectionReestablisher(long thresholdTime) Returns aConnectionReestablisherwhich allows for easy recreation of a connection which may have been closed.Returns the printer's manufacturer.intReturns the maximum time, in milliseconds, to wait for any data to be received.Return a human-readable description of the connection.voidopen()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 readsintreadChar()Reads the next byte of data from the connection, similar to a Java InputStream.voidsetMaxTimeoutForRead(int maxTimeoutForRead) Set the maximum time, in milliseconds, to wait for any data to be receivedtoString()Returns the Connection Builder name of the USB device.voidwrite(byte[] data) Writesdata.lengthbytes from the specified byte array to this output stream.voidwrite(byte[] data, int offset, int length) Writeslengthbytes fromdatastarting atoffset.Methods inherited from class com.zebra.sdk.comm.ConnectionA
addWriteLogStream, getMaxDataToWrite, getTimeToWaitForMoreData, isConnected, read, read, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setMaxDataToWrite, setReadTimeout, setTimeToWaitForMoreData, waitForData, writeMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.zebra.sdk.comm.Connection
getTimeToWaitForMoreData, isConnected, read, read, sendAndWaitForResponse, sendAndWaitForResponse, sendAndWaitForValidResponse, sendAndWaitForValidResponse, setTimeToWaitForMoreData, waitForData, writeMethods inherited from interface com.zebra.sdk.comm.internal.ConnectionI
getMaxDataToWrite, read, setMaxDataToWrite, setReadTimeout
-
Constructor Details
-
UsbConnection
Initializes a new instance of theUsbConnectionclass. This constructor will attempt a connection to the printer specified in the symbolic name.- Parameters:
symbolicName- the USB symbolic name for the device returned by the UsbDiscoverer.getZebraUsbPrinters() member function.- Throws:
ConnectionException- if the system is not running the Windows operating system or if the device cannot be found.
-
UsbConnection
public UsbConnection(String symbolicName, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException Initializes a new instance of theUsbConnectionclass. This constructor will attempt a connection to the printer specified in the symbolic name.- Parameters:
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 printer- Throws:
ConnectionException- if the system is not running the Windows operating system or if the device cannot be found.
-
-
Method Details
-
open
Description copied from interface:ConnectionOpens the connection to a device. If theopenmethod 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 callConnection.close()to free up system resources.- Specified by:
openin interfaceConnection- Overrides:
openin classConnectionA- Throws:
ConnectionException- if the connection cannot be established.- See Also:
-
close
Description copied from interface:ConnectionCloses this connection and releases any system resources associated with the connection. If the connection is already closed then invoking this method has no effect.- Specified by:
closein interfaceConnection- Overrides:
closein classConnectionA- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
write
Description copied from interface:ConnectionWritesdata.lengthbytes from the specified byte array to this output stream. The connection must be open before this method is called. Ifwriteis called when a connection is closed, aConnectionExceptionis thrown.- Specified by:
writein interfaceConnection- Overrides:
writein classConnectionA- Parameters:
data- the data.- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
write
Description copied from interface:ConnectionWriteslengthbytes fromdatastarting atoffset. The connection must be open before this method is called. Ifwriteis called when a connection is closed, aConnectionExceptionis thrown.- Specified by:
writein interfaceConnection- Overrides:
writein classConnectionA- Parameters:
data- the data.offset- the start offset in thedata.length- number of bytes to write.- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
readChar
Description copied from interface:ConnectionReads the next byte of data from the connection, similar to a Java InputStream. The value byte is returned as an int in the range of 0 to 255. If no byte is available on the connection the value -1 is returned.int singleCharacter = printerConnection.readChar();
- Specified by:
readCharin interfaceConnection- Overrides:
readCharin classConnectionA- Returns:
- the next byte from the connection
- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
read
Reads up to maxBytesToRead into byte array
Performing reads using DriverPrinterConnection and UsbConnection concurrently could cause indeterminate reads- Specified by:
readin interfacecom.zebra.sdk.comm.internal.ConnectionI- Overrides:
readin classConnectionA- Parameters:
maxBytesToRead- number of bytes to read- Returns:
- the bytes read from the connection.
- Throws:
ConnectionException- if an I/O error occurs.
-
bytesAvailable
Returns number of bytes currently read from printer.- Specified by:
bytesAvailablein interfaceConnection- Overrides:
bytesAvailablein classConnectionA- Returns:
- number of bytes currently read from printer.
- Throws:
ConnectionException- if an I/O error occurs.- See Also:
-
getSimpleConnectionName
Description copied from interface:ConnectionReturn a human-readable description of the connection.- Specified by:
getSimpleConnectionNamein interfaceConnection- Returns:
- a human-readable description of the connection.
- See Also:
-
getSerialNumber
- Returns:
- serialNumber - The printer's serial number.
-
toString
Returns the Connection Builder name of the USB device.- Specified by:
toStringin interfaceConnection- Overrides:
toStringin classObject- Returns:
- the connection description string.
-
getConnectionReestablisher
public ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException Description copied from interface:ConnectionReturns aConnectionReestablisherwhich allows for easy recreation of a connection which may have been closed.- This call should be made while there is still an active connection to the printer (prior to issuing a command which will make the printer non-responsive).
- Specified by:
getConnectionReestablisherin interfaceConnection- Overrides:
getConnectionReestablisherin classConnectionA- Parameters:
thresholdTime- how long the Connection reestablisher will wait before attempting to reconnection to the printer- Returns:
- ConnectionReestablisher
- Throws:
ConnectionException- if the ConnectionReestablisher could not be created.- See Also:
-
setMaxTimeoutForRead
public void setMaxTimeoutForRead(int maxTimeoutForRead) Description copied from interface:ConnectionSet the maximum time, in milliseconds, to wait for any data to be received- Specified by:
setMaxTimeoutForReadin interfaceConnection- Overrides:
setMaxTimeoutForReadin classConnectionA- Parameters:
maxTimeoutForRead- the maximum time, in milliseconds, to wait for any data to be received.- See Also:
-
getMaxTimeoutForRead
public int getMaxTimeoutForRead()Description copied from interface:ConnectionReturns the maximum time, in milliseconds, to wait for any data to be received.- Specified by:
getMaxTimeoutForReadin interfaceConnection- Overrides:
getMaxTimeoutForReadin classConnectionA- Returns:
- the maximum time, in milliseconds, to wait for any data to be received.
- See Also:
-
getManufacturer
Description copied from class:ConnectionAReturns the printer's manufacturer.- Specified by:
getManufacturerin interfacecom.zebra.sdk.comm.internal.ConnectionI- Overrides:
getManufacturerin classConnectionA- Returns:
- The printer's manufacturer.
- See Also:
-