1 module tests.integration;
2 
3 import std.stdio;
4 import core.time;
5 import unit_threaded;
6 
7 import serial.device;
8 
9 void testWrite() {
10    Duration timeout = dur!("msecs")(2000);
11    string port = "/dev/ttyS2";
12    version(Windows) {
13       port = "COM1";
14    }
15 
16    auto com = new serial.device.SerialPort(port, timeout, timeout);
17    scope (exit) com.close;
18 
19    com.speed = BaudRate.BR_115200;
20    com.dataBits = DataBits.data7;
21    com.parity = Parity.even;
22    com.stopBits = StopBits.two;
23 
24    //string test = "Hello, World!\n";
25    //com.write(test.ptr);
26    ubyte[] test = [0x40, 0x30, 0x30, 0x52, 0x0d];
27    com.write(test);
28    //string message = "abc\n";
29    //com.write(cast(void[])message);
30 }
31 
32 void testParity() {
33    string port = "/dev/ttyS2";
34    version(Windows) {
35       port = "COM1";
36    }
37    Duration timeout = dur!("msecs")(2000);
38 
39    auto com = new serial.device.SerialPort(port, timeout, timeout);
40    scope (exit) com.close;
41 
42    com.speed = BaudRate.BR_115200;
43    com.dataBits = DataBits.data7;
44 
45    com.parity = Parity.even;
46    //assert(com.parity == Parity.even);
47    com.parity.shouldEqual(Parity.even);
48 
49    com.parity = Parity.odd;
50    assert(com.parity == Parity.odd);
51    com.parity.shouldEqual(Parity.odd);
52 
53    com.parity = Parity.none;
54    assert(com.parity == Parity.none);
55 
56 }
57 
58 void testBits() {
59    string port = "/dev/ttyS0";
60    version(Windows) {
61       port = "COM1";
62    }
63    Duration timeout = dur!("msecs")(2000);
64 
65    auto com = new serial.device.SerialPort(port, timeout, timeout);
66    scope (exit) com.close;
67 
68    com.speed = BaudRate.BR_115200;
69    com.parity = Parity.even;
70 
71    com.dataBits = DataBits.data7;
72    assert(com.dataBits == DataBits.data7);
73 
74    com.dataBits = DataBits.data6;
75    assert(com.dataBits == DataBits.data6);
76 
77    com.dataBits = DataBits.data5;
78    assert(com.dataBits == DataBits.data5);
79 
80 }