Skip to content

Commit

Permalink
Extended serial port implementation (#2050)
Browse files Browse the repository at this point in the history
Signed-off-by: docbender <vita.tucek@seznam.cz>
  • Loading branch information
docbender authored Jan 6, 2021
1 parent 75f52ac commit 0026d89
Show file tree
Hide file tree
Showing 3 changed files with 309 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*
* @author Markus Rathgeb - Initial contribution
* @author Kai Kreuzer - added further methods
* @author Vita Tucek - added further methods
*/
@NonNullByDefault
public class SerialPortImpl implements SerialPort {
Expand Down Expand Up @@ -157,4 +158,94 @@ public void enableReceiveThreshold(int i) throws UnsupportedCommOperationExcepti
throw new UnsupportedCommOperationException(e);
}
}

@Override
public int getBaudRate() {
return sp.getBaudRate();
}

@Override
public int getDataBits() {
return sp.getDataBits();
}

@Override
public int getStopBits() {
return sp.getStopBits();
}

@Override
public int getParity() {
return sp.getParity();
}

@Override
public void notifyOnOutputEmpty(boolean enable) {
sp.notifyOnOutputEmpty(enable);
}

@Override
public void notifyOnCTS(boolean enable) {
sp.notifyOnCTS(enable);
}

@Override
public void notifyOnDSR(boolean enable) {
sp.notifyOnDSR(enable);
}

@Override
public void notifyOnRingIndicator(boolean enable) {
sp.notifyOnRingIndicator(enable);
}

@Override
public void notifyOnCarrierDetect(boolean enable) {
sp.notifyOnCarrierDetect(enable);
}

@Override
public int getFlowControlMode() {
return getFlowControlMode();
}

@Override
public boolean isRTS() {
return sp.isRTS();
}

@Override
public void setDTR(boolean state) {
sp.setDTR(state);
}

@Override
public boolean isDTR() {
return sp.isDTR();
}

@Override
public boolean isCTS() {
return sp.isCTS();
}

@Override
public boolean isDSR() {
return sp.isDSR();
}

@Override
public boolean isCD() {
return sp.isCD();
}

@Override
public boolean isRI() {
return sp.isRI();
}

@Override
public void sendBreak(int duration) {
sp.sendBreak(duration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Specific serial port implementation.
*
* @author Markus Rathgeb - Initial contribution
* @author Vita Tucek - added further methods
*/
@NonNullByDefault
public class RxTxSerialPort implements SerialPort {
Expand Down Expand Up @@ -157,4 +158,94 @@ public void enableReceiveThreshold(int i) throws UnsupportedCommOperationExcepti
throw new UnsupportedCommOperationException(e);
}
}

@Override
public int getBaudRate() {
return sp.getBaudRate();
}

@Override
public int getDataBits() {
return sp.getDataBits();
}

@Override
public int getStopBits() {
return sp.getStopBits();
}

@Override
public int getParity() {
return sp.getParity();
}

@Override
public void notifyOnOutputEmpty(boolean enable) {
sp.notifyOnOutputEmpty(enable);
}

@Override
public void notifyOnCTS(boolean enable) {
sp.notifyOnCTS(enable);
}

@Override
public void notifyOnDSR(boolean enable) {
sp.notifyOnDSR(enable);
}

@Override
public void notifyOnRingIndicator(boolean enable) {
sp.notifyOnRingIndicator(enable);
}

@Override
public void notifyOnCarrierDetect(boolean enable) {
sp.notifyOnCarrierDetect(enable);
}

@Override
public int getFlowControlMode() {
return getFlowControlMode();
}

@Override
public boolean isRTS() {
return sp.isRTS();
}

@Override
public void setDTR(boolean state) {
sp.setDTR(state);
}

@Override
public boolean isDTR() {
return sp.isDTR();
}

@Override
public boolean isCTS() {
return sp.isCTS();
}

@Override
public boolean isDSR() {
return sp.isDSR();
}

@Override
public boolean isCD() {
return sp.isCD();
}

@Override
public boolean isRI() {
return sp.isRI();
}

@Override
public void sendBreak(int duration) {
sp.sendBreak(duration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author Markus Rathgeb - Initial contribution
* @author Kai Kreuzer - added further methods
* @author Vita Tucek - added further methods
*/
@NonNullByDefault
public interface SerialPort extends Closeable {
Expand Down Expand Up @@ -66,6 +67,34 @@ public interface SerialPort extends Closeable {
void setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
throws UnsupportedCommOperationException;

/**
* Gets port baud rate.
*
* @return baud rate
*/
int getBaudRate();

/**
* Gets number of port data bits.
*
* @return data bits
*/
int getDataBits();

/**
* Gets number of port stop bits.
*
* @return stop bits count
*/
int getStopBits();

/**
* Gets port parity.
*
* @return parity
*/
int getParity();

/**
* Returns an input stream.
*
Expand Down Expand Up @@ -181,6 +210,41 @@ void setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
*/
void notifyOnParityError(boolean enable);

/**
* Enable / disable the notification on output buffer empty.
*
* @param enable true if the notification should be enabled
*/
void notifyOnOutputEmpty(boolean enable);

/**
* Enable / disable the notification on CTS.
*
* @param enable true if the notification should be enabled
*/
void notifyOnCTS(boolean enable);

/**
* Enable / disable the notification on DSR.
*
* @param enable true if the notification should be enabled
*/
void notifyOnDSR(boolean enable);

/**
* Enable / disable the notification on ring indicator.
*
* @param enable true if the notification should be enabled
*/
void notifyOnRingIndicator(boolean enable);

/**
* Enable / disable the notification on carrier detect.
*
* @param enable true if the notification should be enabled
*/
void notifyOnCarrierDetect(boolean enable);

/**
* Enables the receive timeout.
*
Expand All @@ -207,6 +271,13 @@ void setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
*/
void setFlowControlMode(int flowcontrolRtsctsOut) throws UnsupportedCommOperationException;

/**
* Gets the flow control mode value.
*
* @return flowcontrol value.
*/
int getFlowControlMode();

/**
* Enable receive threshold with the specified thresh parameter.
*
Expand All @@ -221,4 +292,60 @@ void setSerialPortParams(int baudrate, int dataBits, int stopBits, int parity)
* @param rts true rts is set, false if rts cleared
*/
void setRTS(boolean rts);

/**
* Check current state of RTS (Request To Send).
*
* @return true if RTS is set, otherwise false
*/
boolean isRTS();

/**
* Sets or clears the DTR (Request To Send) bit in the UART, if supported by the underlying implementation.
*
* @param state true DTR is set, false if DTR cleared
*/
void setDTR(boolean state);

/**
* Check current state of DTR (Data Terminal Ready).
*
* @return true if DTR is set, otherwise false
*/
boolean isDTR();

/**
* Check current state of CTS (Clear To Send).
*
* @return true if CTS is set, otherwise false
*/
boolean isCTS();

/**
* Check current state of DSR (Request To Send).
*
* @return true if DSR is set, otherwise false
*/
boolean isDSR();

/**
* Check current state of CD (Carrier Detect).
*
* @return true if CD is set, otherwise false
*/
boolean isCD();

/**
* Check current state of RI (Ring Indicator).
*
* @return true if RI is set, otherwise false
*/
boolean isRI();

/**
* Send break.
*
* @param duration Break duration parameter
*/
void sendBreak(int duration);
}

0 comments on commit 0026d89

Please sign in to comment.