Class LocalSerialPort
java.lang.Object
org.harctoolbox.harchardware.comm.LocalSerialPort
- All Implemented Interfaces:
Closeable
,AutoCloseable
,IHarcHardware
- Direct Known Subclasses:
LocalSerialPortBuffered
,LocalSerialPortRaw
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
static enum
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final int
static final int
static final LocalSerialPort.FlowControl
static final LocalSerialPort.Parity
static final String
static final LocalSerialPort.StopBits
static final int
protected InputStream
protected OutputStream
protected boolean
-
Constructor Summary
ConstructorDescriptionLocalSerialPort
(Integer portNumber) LocalSerialPort
(String portName) LocalSerialPort
(String portName, boolean verbose) LocalSerialPort
(String portName, boolean verbose, Integer timeout) LocalSerialPort
(String portName, boolean verbose, Integer timeout, Integer baud) LocalSerialPort
(String portName, boolean verbose, Integer timeout, Integer baud, Integer dataLength, LocalSerialPort.StopBits stopBits, LocalSerialPort.Parity parity, LocalSerialPort.FlowControl flowControl) -
Method Summary
Modifier and TypeMethodDescriptionstatic String
canonicalizePortName
(String portName) static String
canonicalizePortName
(String name, String dflt) void
close()
void
dropDTR
(int duration) void
flush()
void
Returns the nominal port name being used.static String
getSerialPortName
(Integer portNumber) getSerialPortNames
(boolean useCached) Returns all serial port names found in the system.static String
Returns the hardware version (not the version of the driver software).boolean
isValid()
Checks validity of an instance.static LocalSerialPort.StopBits
mkStopBits
(int stopBits) void
open()
Opens the device.void
setDebug
(int dbg) Sets a debug parameter.void
setDTR
(boolean state) static void
setLibraryDir
(File libraryDir) void
setTimeout
(int timeout) Set timeout in milliseconds.void
setVerbose
(boolean verbose) Sets a verbosity flag, causing commands to be executed verbosely.
-
Field Details
-
DEFAULT_PORT
- See Also:
-
DEFAULT_BAUD
public static final int DEFAULT_BAUD- See Also:
-
DEFAULT_DATABITS
public static final int DEFAULT_DATABITS- See Also:
-
DEFAULT_PARITY
-
DEFAULT_STOPBITS
-
DEFAULT_FLOWCONTROL
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT- See Also:
-
DEFAULT
- See Also:
-
inStream
-
outStream
-
verbose
protected boolean verbose
-
-
Constructor Details
-
LocalSerialPort
public LocalSerialPort(String portName, boolean verbose, Integer timeout, Integer baud, Integer dataLength, LocalSerialPort.StopBits stopBits, LocalSerialPort.Parity parity, LocalSerialPort.FlowControl flowControl) throws IOException - Throws:
IOException
-
LocalSerialPort
public LocalSerialPort(String portName, boolean verbose, Integer timeout, Integer baud) throws IOException - Throws:
IOException
-
LocalSerialPort
- Throws:
IOException
-
LocalSerialPort
- Throws:
IOException
-
LocalSerialPort
- Throws:
IOException
-
LocalSerialPort
- Throws:
NonExistingPortException
IOException
-
-
Method Details
-
setLibraryDir
- Throws:
IOException
-
getSerialPortName
- Throws:
NonExistingPortException
-
getSerialPortNames
Returns all serial port names found in the system.- Parameters:
useCached
- If true, use previously acquired list, if available- Returns:
- ArrayList<String>
- Throws:
IOException
-
canonicalizePortName
- Throws:
IOException
-
canonicalizePortName
- Throws:
IOException
-
getSoftwareVersion
-
mkStopBits
-
setVerbose
public void setVerbose(boolean verbose) Description copied from interface:IHarcHardware
Sets a verbosity flag, causing commands to be executed verbosely. Exact semantic depends on the implementation. Typically, all communication with the device is echoed to stderr.- Specified by:
setVerbose
in interfaceIHarcHardware
- Parameters:
verbose
- on or off
-
open
Opens the device.- Specified by:
open
in interfaceIHarcHardware
- Throws:
NonExistingPortException
HarcHardwareException
- Bundles RXTX exceptions together.IOException
-
flushInput
- Throws:
IOException
-
isValid
public boolean isValid()Description copied from interface:IHarcHardware
Checks validity of an instance. Exact meaning can vary.- Specified by:
isValid
in interfaceIHarcHardware
- Returns:
- validity of the instance.
-
setTimeout
Description copied from interface:IHarcHardware
Set timeout in milliseconds. Exact semantics may be dependent on the hardware.- Specified by:
setTimeout
in interfaceIHarcHardware
- Parameters:
timeout
- Timeout in milliseconds.- Throws:
IOException
-
getVersion
Description copied from interface:IHarcHardware
Returns the hardware version (not the version of the driver software). May be null if no relevant information available.- Specified by:
getVersion
in interfaceIHarcHardware
- Returns:
- Version string. Semantics can vary.
-
getPortName
Returns the nominal port name being used. May differ from one requested in the constructor if the device was opened with open(true), or if it is symlink (for example created by udev).- Returns:
- port name used.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
flush
- Throws:
IOException
-
setDTR
public void setDTR(boolean state) -
dropDTR
public void dropDTR(int duration) -
setDebug
public void setDebug(int dbg) Description copied from interface:IHarcHardware
Sets a debug parameter. Exact semantic depends on the implementation.- Specified by:
setDebug
in interfaceIHarcHardware
-