Crea sito


org.zu.ardulink
Class Link

java.lang.Object
  extended by org.zu.ardulink.Link

public class Link
extends Object

Ardulink - return to homepage

v0.6.1 Magnum PI

This class represents the connection between the computer and the Arduino board. At the moment the connection is only a serial connection to USB. Any java class must use this class to communicate with Arduino. To get a class instance you can call a static method to get the default link or require the creation of a specific link. In this way it is possible to simultaneously connect to several Arduino boards. Each link can define a specific protocol or use the protocol ardulink (ALProtocol).

Author:
Luciano Zu project Ardulink http://www.ardulink.org/


Field Summary
static int DEFAULT_BAUDRATE
          Default baud rate for serial connections
static String DEFAULT_LINK_NAME
          Default Link name
 
Method Summary
 boolean addAnalogReadChangeListener(AnalogReadChangeListener listener)
          Register an AnalogReadChangeListener to receive events about analog pin change state.
 boolean addConnectionListener(ConnectionListener connectionListener)
          Register a ConnectionListener to receive events about connection status.
 boolean addDigitalReadChangeListener(DigitalReadChangeListener listener)
          Register an DigitalReadChangeListener to receive events about digital pin change state.
 boolean addRawDataListener(RawDataListener rawDataListener)
          Register a RawDataListener to receive data from Arduino.
 boolean connect(Object... params)
          Connects to Arduino board.
static Link createInstance(String linkName)
          Creates a Link instance with a specific name.
static Link createInstance(String linkName, Connection connection)
          Creates a Link instance with a specific name and a specific connection (default is serial connection)
static Link createInstance(String linkName, String protocolName)
          Creates a Link instance with a specific name and a specific protocol.
static Link createInstance(String linkName, String protocolName, Connection connection)
          Creates a Link instance with a specific name and a specific protocol and a specific connection (default is serial connection)
static Link destroyInstance(String linkName)
           
 boolean disconnect()
          Disconnect from arduino board.
 Connection getConnection()
           
static Link getDefaultInstance()
           
static Link getInstance(String linkName)
           
 LoggerReplyMessageCallback getLoggerCallback()
           
 String getName()
           
 List<String> getPortList()
          It works for serial connection links
 String getProtocolName()
           
 boolean isConnected()
           
 IncomingMessageEvent parseMessage(int[] realMsg)
          Parse a message sent from arduino.
 boolean removeAnalogReadChangeListener(AnalogReadChangeListener listener)
          Remove a AnalogReadChangeListener from the event notification set.
 boolean removeConnectionListener(ConnectionListener connectionListener)
          Remove a ConnectionListener from the event notification set.
 boolean removeDigitalReadChangeListener(DigitalReadChangeListener listener)
          Remove a DigitalReadChangeListener from the event notification set.
 boolean removeRawDataListener(RawDataListener rawDataListener)
          Remove a RawDataListener from the data notification set.
 MessageInfo sendCustomMessage(String message)
          Call protocol sendCustomMessage with this Link (and without a call back implementation to manage reply message) Custom message should be used to request specific actions in custom sketches
 MessageInfo sendCustomMessage(String message, ReplyMessageCallback callback)
          Call protocol sendCustomMessage with this Link.
 MessageInfo sendKeyPressEvent(char keychar, int keycode, int keylocation, int keymodifiers, int keymodifiersex)
          Call protocol sendKeyPressEvent with this Link (and without a call back implementation to manage reply message)
 MessageInfo sendKeyPressEvent(char keychar, int keycode, int keylocation, int keymodifiers, int keymodifiersex, ReplyMessageCallback callback)
          Call protocol sendKeyPressEvent with this Link.
 MessageInfo sendNoToneMessage(int pin)
          Call protocol sendNoToneMessage with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a noTone function call.
 MessageInfo sendNoToneMessage(int pin, ReplyMessageCallback callback)
          Call protocol sendNoToneMessage with this Link This method request arduino to perform a noTone function call.
 MessageInfo sendPowerPinIntensity(int pin, int intensity)
          Call protocol sendPowerPinIntensity with this Link (and without a call back implementation to manage reply message) This method request arduino to perform an analogWrite function call.
 MessageInfo sendPowerPinIntensity(int pin, int intensity, ReplyMessageCallback callback)
          Call protocol sendPowerPinIntensity with this Link.
 MessageInfo sendPowerPinSwitch(int pin, int power)
          Call protocol sendPowerPinSwitch with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a digitalWrite function call.
 MessageInfo sendPowerPinSwitch(int pin, int power, ReplyMessageCallback callback)
          Call protocol sendPowerPinSwitch with this Link.
 MessageInfo sendToneMessage(int pin, int frequency)
          Call protocol sendToneMessage with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a tone function call.
 MessageInfo sendToneMessage(int pin, int frequency, int duration)
          Call protocol sendToneMessage with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a tone function call.
 MessageInfo sendToneMessage(int pin, int frequency, int duration, ReplyMessageCallback callback)
          Call protocol sendToneMessage with this Link This method request arduino to perform a tone function call.
 MessageInfo sendToneMessage(int pin, int frequency, ReplyMessageCallback callback)
          Call protocol sendToneMessage with this Link This method request arduino to perform a tone function call.
 MessageInfo startListenAnalogPin(int pin)
          Call protocol startListenAnalogPin with this Link (and without a call back implementation to manage reply message).
 MessageInfo startListenAnalogPin(int pin, ReplyMessageCallback callback)
          As startListenAnalogPin(int pin) but with the possibility to add a callback.
 MessageInfo startListenDigitalPin(int pin)
          Call protocol startListenDigitalPin with this Link (and without a call back implementation to manage reply message).
 MessageInfo startListenDigitalPin(int pin, ReplyMessageCallback callback)
          As startListenDigitalPin(int pin) but with the possibility to add a callback.
 MessageInfo stopListenAnalogPin(int pin)
          Call protocol stopListenAnalogPin with this Link (and without a call back implementation to manage reply message).
 MessageInfo stopListenAnalogPin(int pin, ReplyMessageCallback callback)
          As stopListenAnalogPin(int pin) but with the possibility to add a callback.
 MessageInfo stopListenDigitalPin(int pin)
          Call protocol stopListenDigitalPin with this Link (and without a call back implementation to manage reply message).
 MessageInfo stopListenDigitalPin(int pin, ReplyMessageCallback callback)
          As stopListenDigitalPin(int pin) but with the possibility to add a callback.
 boolean writeSerial(int numBytes, int[] message)
          Writes data to arduino
 boolean writeSerial(String message)
          Writes data to arduino
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BAUDRATE

