public abstract class SerialChannel extends AbstractSelectableChannel implements GatheringByteChannel, ScatteringByteChannel
It is also possible to use Streams. Use getInputStream and getOutputStream.
| Modifier and Type | Class and Description |
|---|---|
static class |
SerialChannel.Builder
A class that is used to configure serial port and open it.
|
static class |
SerialChannel.Configuration |
static class |
SerialChannel.DataBits |
static class |
SerialChannel.FlowControl |
static class |
SerialChannel.Parity |
static class |
SerialChannel.Speed
Baud rate.
|
static class |
SerialChannel.StopBits |
| Modifier and Type | Field and Description |
|---|---|
protected long |
address |
protected boolean |
block |
protected boolean |
clearOnClose |
protected SerialChannel.Configuration |
configuration |
protected static org.vesalainen.util.logging.JavaLogging |
log |
static int |
MaxSelectors
The maximum number of reads or writes in select
|
protected String |
port |
protected ReentrantLock |
readLock |
protected ReentrantLock |
writeLock |
| Modifier | Constructor and Description |
|---|---|
protected |
SerialChannel() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearBuffers()
Clears input and output buffers.
|
void |
configure(SerialChannel.Configuration config)
Change channel configuration
|
static void |
debug(boolean on)
Sets the debug state.
|
protected abstract void |
doClearBuffers(long address) |
protected void |
doClose() |
protected abstract void |
doClose(long handle) |
protected abstract void |
doConfigure(long handle,
int baudRate,
int parity,
int dataBits,
int stopBits,
int flowControl,
boolean replaceError) |
protected abstract long |
doOpen(byte[] port) |
protected abstract int |
doRead(long handle,
ByteBuffer dst) |
protected abstract int |
doWrite(long handle,
ByteBuffer src) |
static List<String> |
getAllPorts()
Returns all available ports.
|
SerialChannel.Configuration |
getConfiguration()
Returns the current configuration
|
SerialChannel.DataBits |
getDataBits() |
static SerialChannel.DataBits |
getDataBits(int bits) |
static byte[] |
getErrorReplacement() |
SerialChannel.FlowControl |
getFlowControl() |
static SerialChannel.FlowControl |
getFlowControl(String flow) |
static List<String> |
getFreePorts()
Returns all ports that can be opened.
|
InputStream |
getInputStream(int bufferSize)
Returns InputStream.
|
OutputStream |
getOutputStream(int bufferSize)
Returns OutputStream.
|
SerialChannel.Parity |
getParity() |
static SerialChannel.Parity |
getParity(String parity) |
String |
getPort()
Returns the port.
|
SerialChannel.Speed |
getSpeed() |
static SerialChannel.Speed |
getSpeed(int speed)
Return the speed
|
static int |
getSpeed(SerialChannel.Speed speed)
Return the speed
|
SerialChannel.StopBits |
getStopBits() |
static SerialChannel.StopBits |
getStopBits(int bits) |
protected void |
implCloseSelectableChannel() |
protected void |
implConfigureBlocking(boolean block) |
boolean |
isClearOnClose() |
boolean |
isReplaceError() |
protected void |
open()
Creates actual connection.
|
int |
read(ByteBuffer dst)
Reads data at buffers position and then increments the position.
|
long |
read(ByteBuffer[] dsts) |
long |
read(ByteBuffer[] dsts,
int offset,
int length) |
void |
setClearOnClose(boolean clearOnClose) |
protected abstract void |
setTimeouts() |
protected abstract int |
version() |
int |
write(ByteBuffer src)
Writes data at buffers position and then increments the position.
|
long |
write(ByteBuffer[] srcs) |
long |
write(ByteBuffer[] srcs,
int offset,
int length) |
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, registerregister, validOpsbegin, close, end, isOpenpublic static final int MaxSelectors
protected long address
protected String port
protected SerialChannel.Configuration configuration
protected boolean block
protected boolean clearOnClose
protected ReentrantLock readLock
protected ReentrantLock writeLock
protected static final org.vesalainen.util.logging.JavaLogging log
protected abstract int version()
public void clearBuffers()
protected abstract void doClearBuffers(long address)
public SerialChannel.Configuration getConfiguration()
public boolean isClearOnClose()
public void setClearOnClose(boolean clearOnClose)
protected void implConfigureBlocking(boolean block)
throws IOException
implConfigureBlocking in class AbstractSelectableChannelIOExceptionprotected abstract void setTimeouts()
throws IOException
IOExceptionpublic static int getSpeed(SerialChannel.Speed speed)
speed - public static SerialChannel.Speed getSpeed(int speed)
speed - public static SerialChannel.DataBits getDataBits(int bits)
public static SerialChannel.StopBits getStopBits(int bits)
public static SerialChannel.Parity getParity(String parity)
public static SerialChannel.FlowControl getFlowControl(String flow)
public String getPort()
protected void open()
throws IOException
IOExceptionprotected abstract long doOpen(byte[] port)
public static byte[] getErrorReplacement()
public void configure(SerialChannel.Configuration config) throws IOException
config - IOExceptionprotected abstract void doConfigure(long handle,
int baudRate,
int parity,
int dataBits,
int stopBits,
int flowControl,
boolean replaceError)
throws IOException
IOExceptionpublic InputStream getInputStream(int bufferSize)
Using streams is not allowed in non-blocking mode.
bufferSize - IllegalStateException - if in non-blocking mode.public OutputStream getOutputStream(int bufferSize)
Using streams is not allowed in non-blocking mode.
bufferSize - IllegalStateException - if in non-blocking mode.public int read(ByteBuffer dst) throws IOException
read in interface ReadableByteChanneldst - IOExceptionprotected abstract int doRead(long handle,
ByteBuffer dst)
throws IOException
IOExceptionpublic int write(ByteBuffer src) throws IOException
write in interface WritableByteChannelsrc - IOExceptionprotected abstract int doWrite(long handle,
ByteBuffer src)
throws IOException
IOExceptionpublic static void debug(boolean on)
on - public static List<String> getFreePorts()
public SerialChannel.DataBits getDataBits()
public SerialChannel.FlowControl getFlowControl()
public SerialChannel.Parity getParity()
public SerialChannel.Speed getSpeed()
public SerialChannel.StopBits getStopBits()
public boolean isReplaceError()
protected void implCloseSelectableChannel()
throws IOException
implCloseSelectableChannel in class AbstractSelectableChannelIOExceptionprotected void doClose()
throws IOException
IOExceptionprotected abstract void doClose(long handle)
throws IOException
IOExceptionpublic long write(ByteBuffer[] srcs, int offset, int length) throws IOException
write in interface GatheringByteChannelIOExceptionpublic long write(ByteBuffer[] srcs) throws IOException
write in interface GatheringByteChannelIOExceptionpublic long read(ByteBuffer[] dsts, int offset, int length) throws IOException
read in interface ScatteringByteChannelIOExceptionpublic long read(ByteBuffer[] dsts) throws IOException
read in interface ScatteringByteChannelIOExceptionCopyright © 2015. All rights reserved.