Skip to content

Commit 6f75925

Browse files
committed
добавлена первая версия кода
1 parent 9a8531d commit 6f75925

File tree

6 files changed

+1603
-0
lines changed

6 files changed

+1603
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.depend
2+
*.layout
3+
*.o
51 KB
Binary file not shown.

example/com_port/com_port.cbp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="com_port" />
6+
<Option pch_mode="2" />
7+
<Option compiler="mingw_64_7_3_0" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="bin/Debug/com_port" prefix_auto="1" extension_auto="1" />
11+
<Option object_output="obj/Debug/" />
12+
<Option type="1" />
13+
<Option compiler="mingw_64_7_3_0" />
14+
<Compiler>
15+
<Add option="-g" />
16+
<Add directory="../../src" />
17+
</Compiler>
18+
<Linker>
19+
<Add directory="../../src" />
20+
</Linker>
21+
</Target>
22+
<Target title="Release">
23+
<Option output="bin/Release/com_port" prefix_auto="1" extension_auto="1" />
24+
<Option object_output="obj/Release/" />
25+
<Option type="1" />
26+
<Option compiler="mingw_64_7_3_0" />
27+
<Compiler>
28+
<Add option="-O2" />
29+
<Add directory="../../src" />
30+
</Compiler>
31+
<Linker>
32+
<Add option="-s" />
33+
<Add directory="../../src" />
34+
</Linker>
35+
</Target>
36+
</Build>
37+
<Compiler>
38+
<Add option="-Wall" />
39+
<Add option="-fexceptions" />
40+
</Compiler>
41+
<Unit filename="../../src/xserial.cpp" />
42+
<Unit filename="../../src/xserial.hpp" />
43+
<Unit filename="main.cpp" />
44+
<Extensions>
45+
<code_completion />
46+
<envvars />
47+
<debugger />
48+
<lib_finder disable_auto="1" />
49+
</Extensions>
50+
</Project>
51+
</CodeBlocks_project_file>

example/com_port/main.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include "xserial.hpp"
3+
using namespace std;
4+
5+
int main() {
6+
cout << "Hello world!" << endl;
7+
// инициализируем доступный COM порт, без проверки бита четности, с 8-мью битами данных и одним стоп битом.
8+
xserial::ComPort com(115200,com.COM_PORT_NOPARITY, 8, com.COM_PORT_ONESTOPBIT);
9+
10+
if (!com.getStateComPort()) { // Если порт не открылся
11+
cout << "Error: com port is not open!" << endl;
12+
return 0;
13+
}
14+
15+
// выводим список доступых портов
16+
com.printListSerialPorts();
17+
18+
// получаем текст до символа \n
19+
cout << "Test getLine()..." << endl;
20+
com << "Test 1\n";
21+
cout << com.getLine() << endl;
22+
23+
// проверяем функцию проверки количества принятых байт
24+
cout << "Test bytesToRead()..." << endl;
25+
com.print("Test 2\n");
26+
int k = com.bytesToRead();
27+
cout << "bytes to read = " << k << endl;
28+
while(k < 6) {
29+
k = com.bytesToRead();
30+
}
31+
cout << "bytes to read = " << k << endl;
32+
33+
// проверяем функцию чтения
34+
char data[512];
35+
cout << "Test read()..." << endl;
36+
com.read(data, 7);
37+
cout << data << endl;
38+
39+
// проверяем функцию чтения слова
40+
com.print("Bla Bla Bla\n");
41+
cout << "Test getWord(), print Bla Bla Bla" << endl;
42+
cout << "Word 1: " << com.getWord() << endl;
43+
cout << "Word 2: " << com.getWord() << endl;
44+
cout << "Word 3: " << com.getWord() << endl;
45+
46+
return 0;
47+
}

0 commit comments

Comments
 (0)