001package jmri.jmrix;
002
003import java.io.InputStream;
004import java.io.OutputStream;
005
006/**
007 * Serial port
008 *
009 * @author Daniel Bergqvist (C) 2024
010 */
011public interface SerialPort {
012
013    public static final int LISTENING_EVENT_DATA_AVAILABLE = com.fazecast.jSerialComm.SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
014    public static final int ONE_STOP_BIT = com.fazecast.jSerialComm.SerialPort.ONE_STOP_BIT;
015    public static final int NO_PARITY = com.fazecast.jSerialComm.SerialPort.NO_PARITY;
016
017    /**
018     * Enumerate the possible parity choices
019     */
020    public enum Parity {
021        NONE(com.fazecast.jSerialComm.SerialPort.NO_PARITY),
022        EVEN(com.fazecast.jSerialComm.SerialPort.EVEN_PARITY),
023        ODD(com.fazecast.jSerialComm.SerialPort.ODD_PARITY);
024
025        private final int value;
026
027        Parity(int value) {
028            this.value = value;
029        }
030
031        public int getValue() {
032            return value;
033        }
034
035        public static Parity getParity(int parity) {
036            for (Parity p : Parity.values()) {
037                if (p.value == parity) {
038                    return p;
039                }
040            }
041            throw new IllegalArgumentException("Unknown parity");
042        }
043    }
044
045    void addDataListener(SerialPortDataListener listener);
046
047    InputStream getInputStream();
048
049    OutputStream getOutputStream();
050
051    void setRTS();
052
053    void clearRTS();
054
055    void setBaudRate(int baudrate);
056
057    int getBaudRate();
058
059    void setNumDataBits(int bits);
060
061    int getNumDataBits();
062
063    void setNumStopBits(int bits);
064
065    int getNumStopBits();
066
067    void setParity(Parity parity);
068
069    Parity getParity();
070
071    void setDTR();
072
073    void clearDTR();
074
075    boolean getDTR();
076
077    boolean getRTS();
078
079    boolean getDSR();
080
081    boolean getCTS();
082
083    boolean getDCD();
084
085    boolean getRI();
086
087    /**
088     * Configure the flow control settings. Keep this in synch with the
089     * FlowControl enum.
090     *
091     * @param flow  set which kind of flow control to use
092     */
093    void setFlowControl(AbstractSerialPortController.FlowControl flow);
094
095    void setBreak();
096
097    void clearBreak();
098
099    int getFlowControlSettings();
100
101    boolean setComPortTimeouts(int newTimeoutMode, int newReadTimeout, int newWriteTimeout);
102
103    void closePort();
104
105    String getDescriptivePortName();
106
107    @Override
108    String toString();
109
110}