Class UsbLink
A USB device's bulk endpoints: a USB receipt printer, or a USB CDC
device -- many payment terminals -- whose serial line settings do not
matter. Needs Usb.isSupported() (Android) and permission from the user
(Usb.requestPermission(UsbDevice)) before open().
The link sends no control requests, so a USB serial chip that must be
told its baud rate (FTDI, CP210x, CH340) does not work through it; plug
those into a desktop, where the operating system drives the chip and
SerialLink opens it.
A read waits in steps of the platform's transfer timeout, five seconds on Android, so a short timeout may wait longer.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disconnects.booleanisOpen()WhetherByteLink.open()succeeded andByteLink.close()has not been called.voidopen()Connects.intread(byte[] buffer, int offset, int length, int timeout) A printer with no IN endpoint (inEndpointof -1) never answers, and a read reports nothing arrived.voidwrite(byte[] data, int offset, int length) Writes bytes, returning once they are handed to the device.
-
Constructor Details
-
UsbLink
Parameters
-
device: the device -
inEndpoint: the address of its bulk IN endpoint (bit 7 set, as0x81) -
outEndpoint: the address of its bulk OUT endpoint
-
-
-
Method Details
-
open
Description copied from class:ByteLinkConnects. Does nothing when already open.
Throws
IOException: when the device cannot be reached
- Specified by:
openin classByteLink- Throws:
IOException
-
isOpen
public boolean isOpen()Description copied from class:ByteLink -
write
Description copied from class:ByteLinkWrites bytes, returning once they are handed to the device.
Parameters
-
data: the buffer -
offset: where to start in it -
length: how many bytes
Throws
IOException: when the link is closed or broken
- Specified by:
writein classByteLink- Throws:
IOException
-
-
read
A printer with no IN endpoint (inEndpointof -1) never answers, and a read reports nothing arrived.- Specified by:
readin classByteLink- Throws:
IOException
-
close
-