Module providing instruments to work with serial port on Windows and Posix OS. SerialPort class can enumerate available serial ports (works robust only on Windows), check available baud rates.
auto com = new SerialPort("COM1"); // ttyS0 on GNU/Linux, for instance string test = "Hello, World!"; com.write(test.ptr); ubyte[13] buff; com.read(buff); writeln(cast(string)buff);
Represents allowed baud rate speeds for serial port.
Thrown when trying to setup serial port with unsupported baud rate by current OS.
Thrown when setting up new serial port parameters has failed.
Thrown when tried to open invalid serial port file.
Thrown when trying to accept closed device.
Thrown when read/write operations failed due timeout.
Exception carries useful info about number of read/wrote bytes until timeout occurs. It takes sense only for Windows, as posix version won't start reading until the port is empty.
Transfers problematic port name and size of read/wrote bytes until timeout.
Thrown when reading from serial port is failed.
Thrown when writing to serial port is failed.
Main class encapsulating platform dependent files handles and algorithms to work with serial port.
You can open serial port only once, after calling close any nonstatic method will throw DeviceClosedException.
Creates new serial port instance.
string port | Port name. On Posix, it should be reffer to device file
like /dev/ttyS |
Creates new serial port instance.
string port | Port name. On Posix, it should be reffer to device file
like /dev/ttyS |
Duration readTimeout | Setups constant timeout on read operations. |
Duration writeTimeout | Setups constant timeout on write operations. In posix is ignored. |
Creates new serial port instance.
string port | Port name. On Posix, it should be reffer to device file
like /dev/ttyS |
Duration readTimeoutConst | Setups constant timeout on read operations. |
Duration writeTimeoutConst | Setups constant timeout on write operations. In posix is ignored. |
Duration readTimeoutMult | Setups timeout on read operations depending on buffer size. |
Duration writeTimeoutMult | Setups timeout on write operations depending on buffer size. In posix is ignored. |
Converts serial port to it port name.
Set the baud rate for this serial port. Speed values are usually restricted to be 1200 * i ^ 2.
Iterates over all bauds rate and tries to setup port with it.
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.
Closing underlying serial port. You shouldn't use port after it closing.
Returns true if serial port was closed.
Writes down array of bytes to serial port.
Fills up provided array with bytes from com port.