serialport 1.0.0
Simple crossplatform work with serailport
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
SerialPort
Library provides simple work with serial port for Linux, Windows and MacOS.
Simple usage
auto com = new SerialPortBlk("/dev/ttyUSB0", 19200);
// setting parameters example
com.config = SPConfig(9600, DataBits.data8, Parity.none, StopBits.one)
com.set(19200).set(DataBits.data8);
com.stopBits = StopBits.two;
// set 9600 baudrate, 8 data bits, no parity and one stop bit
com.set("9600:8N1");
auto cnt = com.write(someDataArray);
// cnt must be equal someDataArray.length
// res1 is slice of bufferForReading with readed data
auto res1 = com.read(bufferForReading);
SerialPortNonBlk
provides non-blocking read
(immediatlly return data in system serial port buffer)
and write
(return writed bytes count at the first onset).
Warning: unix systems allow only standard speeds [0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400]
Example: monitor
If you want use read/write loops in fibers you can use SerialPortFR
class.
// vibe.core.sleep for example
auto com = new SerialPortFR("/dev/ttyUSB0", "9600:8N1", sleepDelegate);
// write timeout
com.writeLoop(someDataArray, 500.dur!"usecs");
// read timeout frame end gap
auto res2 = com.readLoop(bufferForReading, 500.dur!"msecs", 20.dur!"msecs");
At expiration of write timeout throws TimeoutException
.
At expiration of read timeout throws TimeoutException
if no bytes readed.
If readed bytes count != 0 wait frame end gap and if no new bytes return readed.
Reading and writing loops algorithms use Fiber.yield
if available,
or Thread.yield
otherwise. If you want redefine this behavior, you can set
void delegate() yieldFunc
field of SerialPort
through ctor or directly.
Tests
For linux and OSX tested
- ldc
- ldc-beta
- ldc-1.8.0
- dmd
- dmd-nightly
- dmd-2.079.1
- dmd-2.078.3
For windows tested fox x86 and x64
- dmd beta
- dmd stable
- ldc beta
- ldc stable
NOTE
- Registered by Oleg
- 1.0.0 released 6 years ago
- deviator/serialport
- MIT
- Copyright © 2017
- Authors:
- Dependencies:
- none
- Versions:
-
2.2.3 2020-Jul-27 2.2.2 2019-Oct-25 2.2.1 2019-Oct-24 2.2.0 2018-Oct-25 2.1.7 2018-Jul-19 - Download Stats:
-
-
0 downloads today
-
7 downloads this week
-
29 downloads this month
-
3398 downloads total
-
- Score:
- 2.4
- Short URL:
- serialport.dub.pm