Java ComPort for Android

Java library for serial communication for Android.
  • communication with devices connected to serial port
  • uses Linux Serial API
  • source code included in registered version
  • royalty free distribution in applications

API

public class ComPort {

	public class ComPortException extends Exception;

	public ComPort();

	public boolean isActive();
	public void setActive(boolean value) throws ComPortException, Exception;
	public void open() throws ComPortException;
	public void close() throws Exception;

	public String getDeviceName();
	public void setDeviceName(String value)

	public enum BaudRate {
		DEFAULT, _0, _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
	}
	public BaudRate getBaudRate();
	public void setBaudRate(BaudRate value) throws ComPortException;

	public enum DataBits {
		DEFAULT, _5, _6, _7, _8
	}
	public DataBits getDataBits();
	public void setDataBits(DataBits value) throws ComPortException;

	public enum StopBits {
		DEFAULT, _1, _2
	}
	public StopBits getStopBits();
	public void setStopBits(StopBits value) throws ComPortException;

	public enum Parity {
		DEFAULT, NONE, ODD, EVEN
	}
 	public Parity getParity();
	public void setParity(Parity value) throws ComPortException;

	public enum BlockMode {
		BLOCKING, NON_BLOCKING
	}
	public BlockMode getBlockMode();
	public void setBlockMode(BlockMode value) throws ComPortException;

	public byte getInputInterval();
	public void setInputInterval(byte value);

	public byte getInputRequired();
	public void setInputRequired(byte value) throws ComPortException;

	public int getInputTimeout();
	public void setInputTimeout(int value);

	public enum Option {
		CANONICAL, ECHO, ECHO_ERASE, ECHO_KILL, ECHO_NL, ENABLE_SINGALS, HANG_UP_ON_CLOSE,
		HARDWARE_FLOW_CONTROL, IGNORE_MODEM_LINES, NO_FLUSH_AFTER_INTERRUPT
	}
	public EnumSet<Option> getOptions();
	public void setOptions(EnumSet<Option> value) throws ComPortException;

	public enum InputOption {
		DISABLE_RECEIVER, ENABLE_PROCESSING, ENABLE_XON_XOFF, IGNORE_BREAK, IGNORE_CR,
		IGNORE_PARITY_ERROR, MARK_PARITY_ERROR, PARITY_CHECK, STRIP_OFF_EIGHTH_BIT,
		TRANSLATE_CR_TO_NL, TRANSLATE_NL_TO_CR
	}
	public EnumSet<InputOption> getInputOptions();
	public void setInputOptions(EnumSet<InputOption> value) throws ComPortException;

	public enum OutputOption {
		ANY_CHAR_IS_XON, ENABLE_PROCESSING, ENABLE_XON_XOFF, TRANSLATE_CR_TO_NL,
		TRANSLATE_NL_TO_CRLF, USE_FILL_CHARACTER
	}
	public EnumSet getOutputOptions();
	public void setOutputOptions(EnumSet value) throws ComPortException;

	public int getInputCount() throws ComPortException;

	public void write(byte[] data, int from, int count, boolean waitForCompletion) throws ComPortException;
	public void write(byte[] data, int from, int count) throws ComPortException;
	public void write(byte[] data) throws ComPortException;
	public void write(byte data) throws ComPortException;

	public void write(String data) throws ComPortException;
	public void write(String data, String charsetName) throws ComPortException, UnsupportedEncodingException;
	public void write(String data, Charset charset) throws ComPortException, UnsupportedEncodingException;

	public void writeln(String data) throws ComPortException;
	public void writeln(String data, String charsetName) throws ComPortException, UnsupportedEncodingException;
	public void writeln(String data, Charset charset) throws ComPortException, UnsupportedEncodingException;

	public void waitForWriteCompletion() throws ComPortException;

	public void read(byte[] data, int from, int count) throws ComPortException, InterruptedException;
	public byte[] read() throws ComPortException, InterruptedException;
	public String read(String charsetName) throws InterruptedException, ComPortException, UnsupportedEncodingException;
	public String read(Charset charset) throws InterruptedException, ComPortException;

	public void clearInput() throws ComPortException;
	public void clearOutput() throws ComPortException;
	public void clear() throws ComPortException;

	public void sendBreak() throws ComPortException;
	public void sendBreak(int duration) throws ComPortException;

	public void sendXOn() throws ComPortException;
	public void sendXOff() throws ComPortException;

	public void setXOn() throws ComPortException;
	public void setXOff() throws ComPortException;

	public void clearDTR() throws ComPortException;
	public void clearRTS() throws ComPortException;

	public void setDTR() throws ComPortException;
	public void setRTS() throws ComPortException;

	public enum ModemState {
		CTS, DSR, Ring, RLSD
	}

	public EnumSet getModemStatus() throws ComPortException;

	public static class Device {
		public String getName();
		public String getFileName();
	}

	public static List enumDevices() throws IOException;

	public static class Characters {
		public char getInterrupt();
		public void setInterrupt(char value) throws ComPortException;

		public char getQuit();
		public void setQuit(char value) throws ComPortException;

		public char getErase();
		public void setErase(char value) throws ComPortException;

		public char getKill();
		public void setKill(char value) throws ComPortException;

		public char getEof();
		public void setEof(char value) throws ComPortException;

		public char getStart();
		public void setStart(char value) throws ComPortException;

		public char getStop();
		public void setStop(char value) throws ComPortException;

		public char getSuspend();
		public void setSuspend(char value) throws ComPortException;

		public char getEol();
		public void setEol(char value) throws ComPortException;

		public char getReprint();
		public void setReprint(char value) throws ComPortException;

		public char getDiscard();
		public void setDiscard(char value) throws ComPortException;

		public char getWordErase();
		public void setWordErase(char value) throws ComPortException;

		public char getLiteralNext();
		public void setLiteralNext(char value) throws ComPortException;

		public char getEol2();
		public void setEol2(char value) throws ComPortException;
	}

	public Characters getCharacters();
}

Download and order