kopia lustrzana https://github.com/felHR85/UsbSerial
SerialBuffer completed and Cp210x class to handle this concrete device
rodzic
c2f044de5d
commit
0ea9e59eee
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
|
@ -0,0 +1,70 @@
|
|||
package com.felhr.usbserial;
|
||||
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
|
||||
public class CP2102SerialDevice extends UsbSerialDevice
|
||||
{
|
||||
|
||||
public CP2102SerialDevice(UsbDevice device, UsbDeviceConnection connection)
|
||||
{
|
||||
super(device, connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] buffer)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// This methods is going to need callback
|
||||
@Override
|
||||
public int read()
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaudRate(int baudRate)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataBits(int dataBits)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStopBits(int stopBits)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParity(int parity)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlowControl(int flowControl)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
|
@ -54,13 +54,26 @@ public class SerialBuffer
|
|||
|
||||
public void putReadBuffer(ByteBuffer data)
|
||||
{
|
||||
// TO-DO
|
||||
synchronized(mReadLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
readBuffer.put(data);
|
||||
}catch(BufferOverflowException e)
|
||||
{
|
||||
// TO-DO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getReadBuffer()
|
||||
{
|
||||
// TO-DO
|
||||
return null;
|
||||
synchronized(mReadLock)
|
||||
{
|
||||
byte[] data = readBuffer.array();
|
||||
readBuffer.clear();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,11 +5,12 @@ import android.hardware.usb.UsbDeviceConnection;
|
|||
|
||||
public abstract class UsbSerialDevice implements UsbSerialInterface
|
||||
{
|
||||
private UsbDevice device;
|
||||
private UsbDeviceConnection connection;
|
||||
protected final UsbDevice device;
|
||||
protected final UsbDeviceConnection connection;
|
||||
|
||||
private Object readBufferLock;
|
||||
private Object writeBufferLock;
|
||||
protected SerialBuffer serialBuffer;
|
||||
protected final Object readBufferLock;
|
||||
protected final Object writeBufferLock;
|
||||
|
||||
public UsbSerialDevice(UsbDevice device, UsbDeviceConnection connection)
|
||||
{
|
||||
|
@ -17,7 +18,29 @@ public abstract class UsbSerialDevice implements UsbSerialInterface
|
|||
this.connection = connection;
|
||||
this.readBufferLock = new Object();
|
||||
this.writeBufferLock = new Object();
|
||||
serialBuffer = new SerialBuffer(readBufferLock, writeBufferLock);
|
||||
}
|
||||
|
||||
|
||||
// Common Usb Serial Operations (I/O Asynchronous)
|
||||
@Override
|
||||
public abstract void open();
|
||||
@Override
|
||||
public abstract void write(byte[] buffer);
|
||||
@Override
|
||||
public abstract int read();
|
||||
@Override
|
||||
public abstract void close();
|
||||
|
||||
// Serial port configuration
|
||||
@Override
|
||||
public abstract void setBaudRate(int baudRate);
|
||||
@Override
|
||||
public abstract void setDataBits(int dataBits);
|
||||
@Override
|
||||
public abstract void setStopBits(int stopBits);
|
||||
@Override
|
||||
public abstract void setParity(int parity);
|
||||
@Override
|
||||
public abstract void setFlowControl(int flowControl);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ public interface UsbSerialInterface
|
|||
public static final int FLOW_CONTROL_XON_XOFF_IN = 3;
|
||||
public static final int FLOW_CONTROL_XON_XOFF_OUT = 4;
|
||||
|
||||
// Common Usb Serial Operations
|
||||
// Common Usb Serial Operations (I/O Asynchronous)
|
||||
public void open();
|
||||
public void write(byte[] buffer, int timeout);
|
||||
public int read(byte[] buffer, int timeout);
|
||||
public void write(byte[] buffer);
|
||||
public int read();
|
||||
public void close();
|
||||
|
||||
// Serial port configuration
|
||||
|
|
Ładowanie…
Reference in New Issue