public final class SerialComManager extends Object
Root of SerialPundit.
Native layer if fails to throw exception when an error occurs would log error message to STDERR file. It is assumed that Java application running on production systems will deploy a Java logger which will redirect STDERR messages to a log file. This way if an error occurs and native layer could not throw exception for example in out of memory case it will still be logged for later analysis.
| Modifier and Type | Class and Description |
|---|---|
static class |
SerialComManager.BAUDRATE
Pre-defined enum constants for baud rate values.
|
static class |
SerialComManager.DATABITS
Pre-defined enum constants for number of data bits in a serial frame.
|
static class |
SerialComManager.ENDIAN
Pre-defined enum constants for defining endianness of data to be sent over serial port.
|
static class |
SerialComManager.FLOWCONTROL
Pre-defined enum constants for controlling data flow between DTE and DCE or two serial devices.
|
static class |
SerialComManager.FTPPROTO
Pre-defined enum constants for defining file transfer protocol to use.
|
static class |
SerialComManager.FTPVAR
Pre-defined enum constants for defining variant of file transfer protocol to use.
|
static class |
SerialComManager.NUMOFBYTES
Pre-defined enum constants for defining number of bytes given data can be represented in.
|
static class |
SerialComManager.PARITY
Pre-defined enum constants for enabling type of parity in a serial frame.
|
static class |
SerialComManager.SMODE
Pre-defined enum constants for defining behavior of byte stream.
|
static class |
SerialComManager.STOPBITS
Pre-defined enum constants for number of stop bits in a serial frame.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
CTS
Clear to send mask bit constant for UART control line.
|
static int |
DCD
Data carrier detect mask bit constant for UART control line.
|
static int |
DEFAULT_READBYTECOUNT
Default number of bytes (1024) to read from serial port.
|
static int |
DSR
Data set ready mask bit constant for UART control line.
|
static int |
DTR
Data terminal ready mask bit constant for UART control line.
|
static String |
EXP_UNBLOCKIO
The exception message indicating that a blocked read method has been unblocked
and made to return to caller explicitly (irrespective there was data to read or not).
|
static int |
InputStream
The value indicating instance of SerialComInByteStream class is desired.
|
static String |
JAVA_LIB_VERSION
Production release version of the SerialPundit.
|
static int |
LOOP
Loop indicator mask bit constant for UART control line.
|
static int |
OutputStream
The value indicating instance of SerialComOutByteStream class is desired.
|
static int |
RI
Ring indicator mask bit constant for UART control line.
|
static int |
RTS
Request to send mask bit constant for UART control line.
|
| Constructor and Description |
|---|
SerialComManager()
Allocates a new SerialComManager object.
|
SerialComManager(String loadedLibName,
String directoryPath,
boolean createDirectory,
boolean hotDeploy)
Allocates a new SerialComManager object.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
clearPortIOBuffers(long handle,
boolean clearRxBuffer,
boolean clearTxBuffer)
Discards data sent to port but not transmitted, or data received but not read.
|
boolean |
closeComPort(long handle)
Close the serial port.
|
boolean |
configureComPortControl(long handle,
SerialComManager.FLOWCONTROL flowctrl,
char xon,
char xoff,
boolean ParFraError,
boolean overFlowErr)
This method configures the way data communication will be controlled between DTE and DCE.
|
boolean |
configureComPortData(long handle,
SerialComManager.DATABITS dataBits,
SerialComManager.STOPBITS stopBits,
SerialComManager.PARITY parity,
SerialComManager.BAUDRATE baudRate,
int custBaud)
This method configures the rate at which communication will occur and the format of UART frame.
|
long |
createBlockingIOContext()
Prepares a context that should be passed to readBytesBlocking, writeBytesBlocking,
readBytes, unblockBlockingIOOperation and destroyBlockingIOContext methods.
|
boolean |
destroyBlockingIOContext(long context)
Destroys the context that was created by a call to createBlockingIOContext method for
blocking I/O operations uses.
|
String |
findDriverServingComPort(String comPortName)
Gives the name of the driver who is driving the given serial port.
|
String |
findIRQnumberForComPort(long handle)
Gives the address and IRQ number associated with the given serial port.
|
boolean |
fineTuneReadBehaviour(long handle,
int vmin,
int vtime,
int rit,
int rttm,
int rttc)
This method gives more fine tune control to application for tuning performance and behavior of read
operations to leverage OS specific facility for read operation.
|
int[] |
getByteCountInPortIOBuffer(long handle)
Get number of bytes in input and output port buffers used by operating system for instance tty buffers
in Unix like systems.
|
String[] |
getCurrentConfiguration(long handle)
This method gives currently applicable settings associated with particular serial port.
|
int |
getEventsMask(ISerialComEventListener eventListener)
This method return currently applicable mask for events on serial port.
|
int[] |
getInterruptCount(long handle)
This method gives the number of interrupts on serial line that have occurred.
|
ISerialIOStream |
getIOStreamInstance(int streamType,
long handle,
SerialComManager.SMODE streamMode)
Factory method to create stream of type specified by streamType in blocking or non-blocking mode.
|
String |
getLibraryVersions()
Gives library versions of java and native library implementations for serial port communication.
|
int[] |
getLinesStatus(long handle)
Gives status of serial port's control lines as supported by underlying operating system.
|
String |
getPortName(long handle)
This method gives the port name with which given handle is associated.
|
SerialComDBRelease |
getSerialComDBReleaseInstance(String directoryPath,
String loadedLibName)
Allocate, initialize and return an instance of SerialComDBRelease class on whom APIs can
be called to release COM ports in use.
|
SerialComNullModem |
getSerialComNullModemInstance()
Provides an instance of SerialComNullModem class for managing virtual serial device, null modem,
loop back and custom pinout connected virtual serial devices.
|
SerialComPortMapper |
getSerialComPortMapperInstance(String directoryPath,
String loadedLibName)
Allocate, initialize and return an instance of SerialComPortMapper class on whom APIs can
be called to map or unmap a serial port alias.
|
SerialComVendorLib |
getVendorLibFromFactory(int vendorLibIdentifier,
String libDirectory,
String vlibName)
Gives an instance of the class which implements API defined by vendor in their propriety library.
|
String[] |
listAvailableComPorts()
Returns all available UART style ports available on this system, otherwise an empty array of strings,
if no serial style port is found in the system.
|
long |
openComPort(String portName,
boolean enableRead,
boolean enableWrite,
boolean exclusiveOwnerShip)
Opens a serial port for communication.
|
boolean |
pauseListeningEvents(ISerialComEventListener eventListener)
This pauses delivering events to application.
|
byte[] |
readBytes(long handle)
If user does not specify any count, library try to read DEFAULT_READBYTECOUNT (1024 bytes)
bytes as default value.
|
int |
readBytes(long handle,
byte[] buffer,
int offset,
int length,
long context,
SerialComLineErrors lineErr)
Reads data bytes from serial port into given buffer also providing info about framing, parity etc errors.
|
byte[] |
readBytes(long handle,
int byteCount)
Read specified number of data bytes from the given serial port.
|
byte[] |
readBytesBlocking(long handle,
int byteCount,
long context)
Read specified number of bytes from given serial port and stay blocked till bytes arrive
at serial port.
|
int |
readBytesDirect(long handle,
ByteBuffer buffer,
int offset,
int length)
Reads the bytes from the serial port into the given direct byte buffer using facilities of
the underlying JVM and operating system.
|
byte[] |
readSingleByte(long handle)
This is a utility method to read a single byte from serial port.
|
String |
readString(long handle)
This method reads data from serial port and converts it into string.
|
String |
readString(long handle,
int byteCount)
Reads data from serial port and converts it into string.
|
boolean |
receiveFile(long handle,
File fileToReceive,
SerialComManager.FTPPROTO ftpProto,
SerialComManager.FTPVAR ftpVariant,
boolean textMode,
ISerialComFTPProgress progressListener,
SerialComFTPCMDAbort transferState)
Receives file using specified file transfer protocol.
|
boolean |
registerDataListener(long handle,
ISerialComDataListener dataListener)
This method associate a data looper with the given listener.
|
boolean |
registerLineEventListener(long handle,
ISerialComEventListener eventListener)
This method associate a event looper with the given listener.
|
boolean |
resumeListeningEvents(ISerialComEventListener eventListener)
Resume delivering events kept in queue to application.
|
boolean |
sendBreak(long handle,
int duration)
Assert a break condition on the specified port for the duration expressed in milliseconds.
|
boolean |
sendFile(long handle,
File[] fileToSend,
SerialComManager.FTPPROTO ftpProto,
SerialComManager.FTPVAR ftpVariant,
boolean textMode,
ISerialComFTPProgress progressListener,
SerialComFTPCMDAbort transferState)
Send given file(s) using specified file transfer protocol.
|
boolean |
setDTR(long handle,
boolean enabled)
This method assert/de-assert DTR line of serial port.
|
boolean |
setEventsMask(ISerialComEventListener eventListener,
int newMask)
Defines for which line events registered event listener will be called.
|
boolean |
setRTS(long handle,
boolean enabled)
This method assert/de-assert RTS line of serial port.
|
boolean |
unblockBlockingIOOperation(long context)
Unblocks any blocked operation if it exist.
|
boolean |
unregisterDataListener(long handle,
ISerialComDataListener dataListener)
This method destroys complete java and native looper subsystem associated with this particular data listener.
|
boolean |
unregisterLineEventListener(long handle,
ISerialComEventListener eventListener)
This method destroys complete java and native looper subsystem associated with this particular event listener.
|
int |
writeBytes(long handle,
byte[] buffer)
Utility method to call writeBytes without delay between successive bytes.
|
int |
writeBytes(long handle,
byte[] buffer,
int delay)
This method writes bytes from the specified byte type buffer.
|
int |
writeBytesBlocking(long handle,
byte[] buffer,
long context)
Write bytes from given buffer to the given handle in blocking mode.
|
int |
writeBytesDirect(long handle,
ByteBuffer buffer,
int offset,
int length)
Writes the bytes from the given direct byte buffer using facilities of the underlying JVM
and operating system.
|
int |
writeIntArray(long handle,
int[] buffer,
int delay,
SerialComManager.ENDIAN endianness,
SerialComManager.NUMOFBYTES numOfBytes)
This method send an array of integers on the specified port.
|
int |
writeSingleByte(long handle,
byte dataByte)
This method writes a single byte to the specified port.
|
int |
writeSingleInt(long handle,
int data,
int delay,
SerialComManager.ENDIAN endianness,
SerialComManager.NUMOFBYTES numOfBytes)
Different CPU and OS will have different endianness.
|
boolean |
writeString(long handle,
String data,
Charset charset,
int delay)
This method writes a string to the specified port.
|
boolean |
writeString(long handle,
String data,
int delay)
This method writes a string to the specified port.
|
public static final String JAVA_LIB_VERSION
Production release version of the SerialPundit.
public static final int DEFAULT_READBYTECOUNT
Default number of bytes (1024) to read from serial port.
public static final int CTS
Clear to send mask bit constant for UART control line. Integer constant with value 0x01.
public static final int DSR
Data set ready mask bit constant for UART control line. Integer constant with value 0x02.
public static final int DCD
Data carrier detect mask bit constant for UART control line. Integer constant with value 0x04.
public static final int RI
Ring indicator mask bit constant for UART control line. Integer constant with value 0x08.
public static final int LOOP
Loop indicator mask bit constant for UART control line. Integer constant with value 0x10.
public static final int RTS
Request to send mask bit constant for UART control line. Integer constant with value 0x20.
public static final int DTR
Data terminal ready mask bit constant for UART control line. Integer constant with value 0x40.
public static final int InputStream
The value indicating instance of SerialComInByteStream class is desired. Integer constant with value 0x32.
public static final int OutputStream
The value indicating instance of SerialComOutByteStream class is desired. Integer constant with value 0x33.
public static final String EXP_UNBLOCKIO
The exception message indicating that a blocked read method has been unblocked and made to return to caller explicitly (irrespective there was data to read or not).
public SerialComManager()
throws IOException
Allocates a new SerialComManager object. Identify operating system type, CPU architecture, prepares environment required for running this library, initiates extraction and loading of native libraries.
The native shared library will be extracted in folder named 'sp_tuartx1' inside system/user 'temp' folder or user home folder if access to 'temp' folder is denied.
On ARM Linux embedded platform it is possible to run entire 32 bit user space on a 64 bit ARMv8 processor. In such scenarios, the 32 bit and 64 bit shared libraries must not be mixed. Consider either full 32 bit user space root file system or entire root file system to be 64 bit.
Please contact author of this library if you want to use CPU optimized native shared libraries in your embedded product for achieving maximum performance.
IOException - if file operations on "/proc/cpuinfo" fails for Linux on ARM platform, if java system
properties can not be accessed, if file "/proc/cpuinfo" can not be found for Linux on ARM platform,
if native libraries are not found or can not be loaded/linked and initialized. If appropriate
files/directories can not be read or written.IllegalArgumentException - if directoryPath is null, directoryPath is empty, loadedLibName is null
or empty.public SerialComManager(String loadedLibName, String directoryPath, boolean createDirectory, boolean hotDeploy) throws IOException
Allocates a new SerialComManager object. Identify operating system type, CPU architecture, prepares environment required for running this library, initiates extraction and loading of native libraries.
By default native shared library will be extracted in temp folder. If this constructor is used then, It extracts native shared library in the folder specified by argument directoryPath and gives library name specified by loadedLibName. If the argument createDirectory is true, it will create directory (including parent if it does not exist) as specified by directoryPath, otherwise user should make sure that this directory exist before calling this constructor.
Two or more absolutely independent vendors may package this library into their product's jar file. Now when using default constructor both will extract and use the same folder and library name resulting in inconsistent software. This constructor handle this situation by providing vendor specific isolated environment.
This may also increase security as the folder may be given specific user permissions. To extract library in directory "/home/xxx/yyy", name it lib2 and create directory yyy an example is given below.
SerialComManager scm = new SerialComManager("lib2", "/home/xxx/yyy", true);loadedLibName - library name without extension (do not append .so, .dll or .dylib etc.).directoryPath - absolute path of directory to be used for purpose of extraction.createDirectory - true if directory is to be created otherwise false if given directory already exist.hotDeploy - true if hot deployment is to be supported otherwise false.IOException - if file operations on "/proc/cpuinfo" fails for Linux on ARM platform, if java system
properties can not be accessed, if file "/proc/cpuinfo" can not be found for Linux on ARM platform,
if native libraries are not found or can not be loaded/linked and initialized. If appropriate
files/directories can not be read or written.IllegalArgumentException - if directoryPath is null, directoryPath is empty, loadedLibName is null
or empty.public String getLibraryVersions() throws com.serialpundit.core.SerialComException
Gives library versions of java and native library implementations for serial port communication.
com.serialpundit.core.SerialComException - if native library version could not be determined.public String[] listAvailableComPorts() throws com.serialpundit.core.SerialComException
Returns all available UART style ports available on this system, otherwise an empty array of strings, if no serial style port is found in the system.
This should find regular UART ports, hardware/software virtual COM ports, port server, USB-UART converter, bluetooth/3G dongles, ports connected through USB hub/expander, serial card, serial controller, pseudo terminals, printers and virtual modems etc.
This method may be used to find valid serial ports for communications before opening them for writing more robust application.
Note : The BIOS may ignore UART ports on a PCI card and therefore BIOS settings has to be corrected if you modified default BIOS in OS.
com.serialpundit.core.SerialComException - if an I/O error occurs.public long openComPort(String portName, boolean enableRead, boolean enableWrite, boolean exclusiveOwnerShip) throws com.serialpundit.core.SerialComException
Opens a serial port for communication. If an attempt is made to open a port which is already opened, an exception will be thrown.
For Windows the exclusiveOwnerShip must be true as it does not allow sharing COM ports. An exception is thrown if exclusiveOwnerShip is set to false. For Solaris, exclusiveOwnerShip should be set to false as of now. On Unix-like system this method uses ioctl command TIOCEXCL for exclusive access. and not lock files
When the serial port is opened DTR and RTS lines will be raised by default by this library. Sometimes, DTR acts as a modem on-hook/off-hook control for other end. Modern modems are highly flexible in their dependency, working and configurations. It is best to consult modem manual. If the application design need DTR/RTS not to be asserted when port is opened custom drivers can be used or hardware can be modified for this purpose. Alternatively, if the application is to be run on Windows operating system only, then modifying INF file or registry key may help in not raising DTR/RTS when port is opened. Typically in Windows DTR/RTS is raised due to enumeration sequence (serenum).
In Unix jargon a dial-in TTY device is used for terminals, modems and printers etc. and requires DCD to be high for operation. When used with a modem, the port will wait for carrier before sending out the login prompt to end user. It is for this reason typically DTR of one end is connected to DSR of other end. When the terminal is turned off, any associated jobs are killed, and the user is logged out. Unlike dial-in the dial-out TTY device does not require DCD to be high. Once connection is made DCD may go high. Loss of the DCD signal may cause the jobs to be killed and the user will be automatically logged off.
This method is thread safe.
portName - name of the port to be opened for communication.enableRead - allows application to read bytes from this port.enableWrite - allows application to write bytes to this port.exclusiveOwnerShip - application wants to become exclusive owner of this port or not.IllegalStateException - if trying to become exclusive owner when port is already opened.IllegalArgumentException - if portName is null or invalid length, or if both enableRead and
enableWrite are set to false, if trying to open port in Windows without being exclusive owner.com.serialpundit.core.SerialComException - if the port can be opened for some reason.public boolean closeComPort(long handle)
throws com.serialpundit.core.SerialComException
Close the serial port. Application should unregister listeners if it has registered any before calling this method.
DTR line is dropped when port is closed.
If a blocking operation is in progress like readBytesBlocking() etc. than first such operation must be unblocked and then only closeComPort() should be called. It is invalid application design to violate this rule.
This method is thread safe.
handle - of the port to be closed.com.serialpundit.core.SerialComException - if invalid handle is passed or when it fails in closing the port.IllegalStateException - if application tries to close port while data/event listeners,
or input/output byte streams exist.public int writeBytes(long handle,
byte[] buffer,
int delay)
throws com.serialpundit.core.SerialComException
This method writes bytes from the specified byte type buffer. If the method returns false, the application should try to re-send bytes. The data has been transmitted out of serial port when this method returns.
If large amount of data need to be written, it is advisable to break it into chunks of data of size for example 2KB each.
It should be noted that on Linux system reading from the terminal after a disconnect causes an end-of-file condition, and writing causes an EIO error to be returned. The terminal device must be closed and reopened to clear the condition.
handle - handle of the opened port on which to write bytes.buffer - byte type buffer containing bytes to be written to port.delay - time gap (in milliseconds) between transmitting two successive bytes.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if buffer is null or delay is negative.public int writeBytes(long handle,
byte[] buffer)
throws com.serialpundit.core.SerialComException
Utility method to call writeBytes without delay between successive bytes.
The writeBytes(handle, buffer) method for class SerialComManager has the same effect as:
writeBytes(handle, buffer, 0)
handle - handle of the opened port on which to write bytes.buffer - byte type buffer containing bytes to be written to port.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if buffer is null.public int writeSingleByte(long handle,
byte dataByte)
throws com.serialpundit.core.SerialComException
This method writes a single byte to the specified port. The data has been transmitted out of serial port when this method returns.
handle - handle of the opened port on which to write byte.dataByte - byte to be written to port.com.serialpundit.core.SerialComException - if an I/O error occurs.public boolean writeString(long handle,
String data,
int delay)
throws com.serialpundit.core.SerialComException
This method writes a string to the specified port. The library internally converts string to byte buffer. The data has been transmitted out of serial port when this method returns.
handle - handle of the opened port on which to write byte.data - the string to be send to port.delay - interval between two successive bytes while sending string.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if data is null or empty string.public boolean writeString(long handle,
String data,
Charset charset,
int delay)
throws UnsupportedEncodingException,
com.serialpundit.core.SerialComException
This method writes a string to the specified port. The library internally converts string to byte buffer. The data has been transmitted out of serial port when this method returns.
handle - handle of the opened port on which to write byte.data - the string to be send to port.charset - the character set into which given string will be encoded.delay - time gap between transmitting two successive bytes in this string.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if data is null or empty string.UnsupportedEncodingException - if string encoding/decoding fails.public int writeSingleInt(long handle,
int data,
int delay,
SerialComManager.ENDIAN endianness,
SerialComManager.NUMOFBYTES numOfBytes)
throws com.serialpundit.core.SerialComException
Different CPU and OS will have different endianness. It is therefore we handle the endianness conversion as per the requirement. If the given integer is in range −32,768 to 32,767, only two bytes will be needed. In such case we might like to send only 2 bytes to serial port. On the other hand application might be implementing some custom protocol so that the data must be 4 bytes (irrespective of its range) in order to be interpreted correctly by the receiver terminal. This method assumes that integer value can be represented by 32 or less number of bits. On x86_64 architecture, loss of precision will occur if the integer value is of more than 32 bit.
The data has been transmitted physically out of serial port when this method returns.
In java numbers are represented in 2's complement, so number 650 whose binary representation is 0000001010001010 is printed byte by byte, then will be printed as 1 and -118, because 10001010 in 2's complement is negative number.
handle - handle of the opened port on which to write byte.data - an integer number to be sent to port.delay - interval between two successive bytes .endianness - big or little endian sequence to be followed while sending bytes representing
this integer.numOfBytes - number of bytes this integer can be represented in.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if endianness or numOfBytes is null.public int writeIntArray(long handle,
int[] buffer,
int delay,
SerialComManager.ENDIAN endianness,
SerialComManager.NUMOFBYTES numOfBytes)
throws com.serialpundit.core.SerialComException
This method send an array of integers on the specified port. The data has been transmitted out of serial port when this method returns.
handle - handle of the opened port on which to write byte.buffer - an array of integers to be sent to port.delay - interval between two successive bytes .endianness - big or little endian sequence to be followed while sending bytes representing
this integer.numOfBytes - number of bytes this integer can be represented in.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if endianness or numOfBytes is null.public int writeBytesDirect(long handle,
ByteBuffer buffer,
int offset,
int length)
throws com.serialpundit.core.SerialComException
Writes the bytes from the given direct byte buffer using facilities of the underlying JVM and operating system. When this method returns data would have sent out of serial port physically.
Consider using this method when developing applications based on Bluetooth serial port profile or applications like printing document using printer.
This method does not modify the direct byte buffer attributes position, capacity, limit and mark. The application design is expected to take care of this as and when required in appropriate manner. Further, this method does not consume or modify the data in the given buffer.
handle - handle of the serial port on which to write bytes.buffer - direct byte buffer containing bytes to be written to port.offset - location from where to start sending data out of serial port.length - number of bytes from offset to sent to serial port.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if buffer is null, or if position or limit is negative,
or if given buffer is not direct byte buffer, or if length > (buffer.capacity() - offset).public int writeBytesBlocking(long handle,
byte[] buffer,
long context)
throws com.serialpundit.core.SerialComException
Write bytes from given buffer to the given handle in blocking mode.
Same context should not be used for both reading and writing.
handle - handle of the opened port on which to write bytes.buffer - byte type buffer containing bytes to be written to port.context - context value obtained form call to createBlockingIOContext method.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if buffer is null.public int readBytesDirect(long handle,
ByteBuffer buffer,
int offset,
int length)
throws com.serialpundit.core.SerialComException
Reads the bytes from the serial port into the given direct byte buffer using facilities of the underlying JVM and operating system.
This method does not modify the direct byte buffer attributes position, capacity, limit and mark. The application design is expected to take care of this as and when required in appropriate manner.
handle - handle of the serial port from which to read data bytes.buffer - direct byte buffer into which data bytes will be placed.offset - location in byte buffer from which to start saving data.length - number of bytes from offset to read in buffer.com.serialpundit.core.SerialComException - if an I/O error occurs.IllegalArgumentException - if buffer is null, or if position or limit is negative, or if
given buffer is not direct byte buffer.public long createBlockingIOContext()
throws com.serialpundit.core.SerialComException
Prepares a context that should be passed to readBytesBlocking, writeBytesBlocking, readBytes, unblockBlockingIOOperation and destroyBlockingIOContext methods.
com.serialpundit.core.SerialComException - if an I/O error occurs.public boolean unblockBlockingIOOperation(long context)
throws com.serialpundit.core.SerialComException
Unblocks any blocked operation if it exist. This causes closing of serial port possible gracefully and return the worker thread that called blocking read/write to return and proceed as per application design.
context - context obtained from call to createBlockingIOContext method for blocking
I/O operations.com.serialpundit.core.SerialComException - if an I/O error occurs.public boolean destroyBlockingIOContext(long context)
throws com.serialpundit.core.SerialComException
Destroys the context that was created by a call to createBlockingIOContext method for blocking I/O operations uses.
context - context obtained from call to createBlockingIOContext method for blocking
I/O operations.com.serialpundit.core.SerialComException - if an I/O error occurs.public byte[] readBytesBlocking(long handle,
int byteCount,
long context)
throws com.serialpundit.core.SerialComException
Read specified number of bytes from given serial port and stay blocked till bytes arrive at serial port.
1. If data is read from serial port, array of bytes containing data is returned.
2. If there was no data in serial port to read, null is returned. Note that this case is not possible however for blocking read call.
When no data at serial port has arrived and application wishes to unblock and return the control to the caller for example because application now wants to close the serial port, it should call unblockBlockingIOOperation() passing the same context to this method.
handle - of the serial port from which to read bytes.byteCount - number of bytes to read from serial port.context - context obtained by a call to createBlockingIOContext method.com.serialpundit.core.SerialComException - if an I/O error occurs or if byteCount is greater than 2048.public byte[] readBytes(long handle,
int byteCount)
throws com.serialpundit.core.SerialComException
Read specified number of data bytes from the given serial port.
If there was no data at serial port to read, null is returned.
handle - of the serial port from which to read bytes.byteCount - number of bytes to read from serial port.com.serialpundit.core.SerialComException - if an I/O error occurs or if byteCount is greater than 2048.public byte[] readBytes(long handle)
throws com.serialpundit.core.SerialComException
If user does not specify any count, library try to read DEFAULT_READBYTECOUNT (1024 bytes) bytes as default value.
It has same effect as readBytes(handle, 1024)
handle - of the port from which to read bytes.com.serialpundit.core.SerialComException - if an I/O error occurs.public String readString(long handle, int byteCount) throws com.serialpundit.core.SerialComException
Reads data from serial port and converts it into string.
It constructs a new string by decoding the specified array of bytes using the platform's default character set. The length of the new string is a function of the character set, and hence may not be equal to the length of the byte array read from serial port.
handle - of port from which to read bytes.byteCount - number of bytes to read from this port.com.serialpundit.core.SerialComException - if an I/O error occurs or if byteCount is greater than 2048.public String readString(long handle) throws com.serialpundit.core.SerialComException
This method reads data from serial port and converts it into string.
It Constructs a new string by decoding the specified array of bytes using the platform's default character set. The length of the new string is a function of the charset, and hence may not be equal to the length of the byte array read from serial port.
Note that the length of data bytes read using this method can not be greater than DEFAULT_READBYTECOUNT i.e. 1024.
handle - of the port from which to read bytes.com.serialpundit.core.SerialComException - if an I/O error occurs.public byte[] readSingleByte(long handle)
throws com.serialpundit.core.SerialComException
This is a utility method to read a single byte from serial port.
Its effect is same as readBytes(handle, 1)
handle - of the port from which to read byte.com.serialpundit.core.SerialComException - if an I/O error occurs.public int readBytes(long handle,
byte[] buffer,
int offset,
int length,
long context,
SerialComLineErrors lineErr)
throws com.serialpundit.core.SerialComException
Reads data bytes from serial port into given buffer also providing info about framing, parity etc errors. This method may be used in application design which needs to poll serial port continuously for presence of data.
When no data at serial port has arrived and application wishes to unblock and return the control to the caller for example because application now wants to close the serial port, it should call unblockBlockingIOOperation() passing the same context which is passed to this method.
To find if a framing or parity errors has happened while receiving data or not, call methods as appropriate on lineErr reference.
handle - of the port from which to read data bytes.buffer - data byte buffer in which bytes from serial port will be saved.offset - index in given byte array at which first data byte will be placed.length - number of bytes to read into given buffer (0 <= length <= 2048).context - context obtained by call to createBlockingIOContext method for blocking behavior
or -1 for non-blocking behavior.lineErr - instance of class SerialComLineErrors that will carry line error information or null
if parity/framing errors should not be checked.com.serialpundit.core.SerialComException - if an I/O error occurs.NullPointerException - if buffer is null.IndexOutOfBoundsException - if offset is negative, length is negative, or length is
greater than buffer.length - offset.public boolean configureComPortData(long handle,
SerialComManager.DATABITS dataBits,
SerialComManager.STOPBITS stopBits,
SerialComManager.PARITY parity,
SerialComManager.BAUDRATE baudRate,
int custBaud)
throws com.serialpundit.core.SerialComException
This method configures the rate at which communication will occur and the format of UART frame. This method must be called before configureComPortControl method.
[1] Most of the DTE/DCE (hardware) does not support different baud rates for transmission and reception and therefore this method takes only single value applicable to both transmission and reception.
If parity is enabled, the parity bit will be removed from UART frame before passing it to this library. All hardware/driver/operating systems does not support all parity. Please check your manual. Note that the datasheet of some uart devices does not mention that mark/space parity is supported, however they properly support it as mentioned in their register setting details. If a parity error is detected in received data, the error is not cleared until LSR/LCR registers are read by driver. So if parity detection is used application should enquire its status.
handle - of opened port to which this configuration applies to.dataBits - number of data bits in one frame (refer DATABITS enum in SerialComManager class for this).stopBits - number of stop bits in one frame (refer STOPBITS enum in SerialComManager class for this).parity - of the frame (refer PARITY enum in SerialComManager class for this).baudRate - of the frame (refer BAUDRATE enum in SerialComManager class for this).custBaud - custom baudrate if the desired rate is not included in BAUDRATE enum.com.serialpundit.core.SerialComException - if invalid handle is passed or an error occurs in configuring the port.IllegalArgumentException - if dataBits or stopBits or parity or baudRate is null, or if custBaud is zero or negative.public boolean configureComPortControl(long handle,
SerialComManager.FLOWCONTROL flowctrl,
char xon,
char xoff,
boolean ParFraError,
boolean overFlowErr)
throws com.serialpundit.core.SerialComException
This method configures the way data communication will be controlled between DTE and DCE. This specifies flow control and actions that will be taken when an error is encountered in communication.
It is advisable not to use same XON and XOFF character as opertaing system framework or driver may check for special characters one after the other and will process them. For example while processing data received at serial port, if driver sees XON it will instruct device to start transmission. But when moving further in the processing function, it checks for XOFF and sees that XOFF character has been received and therefore it will stop the transmission.
handle - of opened port to which need to be configured.flowctrl - flow control, how data flow will be controlled (refer FLOWCONTROL enum for this).xon - character representing on condition if software flow control is used.xoff - character representing off condition if software flow control is used.ParFraError - true if parity and frame errors are to be checked false otherwise.overFlowErr - true if overflow error is to be detected false otherwise.com.serialpundit.core.SerialComException - if invalid handle is passed or an error occurs in configuring the port.IllegalArgumentException - if flowctrl is null.public String[] getCurrentConfiguration(long handle) throws com.serialpundit.core.SerialComException
This method gives currently applicable settings associated with particular serial port. The values are bit mask so that application can manipulate them to get required information.
For Unix-like OS the order is : c_iflag, c_oflag, c_cflag, c_lflag, c_line, c_cc[0], c_cc[1], c_cc[2], c_cc[3] c_cc[4], c_cc[5], c_cc[6], c_cc[7], c_cc[8], c_cc[9], c_cc[10], c_cc[11], c_cc[12], c_cc[13], c_cc[14], c_cc[15], c_cc[16], c_ispeed and c_ospeed.
For Windows OS the order is :DCBlength, BaudRate, fBinary, fParity, fOutxCtsFlow, fOutxDsrFlow, fDtrControl, fDsrSensitivity, fTXContinueOnXoff, fOutX, fInX, fErrorChar, fNull, fRtsControl, fAbortOnError, fDummy2, wReserved, XonLim, XoffLim, ByteSize, Parity, StopBits, XonChar, XoffChar, ErrorChar, StopBits, EvtChar, wReserved1.
handle - of the opened port.com.serialpundit.core.SerialComException - if invalid handle is passed or an error occurs while reading current settings.public boolean setRTS(long handle,
boolean enabled)
throws com.serialpundit.core.SerialComException
This method assert/de-assert RTS line of serial port. Set "true" for asserting signal, false otherwise. This changes the state of RTS line electrically.
The RS-232 standard defines the voltage levels that correspond to logical one and logical zero levels for the data transmission and the control signal lines. Valid signals are either in the range of +3 to +15 volts or the range −3 to −15 volts with respect to the ground/common pin; consequently, the range between −3 to +3 volts is not a valid RS-232 level.
On some hardware IC, signals may be active low and therefore for actual voltage datasheet should be consulted. Also please check if the driver supports setting RTS/DTR lines or not.
handle - of the opened port.enabled - if true RTS will be asserted and vice-versa.com.serialpundit.core.SerialComException - if system is unable to complete requested operation.public boolean setDTR(long handle,
boolean enabled)
throws com.serialpundit.core.SerialComException
This method assert/de-assert DTR line of serial port. Set "true" for asserting signal, false otherwise. This changes the state of RTS line electrically.
It is possible to establish PPP connections to transmit binary data over a two (or more) wire interface with full handshaking and modem control signaling if the driver is configured for this. Refer application note from FTDI for details : AN232B-09 Using the Modem Emulation Mode in FTDI's VCP Driver.
handle - of the opened port.enabled - if true DTR will be asserted and vice-versa.com.serialpundit.core.SerialComException - if system is unable to complete requested operation.public boolean registerDataListener(long handle,
ISerialComDataListener dataListener)
throws com.serialpundit.core.SerialComException
This method associate a data looper with the given listener. This looper will keep delivering new data whenever it is made available from native data collection and dispatching subsystem. Note that listener will start receiving new data, even before this method returns.
Application (listener) should implement ISerialComDataListener and override onNewSerialDataAvailable method.
The SerialPundit can manage upto 1024 listeners corresponding to 1024 port handles. Application should not register data listener more than once for the same port otherwise it will lead to inconsistent state.
This method is thread safe.
handle - of the serial port for which given listener will listen for availability of data bytes.dataListener - instance of class which implements ISerialComDataListener interface.com.serialpundit.core.SerialComException - if invalid handle passed, handle is null or data listener already exist for this handle.IllegalArgumentException - if dataListener is null.public boolean unregisterDataListener(long handle,
ISerialComDataListener dataListener)
throws com.serialpundit.core.SerialComException
This method destroys complete java and native looper subsystem associated with this particular data listener. This has no effect on event looper subsystem. This method returns only after native thread has been terminated successfully.
This method is thread safe.
handle - handle of the serial port for which this data listener was registered.dataListener - instance of class which implemented ISerialComDataListener interface.com.serialpundit.core.SerialComException - if null value is passed in dataListener field.IllegalArgumentException - if dataListener is null.public boolean registerLineEventListener(long handle,
ISerialComEventListener eventListener)
throws com.serialpundit.core.SerialComException
This method associate a event looper with the given listener. This looper will keep delivering new event whenever it is made available from native event collection and dispatching subsystem.
Application (listener) should implement ISerialComEventListener and override onNewSerialEvent method.
By default all four events are dispatched to listener. However, application can mask events through setEventsMask() method. In current implementation, native code sends all the events irrespective of mask and we actually filter them in java layers, to decide whether this should be sent to application or not (as per the mask set by setEventsMask() method).
Before calling this method, make sure that port has been configured for hardware flow control using configureComPortControl method. Application should not register event listener more than once for the same port otherwise it will lead to inconsistent state.
This method is thread safe.
handle - of the port opened.eventListener - instance of class which implements ISerialComEventListener interface.com.serialpundit.core.SerialComException - if invalid handle passed, handle is null or event listener already exist for this handle.IllegalArgumentException - if eventListener is null.public boolean unregisterLineEventListener(long handle,
ISerialComEventListener eventListener)
throws com.serialpundit.core.SerialComException
This method destroys complete java and native looper subsystem associated with this particular event listener. This has no effect on data looper subsystem.
This method is thread safe.
handle - handle for which this listener was registered.eventListener - instance of class which implemented ISerialComEventListener interface.com.serialpundit.core.SerialComException - if an error occurs.IllegalArgumentException - if eventListener is null.public boolean pauseListeningEvents(ISerialComEventListener eventListener) throws com.serialpundit.core.SerialComException
This pauses delivering events to application. The events kept accumulating in queue.
eventListener - instance of class which implemented ISerialComEventListener interface.com.serialpundit.core.SerialComException - if null is passed for eventListener field.IllegalArgumentException - if eventListener is null.public boolean resumeListeningEvents(ISerialComEventListener eventListener) throws com.serialpundit.core.SerialComException
Resume delivering events kept in queue to application.
eventListener - is an instance of class which implements ISerialComEventListener.com.serialpundit.core.SerialComException - if error occurs.IllegalArgumentException - if eventListener is null.public boolean fineTuneReadBehaviour(long handle,
int vmin,
int vtime,
int rit,
int rttm,
int rttc)
throws com.serialpundit.core.SerialComException
This method gives more fine tune control to application for tuning performance and behavior of read operations to leverage OS specific facility for read operation. The read operations can be optimized for receiving for example high volume data speedily or low volume data but received in burst mode.
If more than one client has opened the same port, then all the clients will be affected by new settings. When this method is called application should make sure that previous read or write operation is not in progress.
Under multithreading scenarios, if thread is blocked on read method due to timeout configured using this method and other thread tries to close port, the read method may cause the the thread which called read methid not to return. It is therefore either timeout should be kept short or two threads must be synchronized etc.
[1] Time out for read call for unix like OS can be set using vtime. Use formula vtime = time out in milliseconds / 100. For example to wait for 100 milliseconds, vtime = 1 and vmin = 0.
handle - of the opened port.vmin - c_cc[VMIN] field of termios structure (applicable for unix like OS only).vtime - c_cc[VTIME] field of termios structure (10th of a second, applicable for unix like OS only).rit - ReadIntervalTimeout field of COMMTIMEOUTS structure (applicable for windows OS only).rttm - ReadTotalTimeoutMultiplier field of COMMTIMEOUTS structure (applicable for windows OS only).rttc - ReadTotalTimeoutConstant field of COMMTIMEOUTS structure (applicable for windows OS only).com.serialpundit.core.SerialComException - if wrong handle is passed or operation can not be done successfully.IllegalArgumentException - if invalid combination of arguments is passed.public boolean setEventsMask(ISerialComEventListener eventListener, int newMask) throws com.serialpundit.core.SerialComException
Defines for which line events registered event listener will be called.
In future we may shift modifying mask in the native code itself, so as to prevent JNI transitions. This filters what events should be sent to application. Note that, although we sent only those event for which user has set mask, however native code send all the events to java layer as of now.
eventListener - instance of class which implemented ISerialComEventListener interface.com.serialpundit.core.SerialComException - if invalid listener is passed.IllegalArgumentException - if eventListener is null.public int getEventsMask(ISerialComEventListener eventListener) throws com.serialpundit.core.SerialComException
This method return currently applicable mask for events on serial port.
eventListener - instance of class which implemented ISerialComEventListener interface.com.serialpundit.core.SerialComException - if null or wrong listener is passed.IllegalArgumentException - if eventListener is null.public boolean clearPortIOBuffers(long handle,
boolean clearRxBuffer,
boolean clearTxBuffer)
throws com.serialpundit.core.SerialComException
Discards data sent to port but not transmitted, or data received but not read. Some device/OS/driver might not have support for this, but most of them may have. If there is some data to be pending for transmission, it will be discarded and therefore no longer sent. If the application wants to make sure that all data has been transmitted before discarding anything, it must first flush data and then call this method.
handle - of the opened port.clearRxBuffer - if true receive buffer will be cleared otherwise will be left untouched.clearTxBuffer - if true transmit buffer will be cleared otherwise will be left untouched.com.serialpundit.core.SerialComException - if invalid handle is passed or operation can not be completed successfully.IllegalArgumentException - if both purgeTxBuffer and purgeRxBuffer are false.public boolean sendBreak(long handle,
int duration)
throws com.serialpundit.core.SerialComException
Assert a break condition on the specified port for the duration expressed in milliseconds. If the line is held in the logic low condition (space in UART jargon) for longer than a character time, this is a break condition that can be detected by the UART.
Recognizing break condition on line is the responsibility of the UART IC, but if for some reason (such as a limited UART that does not implement this functionality) the UART fails to do so, reception of a break will manifest itself as a large number of framing errors. Also sometimes default drivers built into operating system may not provide break detection facility.
All UART devices (or driver) may not support all break timings. For example CP2105 can set break for from 1 to 125 ms or for infinite time. Developers should consult data sheet to know device capabilities. Sometimes hardware may also report break as all 0 bits byte data.
Dedicated ICs like ELM627 can be used to detect break condition and toggle GPIO lines which may in turn be connected to reset pin of micro-controller. Such schemes are used where the hardware can not detect break condition on line.
handle - of the opened serial port.duration - the time in milliseconds for which break will be active.com.serialpundit.core.SerialComException - if invalid handle is passed or operation can not be successfully completed.IllegalArgumentException - if duration is negative.public int[] getInterruptCount(long handle)
throws com.serialpundit.core.SerialComException
This method gives the number of interrupts on serial line that have occurred. The interrupt count is in following order in array beginning from index 0 and ending at index 11 : CTS, DSR, RING, CARRIER DETECT, RECEIVER BUFFER, TRANSMIT BUFFER, FRAME ERROR, OVERRUN ERROR, PARITY ERROR, BREAK AND BUFFER OVERRUN.
This is applicable for Linux onle. For other operating systems, this will return 0 for all the indexes.
handle - of the port opened on which interrupts might have occurred.com.serialpundit.core.SerialComException - if invalid handle is passed or operation can not be performed successfully.public int[] getLinesStatus(long handle)
throws com.serialpundit.core.SerialComException
Gives status of serial port's control lines as supported by underlying operating system. The sequence of status in returned array is :
Linux OS : CTS, DSR, DCD, RI, LOOP, RTS, DTR respectively.
MAC OS X : CTS, DSR, DCD, RI, 0, RTS, DTR respectively.
Windows OS : CTS, DSR, DCD, RI, 0, 0, 0 respectively.
handle - of the port whose status is to be read.com.serialpundit.core.SerialComException - if invalid handle is passed or operation can not be completed successfully.public String findDriverServingComPort(String comPortName) throws com.serialpundit.core.SerialComException
Gives the name of the driver who is driving the given serial port. The use case scenarios are:
If exactly same usb-uart devices are used to connected two sensors then use findComPortFromUSBAttributes API in USB module giving unique serial numbers of ft232. This will tell which device node belongs to which sensor.
This can also be used where two end products based on same usb-uart converter are connected to the compueter and they use different drivers.
comPortName - name only for windows (for ex; COM52), full path for unix-like os (for ex; /dev/ttyUSB0).com.serialpundit.core.SerialComException - if operation can not be completed successfully.IllegalArgumentException - if argument comPortName is null or is an empty string.public String findIRQnumberForComPort(long handle) throws com.serialpundit.core.SerialComException
Gives the address and IRQ number associated with the given serial port. Applicable manily for serial port built into the mother board itself.
handle - handle of the opened serial port.com.serialpundit.core.SerialComException - if operation can not be completed successfully.public int[] getByteCountInPortIOBuffer(long handle)
throws com.serialpundit.core.SerialComException
Get number of bytes in input and output port buffers used by operating system for instance tty buffers in Unix like systems. Sequence of data in array is : Input buffer byte count, Output buffer byte count.
It should be noted that some chipset specially USB to UART converters might have FIFO buffers in chipset itself. For example FT232R has internal buffers controlled by FIFO CONTROLLERS. For this reason this method should be tested carefully if application is using USB-UART converters. This is driver and OS specific scenario.
handle - of the opened port for which counts need to be determined.com.serialpundit.core.SerialComException - if invalid handle is passed or operation can not be completed successfully.public String getPortName(long handle) throws com.serialpundit.core.SerialComException
This method gives the port name with which given handle is associated. If the given handle is unknown to this library, null is returned. A serial port is known to this if it was opened using SerialComManager's openComPort() method.
handle - for which the port name is to be found.com.serialpundit.core.SerialComException - if invalid handle is passed.public boolean sendFile(long handle,
File[] fileToSend,
SerialComManager.FTPPROTO ftpProto,
SerialComManager.FTPVAR ftpVariant,
boolean textMode,
ISerialComFTPProgress progressListener,
SerialComFTPCMDAbort transferState)
throws IOException
Send given file(s) using specified file transfer protocol.
For Xmodem trasnfer the element at 0th index of fileToSend array must represent a regular file. If the length of fileToSend array is more than one, only 1st file will be sent.
For Ymodem transfer, the fileToSend array should contain all the files to be transffered to receiver end where all the elements in fileToSend array represent regular files.
Xmodem protocol is widely used for flashing executable images in microcontroller via UART. For example the secondary bootloader in LPC2000 can update the user application code in on chip flash via UART with 1K XMODEM protocol. Xmodem protocol is also used for taling to network routers.
If you want to make user defined firmware, consider creating an IDE where end user can place widget, define layout etc. graphically and then when he clicks on save button a firmware hex file gets generated. This file is then flashed into end product as firmware.
handle - of the port on which file is to be sent.fileToSend - File instance representing file to be sent.ftpProto - file transfer protocol to use for communication over serial port.ftpVariant - variant of file transfer protocol to use.textMode - if true file will be sent as text file (ASCII mode), if false file will be sent as
binary file. The text file must contain only valid ASCII characters.progressListener - object of class which implements ISerialComXmodemProgress interface and is
interested in knowing how many blocks have been sent to file receiver till now. If progressListener
is null, update will not be delivered to application.transferState - if application wish to abort sending file at instant of time due to any reason, it can
call abortTransfer method on this object. If the application does not wishes to abort sending file
explicitly transferState can be null.com.serialpundit.core.SerialComException - if invalid handle is passed, if receiver sent abort command.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String)
method denies read access to the file.FileNotFoundException - if the file does not exist, is a directory rather than a regular file, or
for some other reason cannot be opened for reading.SerialComTimeOutException - if timeout occurs as per file transfer protocol.IOException - if error occurs while reading data from file to be sent.IllegalArgumentException - if fileToSend or ftpProto or ftpVariant or ftpMode argument is null.public boolean receiveFile(long handle,
File fileToReceive,
SerialComManager.FTPPROTO ftpProto,
SerialComManager.FTPVAR ftpVariant,
boolean textMode,
ISerialComFTPProgress progressListener,
SerialComFTPCMDAbort transferState)
throws IOException
Receives file using specified file transfer protocol.
For Xmodem transfer the fileToReceive must represent a regular file. For Ymodem transfer fileToReceive must represent a directory in which received files will be saved.
handle - of the serial port on which file is to be sent.fileToReceive - File instance representing file/folder to be sent.ftpProto - file transfer protocol (FTPPROTO_XXX) to use for communication over serial port.ftpVariant - variant of file transfer protocol (FTPVAR_XXX) to use.textMode - if true file will be received as text file (ASCII mode), if false file will be received
as binary file.progressListener - object of class which implements ISerialComXmodemProgress interface and is interested
in knowing how many blocks have been received from file sender till now. If progressListener is null,
update will not be delivered to application.transferState - if application wish to abort receiving file at instant of time due to any reason, it can
call abortTransfer method on this object. If the application does not wishes to abort receiving file
explicitly transferState can be null.com.serialpundit.core.SerialComException - if invalid handle is passed, if sender sent abort command.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method
denies read access to the file.FileNotFoundException - if the file does not exist, is a directory rather than a regular file, or for some
other reason cannot be opened for reading.SerialComTimeOutException - if timeout occurs as per file transfer protocol.IOException - if error occurs while reading data from file to be sent.IllegalArgumentException - if fileToReceive or ftpProto or ftpVariant or ftpMode argument is null.public ISerialIOStream getIOStreamInstance(int streamType, long handle, SerialComManager.SMODE streamMode) throws com.serialpundit.core.SerialComException
Factory method to create stream of type specified by streamType in blocking or non-blocking mode.
If streamType is SerialComManager.OutputStream, an instance of class SerialComOutByteStream is returned. If streamType is SerialComManager.InputStream, an instance of class SerialComInByteStream is returned.
If streamMode is SMODE.NONBLOCKING, read/write to serial port is non-blocking. If streamMode is SMODE.BLOCKING, read/write to serial port is blocking.
streamType - one of the values; SerialComManager.OutputStream or SerialComManager.InputStream.handle - handle of the opened serial port which this stream will wrap internally.streamMode - enum value SMODE.BLOCKING or SMODE.NONBLOCKING.com.serialpundit.core.SerialComException - if input stream already exist for this handle or invalid handle is passed.IllegalArgumentException - if streamMode is null or invalid streamType is passed.public SerialComVendorLib getVendorLibFromFactory(int vendorLibIdentifier, String libDirectory, String vlibName) throws IOException
Gives an instance of the class which implements API defined by vendor in their propriety library.
For example; if vendorLibIdentifier is SerialComVendorLib.VLIB_FTDI_D2XX, an instance of SerialComFTDID2XX class is returned.
vendorLibIdentifier - one of the constant VLIB_XXXX_XXXX in SerialComVendorLib class.libDirectory - absolute directory path where vendor library is placed.vlibName - full name of the vendor library (for ex. libftd2xx.so.1.1.12).IOException - if java system properties can not be accessed, if invalid vendorLibIdentifier is passed.
if native libraries are not found or can not be loaded/linked, if libDirectory does not exist, or is not
a regular directory or is not writtable, If native library can not be initialized.IllegalArgumentException - if vlibName is null or empty string.public SerialComPortMapper getSerialComPortMapperInstance(String directoryPath, String loadedLibName) throws com.serialpundit.core.SerialComException
Allocate, initialize and return an instance of SerialComPortMapper class on whom APIs can be called to map or unmap a serial port alias.
This method will extract native library in directory as specified by directoryPath argument or default directory will be used if directoryPath is null. The native library loaded will be given name as specified by loadedLibName argument or default name will be used if loadedLibName is null.
directoryPath - absolute path of directory to be used for extraction.loadedLibName - library name without extension (do not append .so, .dll or .dylib etc.).IOException - if file operations on "/proc/cpuinfo" fails for Linux on ARM platform, if java system
properties can not be accessed, if file "/proc/cpuinfo" can not be found for Linux on ARM platform,
if native libraries are not found or can not be loaded/linked. If appropriate files/directories can
not be read or written, If native library can not be initialized.IllegalArgumentException - if directoryPath is null, directoryPath is empty, loadedLibName is null
or empty.com.serialpundit.core.SerialComExceptionpublic SerialComDBRelease getSerialComDBReleaseInstance(String directoryPath, String loadedLibName) throws IOException
Allocate, initialize and return an instance of SerialComDBRelease class on whom APIs can be called to release COM ports in use. This methed is applicable for Windows operating system only.
The Windows operating system maintains a database of all COM ports. This database is typically supports com port numbers from 1(COM1) to 256(COM256). This database can get exhausted for example if more than 256 USB-UART devices are connected one after the other in system. This generally happens in factory testing environment. Using the APIs in SerialComDBRelease class, test application can manage the port assignment and its release programatically making production testing faster and less cumbersome.
This method will extract native library in directory as specified by directoryPath argument or default directory will be used if directoryPath is null. The native library loaded will be given name as specified by loadedLibName argument or default name will be used if loadedLibName is null.
directoryPath - absolute path of directory to be used for extraction.loadedLibName - library name without extension (do not append .so, .dll or .dylib etc.).IOException - if file operations on "/proc/cpuinfo" fails for Linux on ARM platform, if java system
properties can not be accessed, if file "/proc/cpuinfo" can not be found for Linux on ARM platform,
if native libraries are not found or can not be loaded/linked. If appropriate files/directories can
not be read or written, If native library can not be initialized.IllegalArgumentException - if directoryPath is null, directoryPath is empty, loadedLibName is null
or empty.public SerialComNullModem getSerialComNullModemInstance() throws IOException
Provides an instance of SerialComNullModem class for managing virtual serial device, null modem, loop back and custom pinout connected virtual serial devices.
IOException - if any error occurs while handling null modem driver specific files.Copyright © 2017. All rights reserved.