public static final int DEFAULT_BAUDRATE
Default baud rate for serial connections

See Also:
Constant Field Values

DEFAULT_LINK_NAME

public static final String DEFAULT_LINK_NAME
Default Link name

See Also:
getDefaultInstance(), getInstance(String linkName), Constant Field Values
Method Detail

getDefaultInstance

public static Link getDefaultInstance()
Returns:
the default Link class instance. It uses ALProtocol.

getInstance

public static Link getInstance(String linkName)
Parameters:
linkName - the link name. If null the method returns the default instance.
Returns:
a link previously created with createInstance method.

createInstance

public static Link createInstance(String linkName)
Creates a Link instance with a specific name. Link created has the current protocol implementation.

Parameters:
linkName -
Returns:
Link created
See Also:
ProtocolHandler

createInstance

public static Link createInstance(String linkName,
                                  String protocolName)
Creates a Link instance with a specific name and a specific protocol.

Parameters:
linkName -
protocolName -
Returns:
Link created
See Also:
ProtocolHandler

createInstance

public static Link createInstance(String linkName,
                                  Connection connection)
Creates a Link instance with a specific name and a specific connection (default is serial connection)

Parameters:
linkName -
connection -
Returns:
Link created

createInstance

public static Link createInstance(String linkName,
                                  String protocolName,
                                  Connection connection)
Creates a Link instance with a specific name and a specific protocol and a specific connection (default is serial connection)

Parameters:
linkName -
protocolName -
connection -
Returns:
Link created

destroyInstance

public static Link destroyInstance(String linkName)

connect

public boolean connect(Object... params)
Connects to Arduino board.

Parameters:
params -
Returns:

getPortList

public List<String> getPortList()
It works for serial connection links

Returns:
ports available
See Also:
SerialConnection

disconnect

public boolean disconnect()
Disconnect from arduino board.

Returns:
true if disconnected

isConnected

public boolean isConnected()
Returns:
true if arduino board is connected
See Also:
SerialConnection

writeSerial

public boolean writeSerial(String message)
Writes data to arduino

Parameters:
message -
Returns:
See Also:
SerialConnection

writeSerial

public boolean writeSerial(int numBytes,
                           int[] message)
Writes data to arduino

Parameters:
numBytes -
message -
Returns:
See Also:
SerialConnection

addConnectionListener

public boolean addConnectionListener(ConnectionListener connectionListener)
Register a ConnectionListener to receive events about connection status.

Parameters:
connectionListener -
Returns:
true if this set did not already contain the specified connectionListener
See Also:
ConnectionContact

removeConnectionListener

public boolean removeConnectionListener(ConnectionListener connectionListener)
Remove a ConnectionListener from the event notification set.

Parameters:
connectionListener -
Returns:
true if this set contained the specified connectionListener
See Also:
ConnectionContact

addRawDataListener

public boolean addRawDataListener(RawDataListener rawDataListener)
Register a RawDataListener to receive data from Arduino.

