Reference+
Class Name
Serial
Description
Class for sending and receiving data using the serial communication protocol.
Examples
// Example by Tom Igoe import processing.serial.*; // The serial port: Serial myPort; // List all the available serial ports: printArray(Serial.list()); // Open the port you are using at the rate you want: myPort = new Serial(this, Serial.list()[0], 9600); // Send a capital A out the serial port: myPort.write(65);
Constructors
Serial(parent)
Serial(parent, baudRate)
Serial(parent, portName)
Serial(parent, portName, baudRate)
Serial(parent, portName, baudRate, parity, dataBits, stopBits)
Parameters
parent
(PApplet)
typically use "this"baudRate
(int)
9600 is the defaultportName
(String)
name of the port (COM1 is the default)parity
(char)
'N' for none, 'E' for even, 'O' for odd, 'M' for mark, 'S' for space ('N' is the default)dataBits
(int)
8 is the defaultstopBits
(float)
1.0, 1.5, or 2.0 (1.0 is the default)
Methods
available()
Returns the number of bytes availablebuffer()
Sets the number of bytes to buffer before calling serialEvent()bufferUntil()
Sets a specific byte to buffer until before calling serialEvent()clear()
Empty the buffer, removes all the data stored therelast()
Returns last byte received or -1 if there is none availablelastChar()
Returns the last byte received as a char or -1 if there is none availablelist()
Gets a list of all available serial portsread()
Returns a number between 0 and 255 for the next byte that's waiting in the bufferreadBytes()
Reads a group of bytes from the buffer or null if there are none availablereadBytesUntil()
Reads from the port into a buffer of bytes up to and including a particular characterreadChar()
Returns the next byte in the buffer as a charreadString()
Returns all the data from the buffer as a String or null if there is nothing availablereadStringUntil()
Combination of readBytesUntil() and readString()serialEvent()
Called when data is availablestop()
Stops data communication on this portwrite()
Writes bytes, chars, ints, bytes[], Strings to the serial port
Related
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.