public final class SerialComLooper extends Object
Encapsulates environment for data and event looper implementation. This runs in as a different thread context and keep looping over data/event queue, delivering data/events to the intended registered listener (data/event handler) one by one.
The rate of delivery of data/events are directly proportional to how fast listener finishes his job and let us return.
| Constructor and Description |
|---|
SerialComLooper(SerialComPortJNIBridge mComPortJNIBridge)
Allocates a new SerialComLooper object.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getEventsMask()
Gives the event mask currently active.
|
void |
insertInDataErrorQueue(int errorNum)
This method insert error info in error queue which will be later delivered to application.
|
void |
insertInDataQueue(byte[] newData)
This method is called from native code to pass data bytes.
|
void |
insertInEventQueue(int newEvent)
Native side detects the change in status of lines, get the new line status and call this method.
|
void |
pause()
Data looper thread refrains from sending new data to the data listener.
|
void |
resume()
Looper starts sending new data again to the data listener.
|
void |
setEventsMask(int newMask)
In future we may shift modifying mask in the native code itself, so as to prevent JNI transitions.
|
void |
startDataLooper(long handle,
ISerialComDataListener dataListener,
String portName)
Start the thread to loop over data queue.
|
void |
startEventLooper(long handle,
ISerialComEventListener eventListener,
String portName)
Get initial status of control lines and start Java worker thread.
|
void |
stopDataLooper()
Set the flag to indicate that the thread is supposed to run to completion and exit.
|
void |
stopEventLooper()
Set the flag to indicate that the thread is supposed to run to completion and exit.
|
public SerialComLooper(SerialComPortJNIBridge mComPortJNIBridge)
Allocates a new SerialComLooper object.
mComPortJNIBridge - interface used to invoke appropriate native function.public void insertInDataQueue(byte[] newData)
This method is called from native code to pass data bytes.
newData - byte array containing data read from serial portpublic void insertInDataErrorQueue(int errorNum)
This method insert error info in error queue which will be later delivered to application.
errorNum - operating system specific error number to be sent to application.public void insertInEventQueue(int newEvent)
Native side detects the change in status of lines, get the new line status and call this method. Based on the mask this method determines whether this event should be sent to application or not.
newEvent - bit mask representing event on serial port control lines.public void startDataLooper(long handle,
ISerialComDataListener dataListener,
String portName)
Start the thread to loop over data queue.
handle - handle of the opened port for which data looper need to be started.dataListener - listener to which data will be delivered.portName - name of port represented by this handle.public void stopDataLooper()
Set the flag to indicate that the thread is supposed to run to completion and exit. Interrupt the thread so that take() method can come out of blocked sleep state.
public void startEventLooper(long handle,
ISerialComEventListener eventListener,
String portName)
throws com.serialpundit.core.SerialComException
Get initial status of control lines and start Java worker thread.
handle - handle of the opened port for which event looper need to be started.eventListener - listener to which event will be delivered.portName - name of port represented by this handle.com.serialpundit.core.SerialComException - if an error occurs.public void stopEventLooper()
throws com.serialpundit.core.SerialComException
Set the flag to indicate that the thread is supposed to run to completion and exit. Interrupt the thread so that take() method can come out of blocked sleep state.
com.serialpundit.core.SerialComException - if an error occurs.public void pause()
Data looper thread refrains from sending new data to the data listener.
public void resume()
Looper starts sending new data again to the data listener.
public void setEventsMask(int newMask)
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.
newMask - new bit mask for events that will be delivered to application.public int getEventsMask()
Gives the event mask currently active.
Copyright © 2017. All rights reserved.