Parameters:
rawDataListener -
Returns:
true if this set did not already contain the specified rawDataListener
See Also:
ConnectionContact

removeRawDataListener

public boolean removeRawDataListener(RawDataListener rawDataListener)
Remove a RawDataListener from the data notification set.

Parameters:
rawDataListener -
Returns:
See Also:
ConnectionContact

addAnalogReadChangeListener

public boolean addAnalogReadChangeListener(AnalogReadChangeListener listener)
Register an AnalogReadChangeListener to receive events about analog pin change state. With this method ardulink is able to receive information from arduino board

Parameters:
listener -
Returns:
true if this set did not already contain the specified AnalogReadChangeListener
See Also:
ConnectionContact

removeAnalogReadChangeListener

public boolean removeAnalogReadChangeListener(AnalogReadChangeListener listener)
Remove a AnalogReadChangeListener from the event notification set.

Parameters:
listener -
Returns:
true if this set contained the specified AnalogReadChangeListener
See Also:
ConnectionContact

addDigitalReadChangeListener

public boolean addDigitalReadChangeListener(DigitalReadChangeListener listener)
Register an DigitalReadChangeListener to receive events about digital pin change state. With this method ardulink is able to receive information from arduino board

Parameters:
listener -
Returns:
true if this set did not already contain the specified DigitalReadChangeListener
See Also:
ConnectionContact

removeDigitalReadChangeListener

public boolean removeDigitalReadChangeListener(DigitalReadChangeListener listener)
Remove a DigitalReadChangeListener from the event notification set.

Parameters:
listener -
Returns:
true if this set contained the specified DigitalReadChangeListener
See Also:
ConnectionContact

getLoggerCallback

public LoggerReplyMessageCallback getLoggerCallback()
Returns:
a simple LoggerCallback implementation just to log messages reply from arduino.

getName

public String getName()
Returns:
the link name

sendKeyPressEvent

public MessageInfo sendKeyPressEvent(char keychar,
                                     int keycode,
                                     int keylocation,
                                     int keymodifiers,
                                     int keymodifiersex)
Call protocol sendKeyPressEvent with this Link (and without a call back implementation to manage reply message)

Parameters:
keychar -
keycode -
keylocation -
keymodifiers -
keymodifiersex -
Returns:
the MessageInfo class

sendPowerPinIntensity

public MessageInfo sendPowerPinIntensity(int pin,
                                         int intensity)
Call protocol sendPowerPinIntensity with this Link (and without a call back implementation to manage reply message) This method request arduino to perform an analogWrite function call.

Parameters:
pin -
intensity - range 0-255
Returns:
the MessageInfo class

sendPowerPinSwitch

public MessageInfo sendPowerPinSwitch(int pin,
                                      int power)
Call protocol sendPowerPinSwitch with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a digitalWrite function call.

Parameters:
pin -
power - IProtocol.POWER_HIGH or IProtocol.POWER_LOW
Returns:
the MessageInfo class

sendToneMessage

public MessageInfo sendToneMessage(int pin,
                                   int frequency)
Call protocol sendToneMessage with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a tone function call.

Parameters:
pin -
frequency -
Returns:
the MessageInfo class

sendToneMessage

public MessageInfo sendToneMessage(int pin,
                                   int frequency,
                                   int duration)
Call protocol sendToneMessage with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a tone function call.

Parameters:
pin -
frequency -
duration -
Returns:
the MessageInfo class

sendNoToneMessage

public MessageInfo sendNoToneMessage(int pin)
Call protocol sendNoToneMessage with this Link (and without a call back implementation to manage reply message) This method request arduino to perform a noTone function call.

Parameters:
pin -
Returns:
the MessageInfo class

sendCustomMessage

public MessageInfo sendCustomMessage(String message)
Call protocol sendCustomMessage with this Link (and without a call back implementation to manage reply message) Custom message should be used to request specific actions in custom sketches

Parameters:
message -
Returns:
the MessageInfo class

sendKeyPressEvent

public MessageInfo sendKeyPressEvent(char keychar,
                                     int keycode,
                                     int keylocation,
                                     int keymodifiers,
                                     int keymodifiersex,
                                     ReplyMessageCallback callback)
Call protocol sendKeyPressEvent with this Link. Arduino should send a reply message back. You can manage this callback with a specific implementation.

Parameters:
keychar -
keycode -
keylocation -
keymodifiers -
keymodifiersex -
callback -
Returns:
the MessageInfo class

sendPowerPinIntensity

public MessageInfo sendPowerPinIntensity(int pin,
                                         int intensity,
                                         ReplyMessageCallback callback)
Call protocol sendPowerPinIntensity with this Link. This method request arduino to perform an analogWrite function call. Arduino should send a reply message back. You can manage this callback with a specific implementation.

