tango.io.device.SerialPort

License:

BSD style: see license.txt

Author:

Robin Kreis
class SerialPort : Device
Enables applications to use a serial port (aka COM-port, ttyS). Usage is similar to that of File:
1
2
3
4
auto serCond = new SerialPort("ttyS0");
serCond.speed = 38400;
serCond.write("Hello world!");
serCond.close();
this(const(char)[] port)
Create a new SerialPort instance. The port will be opened and set to raw mode with 9600-8N1.

Parameters:

portA string identifying the port. On Posix, this must be a device file like /dev/ttyS0. If the input doesn't begin with "/", "/dev/" is automatically prepended, so "ttyS0" is sufficent. On Windows, this must be a device name like COM1.
string toString() [override]
Returns a string describing this serial port. For example: "ttyS0", "COM1", "cuad0".
SerialPort speed(uint speed)
Sets the baud rate of this port. Usually, the baud rate can only be set to fixed values (common values are 1200 * 2^n).
Note that for Posix, the specification only mandates speeds up to 38400, excluding speeds such as 7200, 14400 and 28800. Most Posix systems have chosen to support at least higher speeds though.

See Also:

maxSpeed

Throws:

IOException if speed is unsupported.
const(char)[][] ports() [static]
Tries to enumerate all serial ports. While this usually works on Windows, it's more problematic on other OS. Posix provides no way to list serial ports, and the only option is searching through "/dev".
Because there's no naming standard for the device files, this method must be ported for each OS. This method is also unreliable because the user could have created invalid device files, or deleted them.

Returns:

A string array of all the serial ports that could be found, in alphabetical order. Every string is formatted as a valid argument to the constructor, but the port may not be accessible.