Serial
The Serial library reads and writes data to and from external devices one byte at a time. It allows two computers to send and receive data. This library has the flexibility to communicate with custom microcontroller devices and to use them as the input or output to Processing programs. The serial port is a nine pin I/O port that exists on many PCs and can be emulated through USB.
Issues related to the Serial library on different platforms are documented on the Processing Wiki. The source code is available on the processing GitHub repository.
When sending data to the console, such as via print() or println(), note that the console is relatively slow. It does not support high-speed, real-time output (such as at 60 frames per second). For real-time monitoring of serial values, render those values to the Processing window during draw().
Serial
- Serial
Class for sending and receiving data using the serial communication protocol
- available()
Returns the number of bytes available
- buffer()
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 there
- last()
Returns last byte received or -1 if there is none available
- lastChar()
Returns the last byte received as a char or -1 if there is none available
- list()
Gets a list of all available serial ports
- read()
Returns a number between 0 and 255 for the next byte that's waiting in the buffer
- readBytes()
Reads a group of bytes from the buffer or null if there are none available
- readBytesUntil()
Reads from the port into a buffer of bytes up to and including a particular character
- readChar()
Returns the next byte in the buffer as a char
- readString()
Returns all the data from the buffer as a String or null if there is nothing available
- readStringUntil()
Combination of readBytesUntil() and readString()
- stop()
Stops data communication on this port
- write()
Writes bytes, chars, ints, bytes[], Strings to the serial port
Serial Event
- serialEvent()
Called when data is available