From 111707c92fb5b782729609155b1794e37ecb705a Mon Sep 17 00:00:00 2001 From: mike wakerly Date: Wed, 28 Nov 2012 10:24:47 -0800 Subject: [PATCH] Driver interface: add methods for CD, CTS, DSR, DTR, RI, and RTS. --- .../usbserial/driver/CdcAcmSerialDriver.java | 48 +++++++++++-- .../usbserial/driver/FtdiSerialDriver.java | 50 +++++++++++-- .../usbserial/driver/UsbSerialDriver.java | 70 ++++++++++++++++++- 3 files changed, 157 insertions(+), 11 deletions(-) diff --git a/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java b/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java index db46ba2..6dabac1 100644 --- a/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java +++ b/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java @@ -1,9 +1,5 @@ package com.hoho.android.usbserial.driver; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; - import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDeviceConnection; @@ -11,6 +7,10 @@ import android.hardware.usb.UsbEndpoint; import android.hardware.usb.UsbInterface; import android.util.Log; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + /** * USB CDC/ACM serial driver implementation. * @@ -151,6 +151,46 @@ public class CdcAcmSerialDriver extends UsbSerialDriver { return baudRate; } + @Override + public boolean getCD() throws IOException { + return false; + } + + @Override + public boolean getCTS() throws IOException { + return false; + } + + @Override + public boolean getDSR() throws IOException { + return false; + } + + @Override + public boolean getDTR() throws IOException { + return false; + } + + @Override + public boolean setDTR(boolean value) throws IOException { + return false; + } + + @Override + public boolean getRI() throws IOException { + return false; + } + + @Override + public boolean getRTS() throws IOException { + return false; + } + + @Override + public boolean setRTS(boolean value) throws IOException { + return false; + } + public static Map getSupportedDevices() { final Map supportedDevices = new LinkedHashMap(); supportedDevices.put(Integer.valueOf(UsbId.VENDOR_ARDUINO), diff --git a/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/FtdiSerialDriver.java b/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/FtdiSerialDriver.java index 80a1557..da22fd8 100644 --- a/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/FtdiSerialDriver.java +++ b/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/FtdiSerialDriver.java @@ -20,11 +20,6 @@ package com.hoho.android.usbserial.driver; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.LinkedHashMap; -import java.util.Map; - import android.hardware.usb.UsbConstants; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDeviceConnection; @@ -34,6 +29,11 @@ import android.util.Log; import com.hoho.android.usbserial.util.HexDump; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.LinkedHashMap; +import java.util.Map; + /** * A {@link UsbSerialDriver} implementation for a variety of FTDI devices *

@@ -409,6 +409,46 @@ public class FtdiSerialDriver extends UsbSerialDriver { }; } + @Override + public boolean getCD() throws IOException { + return false; + } + + @Override + public boolean getCTS() throws IOException { + return false; + } + + @Override + public boolean getDSR() throws IOException { + return false; + } + + @Override + public boolean getDTR() throws IOException { + return false; + } + + @Override + public boolean setDTR(boolean value) throws IOException { + return false; + } + + @Override + public boolean getRI() throws IOException { + return false; + } + + @Override + public boolean getRTS() throws IOException { + return false; + } + + @Override + public boolean setRTS(boolean value) throws IOException { + return false; + } + public static Map getSupportedDevices() { final Map supportedDevices = new LinkedHashMap(); supportedDevices.put(Integer.valueOf(UsbId.VENDOR_FTDI), diff --git a/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/UsbSerialDriver.java b/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/UsbSerialDriver.java index e7f8d01..41970ce 100644 --- a/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/UsbSerialDriver.java +++ b/UsbSerialLibrary/src/com/hoho/android/usbserial/driver/UsbSerialDriver.java @@ -20,11 +20,11 @@ package com.hoho.android.usbserial.driver; -import java.io.IOException; - import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbDeviceConnection; +import java.io.IOException; + /** * Driver interface for a supported USB serial device. * @@ -99,6 +99,72 @@ public abstract class UsbSerialDriver { */ public abstract int setBaudRate(final int baudRate) throws IOException; + /** + * Gets the CD (Carrier Detect) bit from the underlying UART. + * + * @return the current state, or {@code false} if not supported. + * @throws IOException if an error occurred during reading + */ + public abstract boolean getCD() throws IOException; + + /** + * Gets the CTS (Clear To Send) bit from the underlying UART. + * + * @return the current state, or {@code false} if not supported. + * @throws IOException if an error occurred during reading + */ + public abstract boolean getCTS() throws IOException; + + /** + * Gets the DSR (Data Set Ready) bit from the underlying UART. + * + * @return the current state, or {@code false} if not supported. + * @throws IOException if an error occurred during reading + */ + public abstract boolean getDSR() throws IOException; + + /** + * Gets the DTR (Data Terminal Ready) bit from the underlying UART. + * + * @return the current state, or {@code false} if not supported. + * @throws IOException if an error occurred during reading + */ + public abstract boolean getDTR() throws IOException; + + /** + * Sets the DTR (Data Terminal Ready) bit on the underlying UART, if + * supported. + * + * @param value the value to set + * @throws IOException if an error occurred during writing + */ + public abstract boolean setDTR(boolean value) throws IOException; + + /** + * Gets the RI (Ring Indicator) bit from the underlying UART. + * + * @return the current state, or {@code false} if not supported. + * @throws IOException if an error occurred during reading + */ + public abstract boolean getRI() throws IOException; + + /** + * Gets the RTS (Request To Send) bit from the underlying UART. + * + * @return the current state, or {@code false} if not supported. + * @throws IOException if an error occurred during reading + */ + public abstract boolean getRTS() throws IOException; + + /** + * Sets the RTS (Request To Send) bit on the underlying UART, if + * supported. + * + * @param value thje value to set + * @throws IOException if an error occurred during writing + */ + public abstract boolean setRTS(boolean value) throws IOException; + /** * Returns the currently-bound USB device. *