public class ArduinoJavaSerialRpc extends Object
- The sketch includes the ArduinoSerialRpc library: "
#include <ArduinoSerialRpc.h>"- The sketch function is registered using the "registerArduinoFunction" method.
- The sketch registered function have one of the following signatures:
- void methodName();
- int methodName(int arg1, int arg2);
- float methodName(float arg);
- String methodName(String arg);
libraryInstance = new ArduinoRpc("COM5", 9600);
libraryInstance.connect();
libraryInstance.executeRemoteFunction("writeAction", 1811, 1118);
- The sketch includes: "
#include <ArduinoSerialRpc.h>".- The required method is part of a class which extends ArduinoJavaSerialRpc.
- The method signature is one of the following:
- void methodName();
- Integer methodName(Integer arg1, Integer arg2);
- Float methodName(Float arg);
- String methodName(String arg);
ArduinoSerialRpc rpc("My Arduino");
rpc.executeRemoteMethod("printArduinoText", "Hello from Arduino");
| Modifier and Type | Field and Description |
|---|---|
static int |
DATA_RATE_115200 |
static int |
DATA_RATE_1200 |
static int |
DATA_RATE_14400 |
static int |
DATA_RATE_19200 |
static int |
DATA_RATE_2400 |
static int |
DATA_RATE_28800 |
static int |
DATA_RATE_300 |
static int |
DATA_RATE_38400 |
static int |
DATA_RATE_4800 |
static int |
DATA_RATE_57600 |
static int |
DATA_RATE_600 |
static int |
DATA_RATE_9600 |
static String |
LINUX_DEFAULT_PORT
Default port to use when the Operative System is Linux.
|
static String |
MAC_OS_DEFAULT_PORT
Default port to use when the Operative System is Mac OS.
|
static String |
RASPBERRY_PI_DEFAULT_PORT
Default port to use when the Platform is Raspberry PI.
|
static String |
WINDOWS_DEFAULT_PORT
Default port to use when the Operative System is Windows.
|
static String |
WINDOWS_USB_1
Port COM1, to be used when the Operative System is Windows.
|
static String |
WINDOWS_USB_2
Port COM2, to be used when the Operative System is Windows.
|
static String |
WINDOWS_USB_3
Port COM3, to be used when the Operative System is Windows.
|
static String |
WINDOWS_USB_4
Port COM4, to be used when the Operative System is Windows.
|
static String |
WINDOWS_USB_5
Port COM5, to be used when the Operative System is Windows.
|
static String |
WINDOWS_USB_6
Port COM6, to be used when the Operative System is Windows.
|
| Constructor and Description |
|---|
ArduinoJavaSerialRpc(String portName,
int baudRate)
Creates a connector to Arduino card.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
Creates a connection with the Arduino card.
|
void |
disconnect()
Release the serial port connected to the Arduino card.
|
void |
executeLocalMethod(String methodToDo)
Discovers and executes a method of the extending class.
|
void |
executeLocalMethod(String methodToDo,
float arg)
Discovers and executes a method of the extending class.
|
void |
executeLocalMethod(String methodToDo,
int arg1,
int arg2)
Discovers and executes a method of the extending class.
|
void |
executeLocalMethod(String methodToDo,
String arg)
Discovers and executes a method of the extending class.
|
void |
executeRemoteFunction(String functionName)
Executes a function (of Arduino sketch) with signature: void functionName();.
|
float |
executeRemoteFunction(String functionName,
float argument)
Executes a method (of Arduino sketch) with signature: float functionName(float);
|
Integer |
executeRemoteFunction(String functionName,
int arg1,
int arg2)
Executes a function (of Arduino sketch) with signature: int functionName(int arg1, int arg2);
For example:
ArduinoSerialRpc rpc;
pinMode(2, OUTPUT);pinMode(3, OUTPUT); rpc.registerArduinoFunction("setLightIntensity", setBrightness); } // Callable method from Java program. |
String |
executeRemoteFunction(String functionName,
String argument)
Executes a function (of Arduino sketch) with signature: string functionName(string);
|
int |
getBaudRate()
Returns the used baud rate
|
String |
getCardName()
Returns the card identification declared into the sketch
It is the string used as argument of ArduinoSerialRpc constructor into the sketch.
|
String |
getPortName()
Returns the used USB port name
|
void |
handlerReceivingException(Exception ex)
Overridable function called when an exception occurs during data reads from Arduino.
|
static String[] |
portScanner()
Discover the available serial ports in system.
|
public static final String MAC_OS_DEFAULT_PORT
public static final String RASPBERRY_PI_DEFAULT_PORT
public static final String LINUX_DEFAULT_PORT
public static final String WINDOWS_DEFAULT_PORT
public static final String WINDOWS_USB_1
public static final String WINDOWS_USB_2
public static final String WINDOWS_USB_3
public static final String WINDOWS_USB_4
public static final String WINDOWS_USB_5
public static final String WINDOWS_USB_6
public static final int DATA_RATE_300
public static final int DATA_RATE_600
public static final int DATA_RATE_1200
public static final int DATA_RATE_2400
public static final int DATA_RATE_4800
public static final int DATA_RATE_9600
public static final int DATA_RATE_14400
public static final int DATA_RATE_19200
public static final int DATA_RATE_28800
public static final int DATA_RATE_38400
public static final int DATA_RATE_57600
public static final int DATA_RATE_115200
public ArduinoJavaSerialRpc(String portName, int baudRate)
portName - The name of connection port; His syntax depends from the operating system in use.baudRate - The value for Serial port speed; His value must be the same of Serial.begin value in the sketch.public void connect()
throws ArduinoRpcInitializationError
ArduinoRpcInitializationError - In any case of connection or
initialization error (i.e. wrong connection port specified).public void disconnect()
throws IOException
IOException - In any case of closing errors.public static String[] portScanner()
public String getPortName()
public int getBaudRate()
public String getCardName() throws ArduinoRpcJavaFailsException
ArduinoRpcJavaFailsException - In any case of communication error or java side problems.public void executeRemoteFunction(String functionName) throws ArduinoRpcJavaFailsException
functionName - The name of Arduino's function to call.ArduinoRpcJavaFailsException - In any case of communication error or java side problems.public Integer executeRemoteFunction(String functionName, int arg1, int arg2) throws ArduinoRpcJavaFailsException
ArduinoSerialRpc rpc;
void setup() {pinMode(2, OUTPUT);}
pinMode(3, OUTPUT);
rpc.registerArduinoFunction("setLightIntensity", setBrightness);
// Callable method from Java program.
// Java executes: libraryInstance.executeRemoteFunction("setLightIntensity", 2, 132);
boolean setBrightness(int pin, int value) {if ((pin == 2) || (pin == 3)) {}analogWrite(pin, value);} else {
return true;return false;}
functionName - The name of function to call, in Arduino sketch.arg1 - First value to send.arg2 - Second value to send.ArduinoRpcJavaFailsException - In any case of communication error or java side problems.public String executeRemoteFunction(String functionName, String argument) throws ArduinoRpcJavaFailsException
functionName - The name of function to call, in Arduino sketch.argument - The parameter to sendArduinoRpcJavaFailsException - In any case of communication error or java side problems.public float executeRemoteFunction(String functionName, float argument) throws ArduinoRpcJavaFailsException
functionName - The name of function to call, in Arduino sketch.argument - The parameter to sendArduinoRpcJavaFailsException - In any case of communication error or java side problemspublic void handlerReceivingException(Exception ex)
ex - The occurred exceptionpublic void executeLocalMethod(String methodToDo) throws ArduinoRpcJavaFailsException
methodToDo - the name of method to be calledArduinoRpcJavaFailsException - In any case of communication error or java side problemspublic void executeLocalMethod(String methodToDo, int arg1, int arg2) throws ArduinoRpcJavaFailsException
methodToDo - the name of method to be calledarg1 - the first input parameterarg2 - the second input parameterArduinoRpcJavaFailsException - In any case of communication error or java side problemspublic void executeLocalMethod(String methodToDo, String arg) throws ArduinoRpcJavaFailsException
methodToDo - the name of method to be calledarg - the input parameterArduinoRpcJavaFailsException - In any case of communication error or java side problemspublic void executeLocalMethod(String methodToDo, float arg) throws ArduinoRpcJavaFailsException
methodToDo - the name of method to be calledarg - the input parameterArduinoRpcJavaFailsException - In any case of communication error or java side problemsCopyright © 2020 Mauxilium (Gabriele Maris). All rights reserved.