ASL
Loading...
Searching...
No Matches
SerialPort Class Reference

Detailed Description

SerialPort represents a serial port to communicate with.

if(!port.open("COM1")) // or "/dev/ttyS0", "/dev/ttyUSB0" ... on Linux
return;
port.config(9600, "8N1"); // 9600 bps, 8 bits, no parity, 1 stop bit
port.setTimeout(0.2);
port << "COMMAND\n";
while(1)
{
if(port.waitInput())
{
if(port.error()) // the device disconnected
break;
String info = port.readLine();
}
}
An Array is a contiguous and resizable array of any type of elements.
Definition Array.h:69
SerialPort represents a serial port to communicate with.
Definition SerialPort.h:41
bool waitInput(double timeout=10)
Waits until there is data to read for a maximum time of timeout seconds (or the device disconnected),...
void setTimeout(double s)
Sets the read timeout in seconds.
bool config(int bps, const String &mode="8N1")
Configures the port with a bitrate and a string encoded as "BPS": B=data bits, P=parity (N/E/O),...
String readLine()
Reads a text line from the port (up to a \r or \n character) and returns it not including the newline...
bool error()
Returns true if there were communication errors (possibly the device was disconnected)
Definition SerialPort.h:65
bool open(const String &port)
Opens the port by name (Windows: "COM...", Linux: "/dev/...")
String represents a character string that behaves similarly to JavaScript strings in that it can be c...
Definition String.h:126

#include <SerialPort.h>

Public Member Functions

bool open (const String &port)
 Opens the port by name (Windows: "COM...", Linux: "/dev/...")
 
void setNewline (const String &nl)
 Sets the newline to expect by readLine(), normally one of "\n", "\r" or "\r\n".
 
void close ()
 Closes the port.
 
bool error ()
 Returns true if there were communication errors (possibly the device was disconnected)
 
void setTimeout (double s)
 Sets the read timeout in seconds.
 
bool config (int bps, const String &mode="8N1")
 Configures the port with a bitrate and a string encoded as "BPS": B=data bits, P=parity (N/E/O), S=stop bits, plus an optional X for Xon/Xoff flow control.
 
bool waitInput (double timeout=10)
 Waits until there is data to read for a maximum time of timeout seconds (or the device disconnected), and return true if something happened before the timeout.
 
int available ()
 Returns the number of bytes available for reading.
 
int write (const void *p, int n)
 Writes n bytes of buffer p to the port.
 
int read (void *p, int n)
 Reads n bytes from the port into buffer p.
 
int write (const String &s)
 Writes the given string to the port.
 
String readLine ()
 Reads a text line from the port (up to a \r or \n character) and returns it not including the newline.
 

The documentation for this class was generated from the following file: