public class RobotUsbDeviceTty extends RobotUsbDeviceImplBase implements RobotUsbDevice
RobotUsbDeviceTty
is an implementation of RobotUsbDevice
that
sits on top of a serial file handle (such as /dev/tty) and presents the persona of
a (fake) USB device.RobotUsbDevice.Channel, RobotUsbDevice.FirmwareVersion, RobotUsbDevice.USBIdentifiers
Modifier and Type | Field and Description |
---|---|
protected int |
baudRate |
static boolean |
DEBUG |
protected boolean |
debugRetainBuffers |
protected java.io.File |
file |
protected int |
msDefaultTimeout |
protected java.lang.String |
productName |
protected java.util.Queue<java.lang.Byte> |
readAhead |
protected java.lang.Object |
readLock |
protected SerialPort |
serialPort |
protected java.lang.Object |
startStopLock |
static java.lang.String |
TAG |
protected RobotUsbDevice.USBIdentifiers |
usbIdentifiers |
protected java.lang.Object |
writeLock |
deviceType, deviceTypes, extantDevices, firmwareVersion, serialNumber
Constructor and Description |
---|
RobotUsbDeviceTty(SerialPort serialPort,
SerialNumber serialNumber,
java.io.File file) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the device
|
boolean |
getDebugRetainBuffers() |
int |
getMsDefaultTimeout() |
java.lang.String |
getProductName() |
java.lang.String |
getTag() |
RobotUsbDevice.USBIdentifiers |
getUsbIdentifiers()
Returns the USB-level vendor and product id of this device.
|
boolean |
isAttached()
Returns whether or not this USB device is known to be physically attached
|
boolean |
isOpen()
Returns whether the device is open or not
|
void |
logRetainedBuffers(long nsOrigin,
long nsTimerExpire,
java.lang.String tag,
java.lang.String format,
java.lang.Object... args) |
boolean |
mightBeAtUsbPacketStart()
Answers as to whether we're it's probably the case we're at the start of a Usb
packet.
|
int |
read(byte[] data,
int ibFirst,
int cbToRead,
long msTimeout,
TimeWindow timeWindow)
Reads a requested number of bytes from the device.
|
void |
requestReadInterrupt(boolean interruptRequested)
Interrupts any reads that are currently pending inside the device, possibly waiting
on a perhaps lengthy timeout.
|
void |
resetAndFlushBuffers()
Resets the remote USB device comm-layer as best we can.
|
void |
setBaudRate(int baudRate)
Sets the rate of data transmission used to communicate with the device.
|
void |
setBreak(boolean enable)
Sets or unsets a break state on the communication line
|
void |
setDataCharacteristics(byte dataBits,
byte stopBits,
byte parity)
Set the Data Characteristics
|
void |
setDebugRetainBuffers(boolean retain) |
void |
setLatencyTimer(int latencyTimer)
Set the latency timer
|
void |
setMsDefaultTimeout(int msDefaultTimeout) |
void |
setProductName(java.lang.String productName) |
void |
setUsbIdentifiers(RobotUsbDevice.USBIdentifiers usbIdentifiers) |
void |
skipToLikelyUsbPacketStart()
Skips to the beginning of a USB packet, if not already there.
|
void |
write(byte[] data)
Write to device
|
dumpBytesReceived, dumpBytesSent, getDeviceType, getDeviceType, getExtantDevices, getFirmwareVersion, getSerialNumber, isOpen, removeFromExtantDevices, setDeviceType, setFirmwareVersion
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDeviceType, getFirmwareVersion, getSerialNumber, setDeviceType, setFirmwareVersion
public static final java.lang.String TAG
public static boolean DEBUG
protected final java.io.File file
protected SerialPort serialPort
protected int baudRate
protected int msDefaultTimeout
protected RobotUsbDevice.USBIdentifiers usbIdentifiers
protected final java.lang.Object startStopLock
protected final java.lang.Object readLock
protected final java.lang.Object writeLock
protected java.util.Queue<java.lang.Byte> readAhead
protected boolean debugRetainBuffers
protected java.lang.String productName
public RobotUsbDeviceTty(SerialPort serialPort, SerialNumber serialNumber, java.io.File file)
public java.lang.String getTag()
getTag
in class RobotUsbDeviceImplBase
public void close()
RobotUsbDevice
close
in interface RobotUsbDevice
public boolean isOpen()
RobotUsbDevice
isOpen
in interface RobotUsbDevice
public boolean isAttached()
RobotUsbDevice
isAttached
in interface RobotUsbDevice
public void resetAndFlushBuffers()
RobotUsbDevice
resetAndFlushBuffers
in interface RobotUsbDevice
public void write(byte[] data) throws RobotUsbException
RobotUsbDevice
write
in interface RobotUsbDevice
data
- byte arrayRobotUsbException
public int read(byte[] data, int ibFirst, int cbToRead, long msTimeout, TimeWindow timeWindow) throws RobotUsbException, java.lang.InterruptedException
RobotUsbDevice
read
in interface RobotUsbDevice
data
- byte array into which to read the dataibFirst
- first index in data at which to read the datacbToRead
- number of bytes to readmsTimeout
- amount of time to wait, in ms, for data to become available to readtimeWindow
- optional place to return information as to when the data was readRobotUsbException
java.lang.InterruptedException
public boolean mightBeAtUsbPacketStart()
RobotUsbDevice
mightBeAtUsbPacketStart
in interface RobotUsbDevice
public void skipToLikelyUsbPacketStart()
RobotUsbDevice
skipToLikelyUsbPacketStart
in interface RobotUsbDevice
public void requestReadInterrupt(boolean interruptRequested)
RobotUsbDevice
requestReadInterrupt
in interface RobotUsbDevice
public void setDebugRetainBuffers(boolean retain)
setDebugRetainBuffers
in interface RobotUsbDevice
public boolean getDebugRetainBuffers()
getDebugRetainBuffers
in interface RobotUsbDevice
public void logRetainedBuffers(long nsOrigin, long nsTimerExpire, java.lang.String tag, java.lang.String format, java.lang.Object... args)
logRetainedBuffers
in interface RobotUsbDevice
public void setBaudRate(int baudRate) throws RobotUsbException
RobotUsbDevice
setBaudRate
in interface RobotUsbDevice
baudRate
- baud rateRobotUsbException
public void setDataCharacteristics(byte dataBits, byte stopBits, byte parity) throws RobotUsbException
RobotUsbDevice
setDataCharacteristics
in interface RobotUsbDevice
dataBits
- data bitsstopBits
- stop bitsparity
- parityRobotUsbException
public void setLatencyTimer(int latencyTimer) throws RobotUsbException
RobotUsbDevice
setLatencyTimer
in interface RobotUsbDevice
latencyTimer
- latency timerRobotUsbException
public void setBreak(boolean enable) throws RobotUsbException
RobotUsbDevice
setBreak
in interface RobotUsbDevice
enable
- whether or not to set a break stateRobotUsbException
public void setMsDefaultTimeout(int msDefaultTimeout)
public int getMsDefaultTimeout()
public RobotUsbDevice.USBIdentifiers getUsbIdentifiers()
RobotUsbDevice
getUsbIdentifiers
in interface RobotUsbDevice
public void setUsbIdentifiers(RobotUsbDevice.USBIdentifiers usbIdentifiers)
public void setProductName(java.lang.String productName)
public java.lang.String getProductName()
getProductName
in interface RobotUsbDevice