Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended serial port implementation #2050

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}