1 |
// serial1.cpp : Defines the entry point for the console application.
|
2 |
//
|
3 |
|
4 |
#ifdef _MSC_VER
|
5 |
#include "serial1.h"
|
6 |
#endif
|
7 |
|
8 |
#include "stdafx.h"
|
9 |
|
10 |
|
11 |
#ifdef _DEBUG
|
12 |
#define new DEBUG_NEW
|
13 |
#endif
|
14 |
|
15 |
#include "H7Serial.h"
|
16 |
|
17 |
#include <iostream>
|
18 |
#include <iomanip>
|
19 |
#include <exception>
|
20 |
#include <stdexcept>
|
21 |
|
22 |
|
23 |
void my_pause()
|
24 |
{
|
25 |
char d[1];
|
26 |
std::cout << "Press enter to continue" << std::endl;
|
27 |
std::cin.getline(d,1);
|
28 |
|
29 |
}
|
30 |
|
31 |
int main(int argc, char* argv[])
|
32 |
{
|
33 |
int count = 0;
|
34 |
unsigned char c,input;
|
35 |
CH7Serial serial;
|
36 |
|
37 |
if (argc != 2)
|
38 |
{
|
39 |
std::cout << "Usage: " << argv[0] << "<serial port>" << std::endl;
|
40 |
exit(0);
|
41 |
}
|
42 |
|
43 |
try
|
44 |
{
|
45 |
|
46 |
serial.open(argv[1], CSerial::Baud9600);
|
47 |
// tænd lysdiode S3&S4 / RB1&RB2
|
48 |
std::cout << "--------------------------------------" << std::endl;
|
49 |
serial.writeTarget(0,1);
|
50 |
std::cout << "-";
|
51 |
serial.writeTarget(1,1);
|
52 |
Sleep(2000);
|
53 |
|
54 |
// sluk lysdiode S3 / RB1
|
55 |
std::cout << "--------------------------------------" << std::endl;
|
56 |
serial.writeTarget(0,0);
|
57 |
Sleep(200);
|
58 |
|
59 |
//Aflæser potmeter ved 9600 bps
|
60 |
std::cout << "--------------------------------------" << std::endl;
|
61 |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
|
62 |
|
63 |
|
64 |
//Skifter hastighed til 19200 bps
|
65 |
serial.writeTarget(10, 4);
|
66 |
Sleep(100);
|
67 |
serial.close();
|
68 |
serial.open(argv[1], CSerial::Baud19200);
|
69 |
|
70 |
//aflæser potmeter ved 19200 bps
|
71 |
std::cout << "--------------------------------------" << std::endl;
|
72 |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
|
73 |
Sleep(7000);
|
74 |
|
75 |
// skiver hastighed tilbage til 9600 bps
|
76 |
serial.writeTarget(10,3);
|
77 |
Sleep(500);
|
78 |
|
79 |
serial.close();
|
80 |
serial.open(argv[1], CSerial::Baud9600);
|
81 |
|
82 |
//aflæser potmeter igen ved 9600 bps
|
83 |
std::cout << "--------------------------------------" << std::endl;
|
84 |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
|
85 |
|
86 |
}
|
87 |
catch (std::runtime_error& e)
|
88 |
{
|
89 |
std::cout << "Error: " << e.what() << std::endl;
|
90 |
exit(1);
|
91 |
}
|
92 |
catch (std::exception& e)
|
93 |
{
|
94 |
std::cout << "Exception: " << e.what() << std::endl;
|
95 |
exit(2);
|
96 |
}
|
97 |
catch(...)
|
98 |
{
|
99 |
std::cout << "asd" << std::endl;
|
100 |
exit(3);
|
101 |
}
|
102 |
|
103 |
//std::cout << serial.readTarget(2) << std::endl;
|
104 |
|
105 |
|
106 |
my_pause();
|
107 |
return 0;
|
108 |
}
|
109 |
|