net.wimpi.modbus.util
Class SerialParameters

java.lang.Object
  extended by net.wimpi.modbus.util.SerialParameters

public class SerialParameters
extends Object

Helper class wrapping all serial port communication parameters. Very similar to the javax.comm demos, however, not the same.

Version:
@version@ (@date@)
Author:
Dieter Wimberger, John Charlton

Constructor Summary
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, int timeout)
          Constructs a new SerialParameters instance with given parameters.
 
Method Summary
 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 getParity()
          Returns the parity schema as int.
 String getParityString()
          Returns the parity schema as String.
 String getPortName()
          Returns the port name.
 int getReceiveTimeout()
          Returns the receive timeout for serial communication.
 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.
 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 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 setReceiveTimeout(int receiveTimeout)
          Sets the receive timeout for serial communication.
 void setReceiveTimeout(String str)
          Sets the receive timeout for the serial communication parsing the given String using Integer.parseInt(String).
 void setStopbits(int stopbits)
          Sets the number of stop bits.
 void setStopbits(String stopbits)
          Sets the number of stop bits from the given String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerialParameters

public SerialParameters()
Constructs a new SerialParameters instance with default values.


SerialParameters

public SerialParameters(String portName,
                        int baudRate,
                        int flowControlIn,
                        int flowControlOut,
                        int databits,
                        int stopbits,
                        int parity,
                        boolean echo,
                        int timeout)
Constructs a new SerialParameters instance with given parameters.

Parameters:
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.
parity - The type of parity.
echo - Flag for setting the RS485 echo mode.

SerialParameters

public SerialParameters(Properties props,
                        String prefix)
Constructs a new SerialParameters instance with parameters obtained from a Properties instance.

Parameters:
props - a Properties instance.
prefix - a prefix for the properties keys if embedded into other properties.
Method Detail

setPortName

public void setPortName(String name)
Sets the port name.

Parameters:
name - the new port name.

getPortName

public String getPortName()
Returns the port name.

Returns:
the port name.

setBaudRate

public void setBaudRate(int rate)
Sets the baud rate.

Parameters:
rate - the new baud rate.

setBaudRate

public void setBaudRate(String rate)
Sets the baud rate.

Parameters:
rate - the new baud rate.

getBaudRate

public int getBaudRate()
Return the baud rate as int.

Returns:
the baud rate as int.

getBaudRateString

public String getBaudRateString()
Returns the baud rate as a String.

Returns:
the baud rate as String.

setFlowControlIn

public void setFlowControlIn(int flowcontrol)
Sets the type of flow control for the input as given by the passed in int.

Parameters:
flowcontrol - the new flow control type.

setFlowControlIn

public void setFlowControlIn(String flowcontrol)
Sets the type of flow control for the input as given by the passed in String.

Parameters:
flowcontrol - the flow control for reading type.

getFlowControlIn

public int getFlowControlIn()
Returns the input flow control type as int.

Returns:
the input flow control type as int.

getFlowControlInString

public String getFlowControlInString()
Returns the input flow control type as String.

Returns:
the input flow control type as String.

setFlowControlOut

public void setFlowControlOut(int flowControlOut)
Sets the output flow control type as given by the passed in int.

Parameters:
flowControlOut - new output flow control type as int.

setFlowControlOut

public void setFlowControlOut(String flowControlOut)
Sets the output flow control type as given by the passed in String.

Parameters:
flowControlOut - the new output flow control type as String.

getFlowControlOut

public int getFlowControlOut()
Returns the output flow control type as int.

Returns:
the output flow control type as int.

getFlowControlOutString

public String getFlowControlOutString()
Returns the output flow control type as String.

Returns:
the output flow control type as String.

setDatabits

public void setDatabits(int databits)
Sets the number of data bits.

Parameters:
databits - the new number of data bits.

setDatabits

public void setDatabits(String databits)
Sets the number of data bits from the given String.

Parameters:
databits - the new number of data bits as String.

getDatabits

public int getDatabits()
Returns the number of data bits as int.

Returns:
the number of data bits as int.

getDatabitsString

public String getDatabitsString()
Returns the number of data bits as String.

Returns:
the number of data bits as String.

setStopbits

public void setStopbits(int stopbits)
Sets the number of stop bits.

Parameters:
stopbits - the new number of stop bits setting.

setStopbits

public void setStopbits(String stopbits)
Sets the number of stop bits from the given String.

Parameters:
stopbits - the number of stop bits as String.

getStopbits

public int getStopbits()
Returns the number of stop bits as int.

Returns:
the number of stop bits as int.

getStopbitsString

public String getStopbitsString()
Returns the number of stop bits as String.

Returns:
the number of stop bits as String.

setParity

public void setParity(int parity)
Sets the parity schema.

Parameters:
parity - the new parity schema as int.

setParity

public void setParity(String parity)
Sets the parity schema from the given String.

Parameters:
parity - the new parity schema as String.

getParity

public int getParity()
Returns the parity schema as int.

Returns:
the parity schema as int.

getParityString

public String getParityString()
Returns the parity schema as String.

Returns:
the parity schema as String.

setEncoding

public void setEncoding(String enc)
Sets the encoding to be used.

Parameters:
enc - the encoding as string.
See Also:
Modbus.SERIAL_ENCODING_ASCII, Modbus.SERIAL_ENCODING_RTU, Modbus.SERIAL_ENCODING_BIN

getEncoding

public String getEncoding()
Returns the encoding to be used.

Returns:
the encoding as string.
See Also:
Modbus.SERIAL_ENCODING_ASCII, Modbus.SERIAL_ENCODING_RTU, Modbus.SERIAL_ENCODING_BIN

isEcho

public boolean isEcho()
Get the Echo value.

Returns:
the Echo value.

setEcho

public void setEcho(boolean newEcho)
Set the Echo value.

Parameters:
newEcho - The new Echo value.

getReceiveTimeout

public int getReceiveTimeout()
Returns the receive timeout for serial communication.

Returns:
the timeout in milliseconds.

setReceiveTimeout

public void setReceiveTimeout(int receiveTimeout)
Sets the receive timeout for serial communication.

Parameters:
receiveTimeout - the receiveTimeout in milliseconds.

setReceiveTimeout

public void setReceiveTimeout(String str)
Sets the receive timeout for the serial communication parsing the given String using Integer.parseInt(String).

Parameters:
str - the timeout as String.


Copyright © 2010. All Rights Reserved.