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 default
  • portName(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 default
  • stopBits(float)1.0, 1.5, or 2.0 (1.0 is the default)

Methods

  • 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()
  • serialEvent()Called when data is available
  • stop()Stops data communication on this port
  • write()Writes bytes, chars, ints, bytes[], Strings to the serial port