Parameters:
pin -
intensity -
callback -
Returns:
the MessageInfo class

sendPowerPinSwitch

public MessageInfo sendPowerPinSwitch(int pin,
                                      int power,
                                      ReplyMessageCallback callback)
Call protocol sendPowerPinSwitch with this Link. This method request arduino to perform a digitalWrite function call. Arduino should send a reply message back. You can manage this callback with a specific implementation.

Parameters:
pin -
power - IProtocol.HIGH or IProtocol.LOW
callback -
Returns:
the MessageInfo class

sendToneMessage

public MessageInfo sendToneMessage(int pin,
                                   int frequency,
                                   ReplyMessageCallback callback)
Call protocol sendToneMessage with this Link This method request arduino to perform a tone function call. Arduino should send a reply message back. You can manage this callback with a specific implementation.

Parameters:
pin -
frequency -
callback -
Returns:
the MessageInfo class

sendToneMessage

public MessageInfo sendToneMessage(int pin,
                                   int frequency,
                                   int duration,
                                   ReplyMessageCallback callback)
Call protocol sendToneMessage with this Link This method request arduino to perform a tone function call. Arduino should send a reply message back. You can manage this callback with a specific implementation.

Parameters:
pin -
frequency -
duration -
callback -
Returns:
the MessageInfo class

sendNoToneMessage

public MessageInfo sendNoToneMessage(int pin,
                                     ReplyMessageCallback callback)
Call protocol sendNoToneMessage with this Link This method request arduino to perform a noTone function call. Arduino should send a reply message back. You can manage this callback with a specific implementation.

Parameters:
pin -
callback -
Returns:
the MessageInfo class

sendCustomMessage

public MessageInfo sendCustomMessage(String message,
                                     ReplyMessageCallback callback)
Call protocol sendCustomMessage with this Link. Custom message should be used to request specific actions in custom sketches

Parameters:
message -
callback -
Returns:
the MessageInfo class

startListenDigitalPin

public MessageInfo startListenDigitalPin(int pin)
Call protocol startListenDigitalPin with this Link (and without a call back implementation to manage reply message). This method request arduino to send messages about digital pin change value. It's called when a DigitalReadChangeListener is added so you don't need to call this method directly.

Parameters:
pin -
Returns:
the MessageInfo class

stopListenDigitalPin

public MessageInfo stopListenDigitalPin(int pin)
Call protocol stopListenDigitalPin with this Link (and without a call back implementation to manage reply message). This method request arduino to stop send messages about digital pin change value. It's called when the last DigitalReadChangeListener is removed so you don't need to call this method directly.

Parameters:
pin -
Returns:
the MessageInfo class

startListenAnalogPin

public MessageInfo startListenAnalogPin(int pin)
Call protocol startListenAnalogPin with this Link (and without a call back implementation to manage reply message). This method request arduino to send messages about analog pin change value. It's called when an AnalogReadChangeListener is added so you don't need to call this method directly.

Parameters:
pin -
Returns:
the MessageInfo class

stopListenAnalogPin

public MessageInfo stopListenAnalogPin(int pin)
Call protocol stopListenAnalogPin with this Link (and without a call back implementation to manage reply message). This method request arduino to stop send messages about analog pin change value. It's called when the last AnalogReadChangeListener is removed so you don't need to call this method directly.

Parameters:
pin -
Returns:
the MessageInfo class

startListenDigitalPin

public MessageInfo startListenDigitalPin(int pin,
                                         ReplyMessageCallback callback)
As startListenDigitalPin(int pin) but with the possibility to add a callback.

Parameters:
pin -
callback -
Returns:
the MessageInfo class

stopListenDigitalPin

public MessageInfo stopListenDigitalPin(int pin,
                                        ReplyMessageCallback callback)
As stopListenDigitalPin(int pin) but with the possibility to add a callback.

Parameters:
pin -
callback -
Returns:
the MessageInfo class

startListenAnalogPin

public MessageInfo startListenAnalogPin(int pin,
                                        ReplyMessageCallback callback)
As startListenAnalogPin(int pin) but with the possibility to add a callback.

Parameters:
pin -
callback -
Returns:
the MessageInfo class

stopListenAnalogPin

public MessageInfo stopListenAnalogPin(int pin,
                                       ReplyMessageCallback callback)
As stopListenAnalogPin(int pin) but with the possibility to add a callback.

Parameters:
pin -
callback -
Returns:
the MessageInfo class

getProtocolName

public String getProtocolName()
Returns:
the protocol name

parseMessage

public IncomingMessageEvent parseMessage(int[] realMsg)
Parse a message sent from arduino. This method should not called directly. It calls the specific protocol parseMessage.

Parameters:
realMsg -
Returns:

getConnection

public Connection getConnection()


Copyright © 2015. All rights reserved.