Class LocalSerialPort
java.lang.Object
org.harctoolbox.harchardware.comm.LocalSerialPort
- All Implemented Interfaces:
Closeable,AutoCloseable,IHarcHardware
- Direct Known Subclasses:
LocalSerialPortBuffered,LocalSerialPortRaw
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final intstatic final intstatic final LocalSerialPort.FlowControlstatic final LocalSerialPort.Paritystatic final Stringstatic final LocalSerialPort.StopBitsstatic final intprotected InputStreamprotected OutputStreamprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionLocalSerialPort(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 StringcanonicalizePortName(String portName) static StringcanonicalizePortName(String name, String dflt) voidclose()voiddropDTR(int duration) voidflush()voidReturns the nominal port name being used.static StringgetSerialPortName(Integer portNumber) getSerialPortNames(boolean useCached) Returns all serial port names found in the system.static StringReturns the hardware version (not the version of the driver software).booleanisValid()Checks validity of an instance.static LocalSerialPort.StopBitsmkStopBits(int stopBits) voidopen()Opens the device.voidsetDebug(int dbg) Sets a debug parameter.voidsetDTR(boolean state) static voidsetLibraryDir(File libraryDir) voidsetTimeout(int timeout) Set timeout in milliseconds.voidsetVerbose(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:
NonExistingPortExceptionIOException
-
-
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:IHarcHardwareSets 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:
setVerbosein interfaceIHarcHardware- Parameters:
verbose- on or off
-
open
Opens the device.- Specified by:
openin interfaceIHarcHardware- Throws:
NonExistingPortExceptionHarcHardwareException- Bundles RXTX exceptions together.IOException
-
flushInput
- Throws:
IOException
-
isValid
public boolean isValid()Description copied from interface:IHarcHardwareChecks validity of an instance. Exact meaning can vary.- Specified by:
isValidin interfaceIHarcHardware- Returns:
- validity of the instance.
-
setTimeout
Description copied from interface:IHarcHardwareSet timeout in milliseconds. Exact semantics may be dependent on the hardware.- Specified by:
setTimeoutin interfaceIHarcHardware- Parameters:
timeout- Timeout in milliseconds.- Throws:
IOException
-
getVersion
Description copied from interface:IHarcHardwareReturns the hardware version (not the version of the driver software). May be null if no relevant information available.- Specified by:
getVersionin 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:
closein interfaceAutoCloseable- Specified by:
closein 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:IHarcHardwareSets a debug parameter. Exact semantic depends on the implementation.- Specified by:
setDebugin interfaceIHarcHardware
-