Subversion Repositories Programming Utils

Rev

Rev 81 | Rev 96 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.rm5248.serial;

import java.io.IOException;

/**
 * A SerialPort represents a serial port on the system.
 *
 * All SerialPorts must implement this class.
 *
 * See the documentation for the subclasses on how to create
 * a specific instance of a SerialPort.
 *
 * @author rm5248
 *
 */

public interface SerialPort {
       
        /**
         * Represents the BaudRate that the SerialPort uses.
         */

        public enum BaudRate{
                /** Not available in Windows */
                B0,
                /** Not available in Windows */
                B50,
                /** Not available in Windows */
                B75,
                B110,
                /** Not available in Windows */
                B134,
                /** Not available in Windows */
                B150,
                B200,
                B300,
                B600,
                B1200,
                /** Not available in Windows */
                B1800,
                B2400,
                B4800,
                B9600,
                B38400,
                B115200
        }

        /**
         * Represents the number of bits that the serial port uses.  
         * Typically, this is 8-bit characters.
         */

        public enum DataBits{
                DATABITS_5,
                DATABITS_6,
                DATABITS_7,
                DATABITS_8
        }

        /**
         * The number of stop bits for data.  Typically this is 1.
         */

        public enum StopBits{
                STOPBITS_1,
                STOPBITS_2
        }

        /**
         * The parity bit for the data.  Typically None.
         */

        public enum Parity{
                NONE,
                EVEN,
                ODD
        }

        /**
         * The Flow control scheme for the data, typically None.
         */

        public enum FlowControl{
                NONE,
                HARDWARE,
                SOFTWARE
        }

        /**
         * Set the Baud Rate for this port.
         *
         * @param rate
         */

        public abstract void setBaudRate(BaudRate rate);

        /**
         * Close the serial port, and all input streams
         */

        public abstract void close();

        /**
         * See if the port has been closed already.
         * @return
         */

        public abstract boolean isClosed();

        /**
         * Set the stop bits of the serial port, after the port has been opened.
         *
         * @param stop
         */

        public abstract void setStopBits(StopBits stop);

        /**
         * Set the data bits size, after the port has been opened.
         *
         * @param data
         */

        public abstract void setDataSize(DataBits data);

        /**
         * Set the parity of the serial port, after the port has been opened.
         *
         * @param parity
         */

        public abstract void setParity(Parity parity);

        /**
         * Get the serial line state for the specified serial port.
         *
         * @return
         */

        public abstract SerialLineState getSerialLineState() throws IOException;

        /**
         * Set the serial line state to the parameters given.
         *
         * @param state
         */

        public abstract void setSerialLineState(SerialLineState state);

        /**
         * Get the baud rate of the serial port.
         *
         * @return
         */

        public abstract IOSerialPort.BaudRate getBaudRate();

        /**
         * Get the number of data bits.
         *
         * @return
         */

        public abstract IOSerialPort.DataBits getDataBits();

        /**
         * Get the number of stop bits.
         *
         * @return
         */

        public abstract IOSerialPort.StopBits getStopBits();

        /**
         * Get the parity of the serial port.
         *
         * @return
         */

        public abstract IOSerialPort.Parity getParity();

        /**
         * Get the flow control for the serial port.
         *
         * @return
         */

        public abstract IOSerialPort.FlowControl getFlowControl();

        /**
         * Set the flow control for the serial port
         *
         * @param flow
         */

        public abstract void setFlowControl(FlowControl flow);

        /**
         * Set the listener which will get events when there is activity on the serial port.
         * Note that this activity does NOT include receive and transmit events - this is
         * changes on the lines of the serial port, such as RI, DSR, and DTR.
         *
         * If listen is null, will remove the listener.
         *
         * @param listen The listener which gets events
         */

        public abstract void setSerialChangeListener(SerialChangeListener listen);

        /**
         * Get the name of the serial port that this object represents.
         * @return
         */

        public abstract String getPortName();

}