|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zu.ardulink.connection.serial.AbstractSerialConnection
public abstract class AbstractSerialConnection
v0.6.1 Magnum PI
Used to simplify communication. One connection per instance of this class can be handled. A separateThread
is started to handle messages that are being
received over the Serial interface.
This class also makes packages out of a stream of bytes received, using a
divider
, and sending these packages as an array of ints (each
between 0 and 255) to a function implemented by a class implementing the
org.zu.ardulink.connection.ConnectionContact
-interface.
Field Summary | |
---|---|
static String |
DEFAULT_CONNECTION_NAME
|
Constructor Summary | |
---|---|
AbstractSerialConnection()
Just as (@link AbstractSerialConnection(ConnectionContact) , but with null contact. |
|
AbstractSerialConnection(ConnectionContact contact)
Just as #AbstractSerialConnection(int, ConnectionContact, int) , but with a default
divider of 255 and a default id of DEFAULT_CONNECTION_NAME. |
|
AbstractSerialConnection(String id)
Just as (@link #AbstractSerialConnection(int, ConnectionContact, int) , but with null contact and default divider. |
|
AbstractSerialConnection(String id,
ConnectionContact contact)
Just as #AbstractSerialConnection(int, ConnectionContact, int) , but with a default
divider of 255. |
|
AbstractSerialConnection(String id,
ConnectionContact contact,
int divider)
|
|
AbstractSerialConnection(String id,
int divider)
Just as (@link #AbstractSerialConnection(int, ConnectionContact, int) , but with null contact. |
Method Summary | |
---|---|
abstract boolean |
connect(Object... params)
|
abstract boolean |
disconnect()
|
ConnectionContact |
getContact()
|
String |
getId()
|
abstract List<String> |
getPortList()
This method is used to get a list of all the available Serial ports (note: only Serial ports are considered). |
boolean |
isConnected()
|
void |
setConnectionContact(ConnectionContact connectionContact)
|
void |
startReader()
|
void |
stopReader()
|
void |
writeLog(String text)
|
boolean |
writeSerial(int numBytes,
int[] message)
If a connection is open, an int between 0 and 255 (except the divider ) can be sent over the Serial port using this
function. |
boolean |
writeSerial(String message)
This method is included as a legacy. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_CONNECTION_NAME
Constructor Detail |
---|
public AbstractSerialConnection(String id, ConnectionContact contact, int divider)
id
- int identifying the specific instance of the
SerialConnection-class. While having only a single instance,
id
is irrelevant. However, having more than one open
connection (using more than one instance of SerialConnection),
id
helps identifying which Serial connection a
message or a log entry came from.contact
- Link to the instance of the class implementing
org.zu.ardulink.connection.ConnectionContact
.divider
- A small int representing the number to be used to
distinguish between two consecutive packages. It can take a
value between 0 and 255. Note that data is only sent to
org.zu.ardulink.connection.ConnectionContact#parseInput(int, int, int[])
once the
following divider
could be identified.public AbstractSerialConnection(String id, ConnectionContact contact)
#AbstractSerialConnection(int, ConnectionContact, int)
, but with a default
divider
of 255.
#SerialConnection(int, ConnectionContact, int)
public AbstractSerialConnection(ConnectionContact contact)
#AbstractSerialConnection(int, ConnectionContact, int)
, but with a default
divider
of 255 and a default id
of DEFAULT_CONNECTION_NAME. This
constructor may mainly be used if only one Serial connection is needed at
any time.
#SerialConnection(int, ConnectionContact, int)
public AbstractSerialConnection()
AbstractSerialConnection(ConnectionContact)
, but with null contact.
The first method to use should be setConnectionContact(ConnectionContact)
public AbstractSerialConnection(String id, int divider)
#AbstractSerialConnection(int, ConnectionContact, int)
, but with null contact.
The first method to use should be setConnectionContact(ConnectionContact)
public AbstractSerialConnection(String id)
#AbstractSerialConnection(int, ConnectionContact, int)
, but with null contact and default divider.
The first method to use should be setConnectionContact(ConnectionContact)
Method Detail |
---|
public abstract List<String> getPortList()
List
can be used as a parameter in
#connect(String)
or #connect(String, int)
to open a
Serial connection.
getPortList
in interface Connection
List
containing String
s showing all available
Serial ports.public void startReader()
public void stopReader()
public boolean writeSerial(String message)
divider
to the end.
If a connection is open, a String
can be sent over the Serial
port using this function. If no connection is available, false is
returned and a message is sent using
org.zu.ardulink.connection.ConnectionContact#writeLog(int, String)
.
writeSerial
in interface Connection
message
- The String
to be sent over the Serial connection.
public boolean writeSerial(int numBytes, int[] message)
divider
) can be sent over the Serial port using this
function. The message will be finished by sending the
divider
. If no connection is available, false
is returned and a message is sent using
org.zu.ardulink.connection.ConnectionContact#writeLog(int, String)
.
writeSerial
in interface Connection
numBytes
- The number of bytes to send over the Serial port.message
- [] The array ofints to be sent over the Serial
connection (between 0 and 256).
divider
.public abstract boolean connect(Object... params)
connect
in interface Connection
public abstract boolean disconnect()
disconnect
in interface Connection
public void setConnectionContact(ConnectionContact connectionContact)
setConnectionContact
in interface Connection
public boolean isConnected()
isConnected
in interface Connection
AbstractSerialConnection
has currently an
open connection of not.public ConnectionContact getContact()
public String getId()
public void writeLog(String text)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |