Module de.ibapl.spsw.jniprovider
Package de.ibapl.spsw.jniprovider
Class AbstractSerialPortSocket<T extends AbstractSerialPortSocket<T>>
- java.lang.Object
-
- java.nio.channels.spi.AbstractInterruptibleChannel
-
- de.ibapl.spsw.jniprovider.AbstractSerialPortSocket<T>
-
- All Implemented Interfaces:
SerialPortConfiguration,SerialPortSocket,Closeable,AutoCloseable,ByteChannel,Channel,InterruptibleChannel,ReadableByteChannel,WritableByteChannel
- Direct Known Subclasses:
GenericTermiosSerialPortSocket,GenericWinSerialPortSocket
public abstract class AbstractSerialPortSocket<T extends AbstractSerialPortSocket<T>> extends AbstractInterruptibleChannel implements SerialPortSocket
Base class for GenericTermiosSerialPortSocket and GenericWinSerialPortSocket with common JNI bindings.- Author:
- scream3r, Arne Plöse
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractSerialPortSocket.SerialInputStreamprotected classAbstractSerialPortSocket.SerialOutputStream
-
Field Summary
Fields Modifier and Type Field Description protected AbstractSerialPortSocket.SerialInputStreamisprotected AbstractSerialPortSocket.SerialOutputStreamos-
Fields inherited from interface de.ibapl.spsw.api.SerialPortConfiguration
INFINITE_TIMEOUT, PORT_FD_INVALID, PORT_IS_CLOSED, PORT_IS_OPEN
-
-
Constructor Summary
Constructors Constructor Description AbstractSerialPortSocket(String portName)Creates a new Instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidensureOpen()DataBitsgetDatatBits()Set<FlowControl>getFlowControl()intgetInBufferBytesCount()InputStreamgetInputStream()intgetOutBufferBytesCount()OutputStreamgetOutputStream()protected intgetParameters(int parameterBitSetMask)Returns the parameters as masked bit set.ParitygetParity()StringgetPortName()SpeedgetSpeed()StopBitsgetStopBits()chargetXOFFChar()chargetXONChar()protected voidimplCloseChannel()booleanisCTS()booleanisDCD()booleanisDSR()booleanisRI()protected voidopen(Speed speed, DataBits dataBits, StopBits stopBits, Parity parity, Set<FlowControl> flowControls)protected abstract voidopen(String portName, int paramBitSet)Open portintread(ByteBuffer dst)voidsendBreak(int duration)voidsetBreak(boolean value)voidsetDataBits(DataBits dataBits)voidsetDTR(boolean value)voidsetFlowControl(Set<FlowControl> flowControls)protected voidsetParameters(int parameterBitSet)Set the parameters that are set in the parameterBitSet.voidsetParity(Parity parity)voidsetRTS(boolean value)voidsetSpeed(Speed speed)voidsetStopBits(StopBits stopBits)voidsetXOFFChar(char c)voidsetXONChar(char c)StringtoString()intwrite(ByteBuffer src)protected voidwriteBytes_ParamsOK(byte[] b, int off, int len)Write data to portprotected voidwriteSingle(int b)-
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.nio.channels.InterruptibleChannel
close
-
Methods inherited from interface de.ibapl.spsw.api.SerialPortConfiguration
calculateMillisForCharacters, calculateMillisPerCharacter, calculateSpeedInCharactersPerSecond, drainOutputBuffer, getInterByteReadTimeout, getOverallReadTimeout, getOverallWriteTimeout, sendXOFF, sendXON, setTimeouts
-
-
-
-
Field Detail
-
is
protected AbstractSerialPortSocket.SerialInputStream is
-
os
protected AbstractSerialPortSocket.SerialOutputStream os
-
-
Constructor Detail
-
AbstractSerialPortSocket
public AbstractSerialPortSocket(String portName)
Creates a new Instance.- Parameters:
portName- the name of the port.- See Also:
FileOutputStream(String)
-
-
Method Detail
-
getXOFFChar
public char getXOFFChar() throws IOException- Specified by:
getXOFFCharin interfaceSerialPortConfiguration- Throws:
IOException
-
getXONChar
public char getXONChar() throws IOException- Specified by:
getXONCharin interfaceSerialPortConfiguration- Throws:
IOException
-
isCTS
public boolean isCTS() throws IOException- Specified by:
isCTSin interfaceSerialPortConfiguration- Throws:
IOException
-
isDSR
public boolean isDSR() throws IOException- Specified by:
isDSRin interfaceSerialPortConfiguration- Throws:
IOException
-
isDCD
public boolean isDCD() throws IOException- Specified by:
isDCDin interfaceSerialPortConfiguration- Throws:
IOException
-
isRI
public boolean isRI() throws IOException- Specified by:
isRIin interfaceSerialPortConfiguration- Throws:
IOException
-
getParameters
protected int getParameters(int parameterBitSetMask) throws IOExceptionReturns the parameters as masked bit set.- Returns:
- the parameters as masked bit set.
- Throws:
IOException
-
getInBufferBytesCount
public int getInBufferBytesCount() throws IOException- Specified by:
getInBufferBytesCountin interfaceSerialPortConfiguration- Throws:
IOException
-
getOutBufferBytesCount
public int getOutBufferBytesCount() throws IOException- Specified by:
getOutBufferBytesCountin interfaceSerialPortConfiguration- Throws:
IOException
-
setDTR
public void setDTR(boolean value) throws IOException- Specified by:
setDTRin interfaceSerialPortConfiguration- Throws:
IOException
-
setParameters
protected void setParameters(int parameterBitSet) throws IOExceptionSet the parameters that are set in the parameterBitSet.- Parameters:
parameterBitSet- the parameters to set in a masked bit set.- Throws:
IOException
-
setXOFFChar
public void setXOFFChar(char c) throws IOException- Specified by:
setXOFFCharin interfaceSerialPortConfiguration- Throws:
IOException
-
setXONChar
public void setXONChar(char c) throws IOException- Specified by:
setXONCharin interfaceSerialPortConfiguration- Throws:
IOException
-
writeBytes_ParamsOK
protected void writeBytes_ParamsOK(byte[] b, int off, int len) throws IOExceptionWrite data to port- Parameters:
b-off- the start offset in the data.len- the number of bytes to write.- Throws:
IOException
-
writeSingle
protected void writeSingle(int b) throws IOException- Throws:
IOException
-
read
public int read(ByteBuffer dst) throws IOException
- Specified by:
readin interfaceReadableByteChannel- Throws:
IOException
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
implCloseChannel
protected void implCloseChannel() throws IOException- Specified by:
implCloseChannelin classAbstractInterruptibleChannel- Throws:
IOException
-
getSpeed
public Speed getSpeed() throws IOException
- Specified by:
getSpeedin interfaceSerialPortConfiguration- Throws:
IOException
-
getDatatBits
public DataBits getDatatBits() throws IOException
- Specified by:
getDatatBitsin interfaceSerialPortConfiguration- Throws:
IOException
-
getFlowControl
public Set<FlowControl> getFlowControl() throws IOException
- Specified by:
getFlowControlin interfaceSerialPortConfiguration- Throws:
IOException
-
getInputStream
public InputStream getInputStream() throws IOException
- Specified by:
getInputStreamin interfaceSerialPortSocket- Throws:
IOException
-
getOutputStream
public OutputStream getOutputStream() throws IOException
- Specified by:
getOutputStreamin interfaceSerialPortSocket- Throws:
IOException
-
getParity
public Parity getParity() throws IOException
- Specified by:
getParityin interfaceSerialPortConfiguration- Throws:
IOException
-
getPortName
public String getPortName()
- Specified by:
getPortNamein interfaceSerialPortConfiguration
-
getStopBits
public StopBits getStopBits() throws IOException
- Specified by:
getStopBitsin interfaceSerialPortConfiguration- Throws:
IOException
-
ensureOpen
public void ensureOpen() throws IOException- Throws:
IOException
-
open
protected void open(Speed speed, DataBits dataBits, StopBits stopBits, Parity parity, Set<FlowControl> flowControls) throws IOException
- Throws:
IOException
-
open
protected abstract void open(String portName, int paramBitSet) throws IOException
Open port- Parameters:
portName- the name of port for openingparamBitSet- the parameters as masked bit set.- Throws:
IOException
-
sendBreak
public void sendBreak(int duration) throws IOException- Specified by:
sendBreakin interfaceSerialPortConfiguration- Throws:
IOException
-
setSpeed
public void setSpeed(Speed speed) throws IOException
- Specified by:
setSpeedin interfaceSerialPortConfiguration- Throws:
IOException
-
setBreak
public void setBreak(boolean value) throws IOException- Specified by:
setBreakin interfaceSerialPortConfiguration- Throws:
IOException
-
setDataBits
public void setDataBits(DataBits dataBits) throws IOException
- Specified by:
setDataBitsin interfaceSerialPortConfiguration- Throws:
IOException
-
setFlowControl
public void setFlowControl(Set<FlowControl> flowControls) throws IOException
- Specified by:
setFlowControlin interfaceSerialPortConfiguration- Throws:
IOException
-
setParity
public void setParity(Parity parity) throws IOException
- Specified by:
setParityin interfaceSerialPortConfiguration- Throws:
IOException
-
setRTS
public void setRTS(boolean value) throws IOException- Specified by:
setRTSin interfaceSerialPortConfiguration- Throws:
IOException
-
setStopBits
public void setStopBits(StopBits stopBits) throws IOException
- Specified by:
setStopBitsin interfaceSerialPortConfiguration- Throws:
IOException
-
-