mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Changed comments for the libraries network, serial, and hardware i/o
This commit is contained in:
@@ -89,7 +89,19 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Calls a function when the value of an input pin changes
|
||||
* Calls a function when the value of an input pin changes<br/>
|
||||
* <br/>
|
||||
* The sketch method provided must accept a single integer (int) parameter, which is the
|
||||
* number of the GPIO pin that the interrupt occured on. As this method might be called
|
||||
* at any time, including when drawing to the display window isn't permitted, it is best
|
||||
* to only set simple variables that are being responded to in the next draw() call, as
|
||||
* shown above. Calling functions of the Hardware I/O library at this point is certainly
|
||||
* possible.<br/>
|
||||
* <br/>
|
||||
* The mode parameter determines when the function will be called: GPIO.FALLING occurs
|
||||
* when the level changes from high to low, GPIO.RISING when the level changes from low
|
||||
* to high, and GPIO.CHANGE when either occurs.
|
||||
*
|
||||
* @param pin GPIO pin
|
||||
* @param parent typically use "this"
|
||||
* @param method name of sketch method to call
|
||||
@@ -98,6 +110,7 @@ public class GPIO {
|
||||
* @see interrupts
|
||||
* @see releaseInterrupt
|
||||
* @webref
|
||||
* @webBrief Calls a function when the value of an input pin changes
|
||||
*/
|
||||
public static void attachInterrupt(int pin, PApplet parent, String method, int mode) {
|
||||
if (irqThreads.containsKey(pin)) {
|
||||
@@ -167,12 +180,18 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of an input pin
|
||||
* Returns the value of an input pin, which is either GPIO.HIGH (1)
|
||||
* or GPIO.LOW (0)<br/>
|
||||
* <br/>
|
||||
* You need to set the pin to input by calling <a href="GPIO_pinMode_.html">
|
||||
* pinMode()</a> before calling this function.
|
||||
*
|
||||
* @param pin GPIO pin
|
||||
* @return GPIO.HIGH (1) or GPIO.LOW (0)
|
||||
* @see pinMode
|
||||
* @see digitalWrite
|
||||
* @webref
|
||||
* @webBrief Returns the value of an input pin
|
||||
*/
|
||||
public static int digitalRead(int pin) {
|
||||
checkValidPin(pin);
|
||||
@@ -202,12 +221,18 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Sets an output pin to be either high or low
|
||||
* Sets an output pin to be either high or low<br/>
|
||||
* <br/>
|
||||
* You need to set the pin to output by calling <a href="GPIO_pinMode_.html">pinMode()</a>
|
||||
* before calling this function. Unlike on Arduino, it is not possible to set a input pin's
|
||||
* internal pull-up resistor using this function.
|
||||
*
|
||||
* @param pin GPIO pin
|
||||
* @param value GPIO.HIGH (1) or GPIO.LOW (0)
|
||||
* @see pinMode
|
||||
* @see digitalRead
|
||||
* @webref
|
||||
* @webBrief Sets an output pin to be either high or low
|
||||
*/
|
||||
public static void digitalWrite(int pin, int value) {
|
||||
checkValidPin(pin);
|
||||
@@ -302,11 +327,18 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Allows interrupts to happen
|
||||
* Allows interrupts to happen<br/>
|
||||
* <br/>
|
||||
* You can use <a href="GPIO_noInterrupts_.html">noInterrupts()</a>
|
||||
* and interrupts() in tandem to make sure no interrupts are occuring
|
||||
* while your sketch is doing a particular task. By default, interrupts
|
||||
* are enabled.
|
||||
*
|
||||
* @see attachInterrupt
|
||||
* @see noInterrupts
|
||||
* @see releaseInterrupt
|
||||
* @webref
|
||||
* @webBrief Allows interrupts to happen
|
||||
*/
|
||||
public static void interrupts() {
|
||||
serveInterrupts = true;
|
||||
@@ -314,11 +346,22 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Prevents interrupts from happpening
|
||||
* Prevents interrupts from happpening<br/>
|
||||
* <br/>
|
||||
* You can use noInterrupts() and <a href="GPIO_interrupts_.html">interrupts()</a>
|
||||
* in tandem to make sure no interrupts are occuring while your sketch is doing a
|
||||
* particular task.<br/>
|
||||
* br/>
|
||||
* While a method associated with a pin's interrupt is being executed, interrupts
|
||||
* from the same pin are automatically prevented from occurring. Interrupts from
|
||||
* other pins can still happen, however. If you also want to prevent those, put
|
||||
* noInterrupts() at the beginning of your callback function and interrupts() at its end.
|
||||
*
|
||||
* @see attachInterrupt
|
||||
* @see interrupts
|
||||
* @see releaseInterrupt
|
||||
* @webref
|
||||
* @webBrief Prevents interrupts from happpening
|
||||
*/
|
||||
public static void noInterrupts() {
|
||||
serveInterrupts = false;
|
||||
@@ -326,13 +369,28 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Configures a pin to act either as input or output
|
||||
* Configures a pin to act either as input (<b>INPUT</b>), or input with internal pull-up
|
||||
* resistor (<b>INPUT_PULLUP</b>), or input with internal pull-down resistor (<b>INPUT_PULLDOWN</b>)
|
||||
* or output (<b>OUTPUT</b>)<br/>
|
||||
* <br/>
|
||||
* Unlike on Arduino, where pins are implicitly set to inputs by default, it is necessary
|
||||
* to call this function for any pin you want to access, including input pins.<br/>
|
||||
* <br/>
|
||||
* Pull-up and pull-down resistors are very useful when connecting buttons and switches,
|
||||
* since they will force the value of the pin in a specified electrical state when no
|
||||
* electrical connection is made, and the pin would otherwise be left "floating".<br/>
|
||||
* <br/>
|
||||
* The ability to set (and clear) pull-up and pull-down resistors is currently limited
|
||||
* to the Raspberry Pi running the Raspbian distribution. On other systems, a warning
|
||||
* will be shown.
|
||||
*
|
||||
* @param pin GPIO pin
|
||||
* @param mode GPIO.INPUT, GPIO.INPUT_PULLUP, GPIO.INPUT_PULLDOWN, or GPIO.OUTPUT
|
||||
* @see digitalRead
|
||||
* @see digitalWrite
|
||||
* @see releasePin
|
||||
* @webref
|
||||
* @webBrief Configures a pin to act either as input or output
|
||||
*/
|
||||
public static void pinMode(int pin, int mode) {
|
||||
checkValidPin(pin);
|
||||
@@ -406,11 +464,13 @@ public class GPIO {
|
||||
|
||||
/**
|
||||
* Stops listening for interrupts on an input pin
|
||||
*
|
||||
* @param pin GPIO pin
|
||||
* @see attachInterrupt
|
||||
* @see noInterrupts
|
||||
* @see interrupts
|
||||
* @webref
|
||||
* @webBrief Stops listening for interrupts on an input pin
|
||||
*/
|
||||
public static void releaseInterrupt(int pin) {
|
||||
Thread t = irqThreads.get(pin);
|
||||
@@ -432,10 +492,15 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Gives ownership of a pin back to the operating system
|
||||
* Gives ownership of a pin back to the operating system<br/>
|
||||
* <br/>
|
||||
* Without calling this function, the pin will remain in the current
|
||||
* state even after the sketch has been closed.
|
||||
*
|
||||
* @param pin GPIO pin
|
||||
* @see pinMode
|
||||
* @webref
|
||||
* @webBrief Gives ownership of a pin back to the operating system
|
||||
*/
|
||||
public static void releasePin(int pin) {
|
||||
checkValidPin(pin);
|
||||
@@ -459,10 +524,20 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Waits for the value of an input pin to change
|
||||
* Waits for the value of an input pin to change<br/>
|
||||
* <br/>
|
||||
* The mode parameter determines when the function will return: GPIO.FALLING occurs
|
||||
* when the level changes from high to low, GPIO.RISING when the level changes from
|
||||
* low to high, and GPIO.CHANGE when either occurs.<br/>
|
||||
* <br/>
|
||||
* The optional timeout parameter determines how many milliseconds the function will
|
||||
* wait at the most. If the value of the input pin hasn't changed at this point, an
|
||||
* exception is raised for this line. Without a timeout parameter the function will
|
||||
* wait indefinitely until the input pin has changed to the desired state.
|
||||
* @param pin GPIO pin
|
||||
* @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
|
||||
* @webref
|
||||
* @webBrief Waits for the value of an input pin to change
|
||||
*/
|
||||
public static void waitFor(int pin, int mode) {
|
||||
waitFor(pin, mode, -1);
|
||||
@@ -470,11 +545,21 @@ public class GPIO {
|
||||
|
||||
|
||||
/**
|
||||
* Waits for the value of an input pin to change
|
||||
* Waits for the value of an input pin to change<br/>
|
||||
* <br/>
|
||||
* The mode parameter determines when the function will return: GPIO.FALLING occurs
|
||||
* when the level changes from high to low, GPIO.RISING when the level changes from
|
||||
* low to high, and GPIO.CHANGE when either occurs.<br/>
|
||||
* <br/>
|
||||
* The optional timeout parameter determines how many milliseconds the function will
|
||||
* wait at the most. If the value of the input pin hasn't changed at this point, an
|
||||
* exception is raised for this line. Without a timeout parameter the function will
|
||||
* wait indefinitely until the input pin has changed to the desired state.
|
||||
*
|
||||
* This function will throw a RuntimeException in case of a timeout.
|
||||
* @param timeout don't wait more than timeout milliseconds
|
||||
* @webref
|
||||
* @webBrief Waits for the value of an input pin to change
|
||||
*/
|
||||
public static void waitFor(int pin, int mode, int timeout) {
|
||||
enableInterrupt(pin, mode);
|
||||
|
||||
@@ -31,15 +31,13 @@ import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client.xml )
|
||||
*
|
||||
* A client connects to a server and sends data back and forth. If anything
|
||||
* goes wrong with the connection, for example the host is not there or is
|
||||
* listening on a different port, an exception is thrown.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref net
|
||||
* @brief The client class is used to create client Objects which connect to a server to exchange data.
|
||||
* @webBrief The client class is used to create client Objects which connect to a server to exchange data.
|
||||
* @instanceName client any variable of type Client
|
||||
* @usage Application
|
||||
* @see_external LIB_net/clientEvent
|
||||
@@ -148,14 +146,12 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_stop.xml )
|
||||
*
|
||||
* Disconnects from the server. Use to shut the connection when you're
|
||||
* finished with the Client.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @brief Disconnects from the server
|
||||
* @webBrief Disconnects from the server
|
||||
* @usage application
|
||||
*/
|
||||
public void stop() {
|
||||
@@ -306,14 +302,12 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_active.xml )
|
||||
*
|
||||
* Returns true if this client is still active and hasn't run
|
||||
* into any trouble.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @brief Returns true if this client is still active
|
||||
* @webBrief Returns true if this client is still active
|
||||
* @usage application
|
||||
*/
|
||||
public boolean active() {
|
||||
@@ -322,14 +316,12 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_ip.xml )
|
||||
*
|
||||
* Returns the IP address of the computer to which the Client is attached.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Returns the IP address of the machine as a String
|
||||
* @webBrief Returns the IP address of the machine as a String
|
||||
*/
|
||||
public String ip() {
|
||||
if (socket != null){
|
||||
@@ -340,15 +332,13 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_available.xml )
|
||||
*
|
||||
* Returns the number of bytes available. When any client has bytes
|
||||
* available from the server, it returns the number of bytes.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Returns the number of bytes in the buffer waiting to be read
|
||||
* @webBrief Returns the number of bytes in the buffer waiting to be read
|
||||
*/
|
||||
public int available() {
|
||||
synchronized (bufferLock) {
|
||||
@@ -358,14 +348,12 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_clear.xml )
|
||||
*
|
||||
* Empty the buffer, removes all the data stored there.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Clears the buffer
|
||||
* @webBrief Clears the buffer
|
||||
*/
|
||||
public void clear() {
|
||||
synchronized (bufferLock) {
|
||||
@@ -376,16 +364,14 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_read.xml )
|
||||
*
|
||||
* Returns a number between 0 and 255 for the next byte that's waiting in
|
||||
* the buffer. Returns -1 if there is no byte, although this should be
|
||||
* avoided by first cheacking <b>available()</b> to see if any data is available.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Returns a value from the buffer
|
||||
* @webBrief Returns a value from the buffer
|
||||
*/
|
||||
public int read() {
|
||||
synchronized (bufferLock) {
|
||||
@@ -402,15 +388,13 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_readChar.xml )
|
||||
*
|
||||
* Returns the next byte in the buffer as a char. Returns -1 or 0xffff if
|
||||
* nothing is there.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Returns the next byte in the buffer as a char
|
||||
* @webBrief Returns the next byte in the buffer as a char
|
||||
*/
|
||||
public char readChar() {
|
||||
synchronized (bufferLock) {
|
||||
@@ -421,7 +405,6 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_readBytes.xml )
|
||||
*
|
||||
* Reads a group of bytes from the buffer. The version with no parameters
|
||||
* returns a byte array of all data in the buffer. This is not efficient,
|
||||
@@ -431,7 +414,6 @@ public class Client implements Runnable {
|
||||
* of bytes read. If more bytes are available than can fit into the
|
||||
* <b>byteBuffer</b>, only those that fit are read.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* <h3>Advanced</h3>
|
||||
* Return a byte array of anything that's in the serial buffer.
|
||||
* Not particularly memory/speed efficient, because it creates
|
||||
@@ -440,7 +422,7 @@ public class Client implements Runnable {
|
||||
*
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Reads everything in the buffer
|
||||
* @webBrief Reads everything in the buffer
|
||||
*/
|
||||
public byte[] readBytes() {
|
||||
synchronized (bufferLock) {
|
||||
@@ -518,7 +500,6 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_readBytesUntil.xml )
|
||||
*
|
||||
* Reads from the port into a buffer of bytes up to and including a
|
||||
* particular character. If the character isn't in the buffer, 'null' is
|
||||
@@ -531,10 +512,9 @@ public class Client implements Runnable {
|
||||
* not large enough, -1 is returned and an error is printed to the message
|
||||
* area. If nothing is in the buffer, 0 is returned.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Reads from the buffer of bytes up to and including a particular character
|
||||
* @webBrief Reads from the buffer of bytes up to and including a particular character
|
||||
* @param interesting character designated to mark the end of the data
|
||||
*/
|
||||
public byte[] readBytesUntil(int interesting) {
|
||||
@@ -615,7 +595,6 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_readString.xml )
|
||||
*
|
||||
* Returns the all the data from the buffer as a String. This method
|
||||
* assumes the incoming characters are ASCII. If you want to transfer
|
||||
@@ -623,10 +602,9 @@ public class Client implements Runnable {
|
||||
* representation of your choice (i.e. UTF8 or two-byte Unicode data), and
|
||||
* send it as a byte array.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Returns the buffer as a String
|
||||
* @webBrief Returns the buffer as a String
|
||||
*/
|
||||
public String readString() {
|
||||
byte b[] = readBytes();
|
||||
@@ -636,12 +614,10 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_readStringUntil.xml )
|
||||
*
|
||||
* Combination of <b>readBytesUntil()</b> and <b>readString()</b>. Returns
|
||||
* <b>null</b> if it doesn't find what you're looking for.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* <h3>Advanced</h3>
|
||||
* <p/>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
@@ -650,7 +626,7 @@ public class Client implements Runnable {
|
||||
*
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Returns the buffer as a String up to and including a particular character
|
||||
* @webBrief Returns the buffer as a String up to and including a particular character
|
||||
* @param interesting character designated to mark the end of the data
|
||||
*/
|
||||
public String readStringUntil(int interesting) {
|
||||
@@ -661,14 +637,12 @@ public class Client implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Client_write.xml )
|
||||
*
|
||||
* Writes data to a server specified when constructing the client.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref client:client
|
||||
* @usage application
|
||||
* @brief Writes bytes, chars, ints, bytes[], Strings
|
||||
* @webBrief Writes bytes, chars, ints, bytes[], Strings
|
||||
* @param data data to write
|
||||
*/
|
||||
public void write(int data) { // will also cover char
|
||||
|
||||
@@ -33,7 +33,6 @@ import java.net.*;
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Server.xml )
|
||||
*
|
||||
* A server sends and receives data to and from its associated clients
|
||||
* (other programs connected to it). When a server is started, it begins
|
||||
@@ -42,10 +41,10 @@ import java.net.*;
|
||||
* commonly used so be sure to not select one of these. For example, web
|
||||
* servers usually use port 80 and POP mail uses port 110.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref net
|
||||
* @usage application
|
||||
* @brief The server class is used to create server objects which send and receives data to and from its associated clients (other programs connected to it).
|
||||
* @webBrief The server class is used to create server objects which send
|
||||
* and receives data to and from its associated clients (other programs connected to it).
|
||||
* @instanceName server any variable of type Server
|
||||
*/
|
||||
public class Server implements Runnable {
|
||||
@@ -115,13 +114,11 @@ public class Server implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Server_disconnect.xml )
|
||||
*
|
||||
* Disconnect a particular client.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @brief Disconnect a particular client.
|
||||
* @webref server:server
|
||||
* @webBrief Disconnect a particular client.
|
||||
* @param client the client to disconnect
|
||||
*/
|
||||
public void disconnect(Client client) {
|
||||
@@ -186,14 +183,12 @@ public class Server implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Server_active.xml )
|
||||
*
|
||||
* Returns true if this server is still active and hasn't run
|
||||
* into any trouble.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref server:server
|
||||
* @brief Return true if this server is still active.
|
||||
* @webBrief Return true if this server is still active.
|
||||
*/
|
||||
public boolean active() {
|
||||
return thread != null;
|
||||
@@ -216,13 +211,11 @@ public class Server implements Runnable {
|
||||
int lastAvailable = -1;
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Server_available.xml )
|
||||
*
|
||||
* Returns the next client in line with a new message.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @brief Returns the next client in line with a new message.
|
||||
* @webref server
|
||||
* @webBrief Returns the next client in line with a new message.
|
||||
* @usage application
|
||||
*/
|
||||
public Client available() {
|
||||
@@ -254,17 +247,15 @@ public class Server implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Server_stop.xml )
|
||||
*
|
||||
* Disconnects all clients and stops the server.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* <h3>Advanced</h3>
|
||||
* Use this to shut down the server if you finish using it while your applet
|
||||
* is still running. Otherwise, it will be automatically be shut down by the
|
||||
* host PApplet using dispose(), which is identical.
|
||||
* @brief Disconnects all clients and stops the server.
|
||||
* @webref server
|
||||
* @webBrief Disconnects all clients and stops the server.
|
||||
* @usage application
|
||||
*/
|
||||
public void stop() {
|
||||
@@ -332,14 +323,12 @@ public class Server implements Runnable {
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Server_write.xml )
|
||||
*
|
||||
* Writes a value to all the connected clients. It sends bytes out from the
|
||||
* Server object.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref server
|
||||
* @brief Writes data to all connected clients
|
||||
* @webBrief Writes data to all connected clients
|
||||
* @param data data to write
|
||||
*/
|
||||
public void write(int data) { // will also cover char
|
||||
|
||||
@@ -34,13 +34,11 @@ import jssc.*;
|
||||
|
||||
|
||||
/**
|
||||
* ( begin auto-generated from Serial.xml )
|
||||
*
|
||||
* Class for sending and receiving data using the serial communication protocol.
|
||||
*
|
||||
* ( end auto-generated )
|
||||
* @webref serial
|
||||
* @brief Class for sending and receiving data using the serial communication protocol.
|
||||
* @webBrief Class for sending and receiving data using the serial communication protocol.
|
||||
* @instanceName serial any variable of type Serial
|
||||
* @usage Application
|
||||
* @see_external LIB_serial/serialEvent
|
||||
@@ -187,8 +185,11 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available.
|
||||
*
|
||||
* @generate Serial_available.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Returns the number of bytes available.
|
||||
* @usage web_application
|
||||
*/
|
||||
public int available() {
|
||||
@@ -197,8 +198,10 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Sets the number of bytes to buffer before calling serialEvent()
|
||||
* @generate Serial_buffer.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Sets the number of bytes to buffer before calling serialEvent()
|
||||
* @usage web_application
|
||||
* @param size number of bytes to buffer
|
||||
*/
|
||||
@@ -208,8 +211,11 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Sets a specific byte to buffer until before calling <b>serialEvent()</b>.
|
||||
*
|
||||
* @generate Serial_bufferUntil.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Sets a specific byte to buffer until before calling <b>serialEvent()</b>.
|
||||
* @usage web_application
|
||||
* @param inByte the value to buffer until
|
||||
*/
|
||||
@@ -220,8 +226,11 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Empty the buffer, removes all the data stored there.
|
||||
*
|
||||
* @generate Serial_clear.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Empty the buffer, removes all the data stored there.
|
||||
* @usage web_application
|
||||
*/
|
||||
public void clear() {
|
||||
@@ -256,12 +265,15 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Returns last byte received or -1 if there is none available.
|
||||
*
|
||||
* @generate Serial_last.xml
|
||||
* <h3>Advanced</h3>
|
||||
* Same as read() but returns the very last value received
|
||||
* and clears the buffer. Useful when you just want the most
|
||||
* recent value sent over the port.
|
||||
* @webref serial:serial
|
||||
* @webBrief Returns last byte received or -1 if there is none available.
|
||||
* @usage web_application
|
||||
*/
|
||||
public int last() {
|
||||
@@ -279,8 +291,11 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the last byte received as a char or -1 if there is none available.
|
||||
*
|
||||
* @generate Serial_lastChar.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Returns the last byte received as a char or -1 if there is none available.
|
||||
* @usage web_application
|
||||
*/
|
||||
public char lastChar() {
|
||||
@@ -289,8 +304,12 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Gets a list of all available serial ports. Use <b>println()</b> to write the
|
||||
* information to the text window.
|
||||
*
|
||||
* @generate Serial_list.xml
|
||||
* @webref serial
|
||||
* @webBrief Gets a list of all available serial ports.
|
||||
* @usage web_application
|
||||
*/
|
||||
public static String[] list() {
|
||||
@@ -301,8 +320,13 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Returns a number between 0 and 255 for the next byte that's waiting in the buffer.
|
||||
* Returns -1 if there is no byte, although this should be avoided by first cheacking
|
||||
* <b>available()</b> to see if data is available.
|
||||
*
|
||||
* @generate Serial_read.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Returns a number between 0 and 255 for the next byte that's waiting in the buffer.
|
||||
* @usage web_application
|
||||
*/
|
||||
public int read() {
|
||||
@@ -322,8 +346,15 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Reads a group of bytes from the buffer or <b>null</b> if there are none available. The version
|
||||
* with no parameters returns a byte array of all data in the buffer. This is not efficient, but
|
||||
* is easy to use. The version with the <b>byteBuffer</b> parameter is more memory and time
|
||||
* efficient. It grabs the data in the buffer and puts it into the byte array passed in and returns
|
||||
* an int value for the number of bytes read. If more bytes are available than can fit into the
|
||||
* <b>byteBuffer</b>, only those that fit are read.
|
||||
* @generate Serial_readBytes.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Reads a group of bytes from the buffer or <b>null</b> if there are none available.
|
||||
* @usage web_application
|
||||
*/
|
||||
public byte[] readBytes() {
|
||||
@@ -404,8 +435,18 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Reads from the port into a buffer of bytes up to and including a particular character. If the
|
||||
* character isn't in the buffer, <b>null</b> is returned. The version with without the
|
||||
* <b>byteBuffer</b> parameter returns a byte array of all data up to and including the
|
||||
* <b>interesting</b> byte. This is not efficient, but is easy to use. The version with the
|
||||
* <b>byteBuffer</b> parameter is more memory and time efficient. It grabs the data in the buffer
|
||||
* and puts it into the byte array passed in and returns an int value for the number of bytes read.
|
||||
* If the byte buffer is not large enough, -1 is returned and an error is printed to the message
|
||||
* area. If nothing is in the buffer, 0 is returned.
|
||||
*
|
||||
* @generate Serial_readBytesUntil.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Reads from the port into a buffer of bytes up to and including a particular character.
|
||||
* @usage web_application
|
||||
* @param inByte character designated to mark the end of the data
|
||||
*/
|
||||
@@ -486,8 +527,12 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the next byte in the buffer as a char. Returns <b>-1</b> or <b>0xffff</b>
|
||||
* if nothing is there.
|
||||
*
|
||||
* @generate Serial_readChar.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Returns the next byte in the buffer as a char.
|
||||
* @usage web_application
|
||||
*/
|
||||
public char readChar() {
|
||||
@@ -496,8 +541,14 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the data from the buffer as a String or <b>null</b> if there is nothing available.
|
||||
* This method assumes the incoming characters are ASCII. If you want to transfer Unicode data,
|
||||
* first convert the String to a byte stream in the representation of your choice (i.e. UTF8 or
|
||||
* two-byte Unicode data), and send it as a byte array.
|
||||
*
|
||||
* @generate Serial_readString.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Returns all the data from the buffer as a String or <b>null</b> if there is nothing available.
|
||||
* @usage web_application
|
||||
*/
|
||||
public String readString() {
|
||||
@@ -509,6 +560,9 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Combination of <b>readBytesUntil()</b> and <b>readString()</b>. Returns <b>null</b>
|
||||
* if it doesn't find what you're looking for.
|
||||
*
|
||||
* @generate Serial_readStringUntil.xml
|
||||
*<h3>Advanced</h3>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
@@ -516,6 +570,7 @@ public class Serial implements SerialPortEventListener {
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*
|
||||
* @webref serial:serial
|
||||
* @webBrief Combination of <b>readBytesUntil()</b> and <b>readString()</b>.
|
||||
* @usage web_application
|
||||
* @param inByte character designated to mark the end of the data
|
||||
*/
|
||||
@@ -530,8 +585,16 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Called when data is available. Use one of the <b>read()</b> methods to capture this data.
|
||||
* The <b>serialEvent()</b> can be set with <b>buffer()</b> to only trigger after a certain
|
||||
* number of data elements are read and can be set with <b>bufferUntil()</b> to only trigger
|
||||
* after a specific character is read. The <b>which</b> parameter contains the name of the
|
||||
* port where new data is available, but is only useful when there is more than one serial
|
||||
* connection open and it's necessary to distinguish between the two.
|
||||
*
|
||||
* @generate serialEvent.xml
|
||||
* @webref serial:events
|
||||
* @webBrief Called when data is available.
|
||||
* @usage web_application
|
||||
* @param event the port where new data is available
|
||||
*/
|
||||
@@ -612,8 +675,11 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Stops data communication on this port. Use to shut the connection when you're finished with the Serial.
|
||||
*
|
||||
* @generate Serial_stop.xml
|
||||
* @webref serial:serial
|
||||
* @webBrief Stops data communication on this port.
|
||||
* @usage web_application
|
||||
*/
|
||||
public void stop() {
|
||||
@@ -656,6 +722,8 @@ public class Serial implements SerialPortEventListener {
|
||||
|
||||
|
||||
/**
|
||||
* Writes bytes, chars, ints, bytes[], Strings to the serial port
|
||||
*
|
||||
* @generate Serial_write.xml
|
||||
* <h3>Advanced</h3>
|
||||
* Write a String to the output. Note that this doesn't account
|
||||
@@ -670,6 +738,7 @@ public class Serial implements SerialPortEventListener {
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
*
|
||||
* @webref serial:serial
|
||||
* @webBrief Writes bytes, chars, ints, bytes[], Strings to the serial port
|
||||
* @usage web_application
|
||||
* @param src data to write
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user