FileDocCategorySizeDatePackage
SerialPort.javaAPI DocAndroid 5.1 API4115Thu Mar 12 22:22:10 GMT 2015android.hardware

SerialPort

public class SerialPort extends Object
hide

Fields Summary
private static final String
TAG
private int
mNativeContext
private final String
mName
private android.os.ParcelFileDescriptor
mFileDescriptor
Constructors Summary
public SerialPort(String name)
SerialPort should only be instantiated by SerialManager

hide


                 
       
        mName = name;
    
Methods Summary
public voidclose()
Closes the serial port

        if (mFileDescriptor != null) {
            mFileDescriptor.close();
            mFileDescriptor = null;
        }
        native_close();
    
public java.lang.StringgetName()
Returns the name of the serial port

return
the serial port's name

        return mName;
    
private native voidnative_close()

private native voidnative_open(java.io.FileDescriptor pfd, int speed)

private native intnative_read_array(byte[] buffer, int length)

private native intnative_read_direct(java.nio.ByteBuffer buffer, int length)

private native voidnative_send_break()

private native voidnative_write_array(byte[] buffer, int length)

private native voidnative_write_direct(java.nio.ByteBuffer buffer, int length)

public voidopen(android.os.ParcelFileDescriptor pfd, int speed)
SerialPort should only be instantiated by SerialManager Speed must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000

hide

        native_open(pfd.getFileDescriptor(), speed);
        mFileDescriptor = pfd;
    
public intread(java.nio.ByteBuffer buffer)
Reads data into the provided buffer. Note that the value returned by {@link java.nio.Buffer#position()} on this buffer is unchanged after a call to this method.

param
buffer to read into
return
number of bytes read

        if (buffer.isDirect()) {
            return native_read_direct(buffer, buffer.remaining());
        } else if (buffer.hasArray()) {
            return native_read_array(buffer.array(), buffer.remaining());
        } else {
            throw new IllegalArgumentException("buffer is not direct and has no array");
        }
    
public voidsendBreak()
Sends a stream of zero valued bits for 0.25 to 0.5 seconds

        native_send_break();
    
public voidwrite(java.nio.ByteBuffer buffer, int length)
Writes data from provided buffer. Note that the value returned by {@link java.nio.Buffer#position()} on this buffer is unchanged after a call to this method.

param
buffer to write
param
length number of bytes to write

        if (buffer.isDirect()) {
            native_write_direct(buffer, length);
        } else if (buffer.hasArray()) {
            native_write_array(buffer.array(), length);
        } else {
            throw new IllegalArgumentException("buffer is not direct and has no array");
        }