|
||||||||||
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 org.zu.ardulink.connection.serial.SerialConnection
public class SerialConnection
v0.6.1 Magnum PI
Used to simplify communication over a Serial port. Using the RXTX-library (rxtx.qbang.org), one connection per instance of this class can be handled. In addition to handling a connection, information about the available Serial ports can be received using this class. 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
AbstractSerialConnection.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.
Luciano Zu Ardulink has added Connection implementation interface to allow multiple connections.
Luciano Zu Ardulink has heavily refactored this class (its original name was gnu.io.net.Network)
Field Summary |
---|
Fields inherited from class org.zu.ardulink.connection.serial.AbstractSerialConnection |
---|
DEFAULT_CONNECTION_NAME |
Constructor Summary | |
---|---|
SerialConnection()
See super constructor |
|
SerialConnection(ConnectionContact contact)
Just as #SerialConnection(int, ConnectionContact, int) , but with a default
AbstractSerialConnection.divider of 255 and a default AbstractSerialConnection.id of 0. |
|
SerialConnection(String id)
See super constructor |
|
SerialConnection(String id,
ConnectionContact contact)
Just as #SerialConnection(int, ConnectionContact, int) , but with a default
AbstractSerialConnection.divider of 255. |
|
SerialConnection(String id,
ConnectionContact contact,
int divider)
|
|
SerialConnection(String id,
int divider)
See super constructor |
Method Summary | |
---|---|
boolean |
connect(Object... params)
|
boolean |
connect(String portName)
Just as connect(String, int) , but using 115200 bps as a default
speed of the connection. |
boolean |
connect(String portName,
int speed)
Opening a connection to the specified Serial port, using the specified speed. |
boolean |
disconnect()
Simple function closing the connection held by this instance of SerialConnection . |
List<String> |
getPortList()
This method is used to get a list of all the available Serial ports (note: only Serial ports are considered). |
Methods inherited from class org.zu.ardulink.connection.serial.AbstractSerialConnection |
---|
getContact, getId, isConnected, setConnectionContact, startReader, stopReader, writeLog, writeSerial, writeSerial |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.zu.ardulink.connection.Connection |
---|
isConnected, setConnectionContact, writeSerial, writeSerial |
Constructor Detail |
---|
public SerialConnection(String id, ConnectionContact contact, int divider)
id
- int identifying the specific instance of the
SerialConnection-class. While having only a single instance,
AbstractSerialConnection.id
is irrelevant. However, having more than one open
connection (using more than one instance of SerialConnection),
AbstractSerialConnection.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 AbstractSerialConnection.divider
could be identified.public SerialConnection(String id, ConnectionContact contact)
#SerialConnection(int, ConnectionContact, int)
, but with a default
AbstractSerialConnection.divider
of 255.
#SerialConnection(int, ConnectionContact, int)
public SerialConnection(ConnectionContact contact)
#SerialConnection(int, ConnectionContact, int)
, but with a default
AbstractSerialConnection.divider
of 255 and a default AbstractSerialConnection.id
of 0. This
constructor may mainly be used if only one Serial connection is needed at
any time.
#SerialConnection(int, ConnectionContact, int)
public SerialConnection()
public SerialConnection(String id, int divider)
public SerialConnection(String id)
Method Detail |
---|
public 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
getPortList
in class AbstractSerialConnection
List
containing String
s showing all available
Serial ports.public boolean connect(String portName)
connect(String, int)
, but using 115200 bps as a default
speed of the connection.
portName
- The name of the port the connection should be opened to (see
getPortList()
).
connect(String, int)
public boolean connect(String portName, int speed)
AbstractSerialConnection.writeSerial(String)
and received data will be packed into
packets (see AbstractSerialConnection.divider
) and forwarded using
org.zu.ardulink.connection.ConnectionContact#parseInput(int, int, int[])
.
portName
- The name of the port the connection should be opened to (see
getPortList()
).speed
- The desired speed of the connection in bps.
public boolean disconnect()
SerialConnection
. It also ends the Thread AbstractSerialConnection.reader
.
disconnect
in interface Connection
disconnect
in class AbstractSerialConnection
public boolean connect(Object... params)
connect
in interface Connection
connect
in class AbstractSerialConnection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |