public class SerialParameters extends Object
| Constructor and Description |
|---|
SerialParameters()
Constructs a new SerialParameters instance with
default values.
|
SerialParameters(Properties props,
String prefix)
Constructs a new SerialParameters instance with
parameters obtained from a Properties instance.
|
SerialParameters(String portName,
int baudRate,
int flowControlIn,
int flowControlOut,
int databits,
int stopbits,
int parity,
boolean echo)
Constructs a new SerialParameters instance with
given parameters for a regular serial interface.
|
SerialParameters(String portName,
int baudRate,
int flowControlIn,
int flowControlOut,
int databits,
int stopbits,
int parity,
boolean echo,
boolean rs485Mode,
boolean rs485TxEnableActiveHigh,
int rs485DelayBeforeTxMicroseconds,
int rs485DelayAfterTxMicroseconds)
Constructs a new SerialParameters instance with given
parameters for a serial interface in RS-485 mode on Linux.
|
| Modifier and Type | Method and Description |
|---|---|
void |
disableRs485Control()
Disables RS-485 control signals management.
|
int |
getBaudRate()
Return the baud rate as int.
|
String |
getBaudRateString()
Returns the baud rate as a String.
|
int |
getDatabits()
Returns the number of data bits as int.
|
String |
getDatabitsString()
Returns the number of data bits as String.
|
String |
getEncoding()
Returns the encoding to be used.
|
int |
getFlowControlIn()
Returns the input flow control type as int.
|
String |
getFlowControlInString()
Returns the input flow control type as String.
|
int |
getFlowControlOut()
Returns the output flow control type as int.
|
String |
getFlowControlOutString()
Returns the output flow control type as String.
|
int |
getOpenDelay()
Gets the open delay used to prevent some OS from losing the comms port
|
int |
getParity()
Returns the parity schema as int.
|
String |
getParityString()
Returns the parity schema as String.
|
String |
getPortName()
Returns the port name.
|
int |
getRs485DelayAfterTxMicroseconds()
Returns the delay between the end of transmitting data and deactivating
the RS-485 transmitter.
|
int |
getRs485DelayBeforeTxMicroseconds()
Returns the delay between activating the RS-485 transmitter and actually
sending data.
|
boolean |
getRs485EnableTermination()
Returns whether the RS-485 interface shall enable internal bus
termination.
|
boolean |
getRs485Mode()
Returns whether RS-485 half-duplex mode is enabled.
|
boolean |
getRs485RxDuringTx()
Returns whether the RS-485 interface receives data it sends.
|
boolean |
getRs485TxEnableActiveHigh()
Returns whether the RS-485 transmitter is enabled by a high or low
control signal.
|
int |
getStopbits()
Returns the number of stop bits as int.
|
String |
getStopbitsString()
Returns the number of stop bits as String.
|
boolean |
isEcho()
Get the Echo value.
|
boolean |
isRs485ControlDisabled()
Returns whether RS-485 control signals management is disabled.
|
void |
setBaudRate(int rate)
Sets the baud rate.
|
void |
setBaudRate(String rate)
Sets the baud rate.
|
void |
setDatabits(int databits)
Sets the number of data bits.
|
void |
setDatabits(String databits)
Sets the number of data bits from the given String.
|
void |
setEcho(boolean newEcho)
Set the Echo value.
|
void |
setEncoding(String enc)
Sets the encoding to be used.
|
void |
setFlowControlIn(int flowControl)
Sets the type of flow control for the input
as given by the passed in int.
|
void |
setFlowControlIn(String flowControl)
Sets the type of flow control for the input
as given by the passed in String.
|
void |
setFlowControlOut(int flowControlOut)
Sets the output flow control type as given
by the passed in int.
|
void |
setFlowControlOut(String flowControlOut)
Sets the output flow control type as given
by the passed in String.
|
void |
setOpenDelay(int openDelay)
Sets the sleep time tat occurs just prior to opening a coms port
Some OS don't like to have their comms ports opened/closed in very quick succession
particularly, virtual ports.
|
void |
setOpenDelay(String openDelay)
Sets the sleep time tat occurs just prior to opening a coms port
Some OS don't like to have their comms ports opened/closed in very quick succession
particularly, virtual ports.
|
void |
setParity(int parity)
Sets the parity schema.
|
void |
setParity(String parity)
Sets the parity schema from the given
String.
|
void |
setPortName(String name)
Sets the port name.
|
void |
setRs485DelayAfterTxMicroseconds(int microseconds)
Sets the delay between the end of transmitting data and deactivating the
RS-485 transmitter.
|
void |
setRs485DelayAfterTxMicroseconds(String microseconds)
Sets the delay between end of transmitting data and deactivating the
RS-458 transmitter.
|
void |
setRs485DelayBeforeTxMicroseconds(int microseconds)
Sets the delay between activating the RS-485 transmitter and actually
sending data.
|
void |
setRs485DelayBeforeTxMicroseconds(String microseconds)
Sets the delay between activating the RS-485 transmitter and actually
sending data.
|
void |
setRs485EnableTermination(boolean enable)
Sets whether the RS-485 interface shall enable internal bus termination.
|
void |
setRs485Mode(boolean enable)
Sets whether to configure the serial interface into RS-485 half-duplex
mode.
|
void |
setRs485RxDuringTx(boolean enable)
Sets whether the RS-485 interface receives the data its sends.
|
void |
setRs485TxEnableActiveHigh(boolean activeHigh)
Sets whether the RS-485 transmitter is enabled by a high or low control
signal.
|
void |
setStopbits(int stopbits)
Sets the number of stop bits.
|
void |
setStopbits(String stopbits)
Sets the number of stop bits from the given String.
|
String |
toString() |
public SerialParameters()
public SerialParameters(String portName, int baudRate, int flowControlIn, int flowControlOut, int databits, int stopbits, int parity, boolean echo)
portName - The name of the port.baudRate - The baud rate.flowControlIn - Type of flow control for receiving.flowControlOut - Type of flow control for sending.databits - The number of data bits.stopbits - The number of stop bits. com.fazecast.jSerialComm.SerialPort stop-bit constants should be used in this method (ONE_STOP_BIT, ONE_POINT_FIVE_STOP_BITS, TWO_STOP_BITS)parity - The type of parity.echo - Flag for setting the RS485 echo mode.public SerialParameters(String portName, int baudRate, int flowControlIn, int flowControlOut, int databits, int stopbits, int parity, boolean echo, boolean rs485Mode, boolean rs485TxEnableActiveHigh, int rs485DelayBeforeTxMicroseconds, int rs485DelayAfterTxMicroseconds)
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
There are interfaces operating in RS-485 mode by default and don't require explicitly configuring this mode.
portName - The name of the port.baudRate - The baud rate.flowControlIn - Type of flow control for receiving.flowControlOut - Type of flow control for sending.databits - The number of data bits.stopbits - The number of stop bits. com.fazecast.jSerialComm.SerialPort stop-bit constants should be used in this method (ONE_STOP_BIT, ONE_POINT_FIVE_STOP_BITS, TWO_STOP_BITS)parity - The type of parity.echo - Flag for setting the RS485 echo mode.rs485Mode - Whether to enable RS-485 mode
(transmitter control)rs485TxEnableActiveHigh - Whether the RS-485 transmitter is
enabled when the by a high or low logic levelrs485DelayBeforeTxMicroseconds - The length of the delay between
enabling the transmitter and the
actual start of sending datars485DelayAfterTxMicroseconds - The length of the delay between
the end of a data transmission and
disabling the transmitter againpublic SerialParameters(Properties props, String prefix)
props - a Properties instance.prefix - a prefix for the properties keys if embedded into
other properties.public String getPortName()
public void setPortName(String name)
name - the new port name.public void setBaudRate(int rate)
rate - the new baud rate.public int getBaudRate()
public void setBaudRate(String rate)
rate - the new baud rate.public String getBaudRateString()
public void setFlowControlIn(int flowControl)
flowControl - the new flow control type.IllegalArgumentException - on invalid flowControlpublic int getFlowControlIn()
public void setFlowControlIn(String flowControl)
flowControl - the flow control for reading type.IllegalArgumentException - on invalid flowControlpublic String getFlowControlInString()
public void setFlowControlOut(int flowControlOut)
flowControlOut - new output flow control type as int.public int getFlowControlOut()
public void setFlowControlOut(String flowControlOut)
flowControlOut - the new output flow control type as String.public String getFlowControlOutString()
public void setDatabits(int databits)
databits - the new number of data bits.public int getDatabits()
public void setDatabits(String databits)
databits - the new number of data bits as String.public String getDatabitsString()
public void setStopbits(int stopbits)
stopbits - the new number of stop bits setting.public int getStopbits()
public void setStopbits(String stopbits)
stopbits - the number of stop bits as String.public String getStopbitsString()
public void setParity(int parity)
parity - the new parity schema as int.public int getParity()
public void setParity(String parity)
parity - the new parity schema as String.IllegalArgumentException - on invalid paritypublic String getParityString()
public String getEncoding()
Modbus.SERIAL_ENCODING_ASCII,
Modbus.SERIAL_ENCODING_RTUpublic void setEncoding(String enc)
enc - the encoding as string.IllegalArgumentException - on invalid parityModbus.SERIAL_ENCODING_ASCII,
Modbus.SERIAL_ENCODING_RTUpublic boolean isEcho()
public void setEcho(boolean newEcho)
newEcho - The new Echo value.public int getOpenDelay()
public void setOpenDelay(int openDelay)
openDelay - Sleep time in milliesecondspublic void setOpenDelay(String openDelay)
openDelay - Sleep time in milliesecondspublic boolean getRs485Mode()
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
public void setRs485Mode(boolean enable)
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
enable - Whether to enable RS-485 half-duplex modepublic boolean getRs485TxEnableActiveHigh()
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
public void setRs485TxEnableActiveHigh(boolean activeHigh)
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
activeHigh - If true, the transmitter is activated by a
high control signal level. Otherwise, it is activated
by a low level.public boolean getRs485EnableTermination()
This configuration option is only available under Linux and only if device driver and hardware support it.
public void setRs485EnableTermination(boolean enable)
This configuration option is only available under Linux and only if device driver and hardware support it.
enable - If true, the serial interface shall enable its
internal bus termination.public boolean getRs485RxDuringTx()
This configuration option is only available under Linux and only if device driver and hardware support it.
See setRs485RxDuringTx(boolean) for more details.
public void setRs485RxDuringTx(boolean enable)
This configuration option is only available under Linux and only if device driver and hardware support it.
BEWARE: For normal operation, j2mod expects this feature do be disable. This method is provided only for fixing the behaviour with certain device drivers which require this feature to be enabled for normal operation.
enable - If true, the serial interface is expected to
receive the data it transmits itself too.public int getRs485DelayBeforeTxMicroseconds()
Please note that the actual interface might not support a resolution down to microseconds and might require appropriately large values for actually generating a delay.
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
public void setRs485DelayBeforeTxMicroseconds(int microseconds)
Please note that the actual interface might not support a resolution down to microseconds and might require appropriately large values for actually generating a delay.
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
microseconds - The delay in microsecondsIllegalArgumentException - on strictly negative inputpublic void setRs485DelayBeforeTxMicroseconds(String microseconds)
This is a convenience wrapper around
setRs485DelayBeforeTxMicroseconds(int) which parses the delay
from the supplied string. See the documentation of this method for more
details.
microseconds - The string to parse the delay value frompublic int getRs485DelayAfterTxMicroseconds()
Please note that the actual interface might not support a resolution down to microseconds and might require appropriately large values for actually generating a delay.
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
public void setRs485DelayAfterTxMicroseconds(int microseconds)
Please note that the actual interface might not support a resolution down to microseconds and might require appropriately large values for actually generating a delay.
RS-485 half-duplex mode is only available on Linux and only if the device driver supports it. Its configuration parameters have no effect on other platforms.
microseconds - The delay in microsecondspublic void setRs485DelayAfterTxMicroseconds(String microseconds)
This is a convenience wrapper around
setRs485DelayAfterTxMicroseconds(int) which parses the delay
from the supplied string. See the documentation of this method for more
details.
microseconds - The string to parse the delay value frompublic void disableRs485Control()
Please note that this is only effective on Linux.
This function forces RS-485 mode to stay untouched, regardless of the current setting of RS-485 mode.
This function is necessary for Linux drivers that don't handle TIOCGRS485 properly.
public boolean isRs485ControlDisabled()
Copyright © 2025. All Rights Reserved.