1 |
// serial1.cpp : Defines the entry point for the console application. |
// serial1.cpp : Defines the entry point for the console application. |
2 |
// |
// |
3 |
|
|
4 |
#include "stdafx.h" |
#ifdef _MSC_VER |
5 |
#include "serial1.h" |
#include "serial1.h" |
6 |
|
#endif |
7 |
|
|
8 |
|
#include "stdafx.h" |
9 |
|
|
10 |
|
|
11 |
#ifdef _DEBUG |
#ifdef _DEBUG |
12 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
13 |
#endif |
#endif |
17 |
#include <iostream> |
#include <iostream> |
18 |
#include <iomanip> |
#include <iomanip> |
19 |
#include <exception> |
#include <exception> |
20 |
|
#include <stdexcept> |
21 |
|
|
|
#include <conio.h> |
|
22 |
|
|
23 |
void pause() |
void my_pause() |
24 |
{ |
{ |
25 |
char d[1]; |
char d[1]; |
26 |
std::cout << "Press enter to continue" << std::endl; |
std::cout << "Press enter to continue" << std::endl; |
32 |
{ |
{ |
33 |
int count = 0; |
int count = 0; |
34 |
unsigned char c,input; |
unsigned char c,input; |
35 |
CH7Serial serial("com8", 9600); |
CH7Serial serial; |
36 |
|
|
37 |
try |
try |
38 |
{ |
{ |
39 |
|
|
40 |
|
serial.open("COM8", 9600); |
41 |
// tænd lysdiode S3 / RB1 |
// tænd lysdiode S3 / RB1 |
42 |
std::cout << "--------------------------------------" << std::endl; |
std::cout << "--------------------------------------" << std::endl; |
43 |
serial.writeTarget(0,1); |
serial.writeTarget(1,1); |
44 |
|
std::cout << "-"; |
45 |
Sleep(2000); |
Sleep(2000); |
46 |
|
|
47 |
// sluk lysdiode S3 / RB1 |
// sluk lysdiode S3 / RB1 |
48 |
std::cout << "--------------------------------------" << std::endl; |
std::cout << "--------------------------------------" << std::endl; |
49 |
serial.writeTarget(0,0); |
serial.writeTarget(0,1); |
50 |
Sleep(2000); |
Sleep(200); |
51 |
|
|
52 |
//Aflæser potmeter ved 9600 bps |
//Aflæser potmeter ved 9600 bps |
53 |
std::cout << "--------------------------------------" << std::endl; |
std::cout << "--------------------------------------" << std::endl; |
54 |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl; |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl; |
55 |
|
|
56 |
|
/* |
57 |
//Skifter hastighed til 19200 bps |
//Skifter hastighed til 19200 bps |
58 |
serial.writeTarget(10, 4); |
serial.writeTarget(10, 4); |
59 |
Sleep(100); |
Sleep(100); |
75 |
//aflæser potmeter igen ved 9600 bps |
//aflæser potmeter igen ved 9600 bps |
76 |
std::cout << "--------------------------------------" << std::endl; |
std::cout << "--------------------------------------" << std::endl; |
77 |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl; |
std::cout << "Potmeter: " << serial.readTarget(5) << std::endl; |
78 |
} catch (std::exception e) |
*/ |
79 |
|
} |
80 |
|
catch (std::runtime_error& e) |
81 |
|
{ |
82 |
|
std::cout << "Error: " << e.what() << std::endl; |
83 |
|
exit(1); |
84 |
|
} |
85 |
|
catch (std::exception& e) |
86 |
|
{ |
87 |
|
std::cout << "Exception: " << e.what() << std::endl; |
88 |
|
exit(2); |
89 |
|
} |
90 |
|
catch(...) |
91 |
{ |
{ |
92 |
std::cout << "Exception :" << e.what() << std::endl; |
std::cout << "asd" << std::endl; |
93 |
|
exit(3); |
94 |
} |
} |
95 |
|
|
96 |
//std::cout << serial.readTarget(2) << std::endl; |
//std::cout << serial.readTarget(2) << std::endl; |
97 |
|
|
98 |
|
|
99 |
pause(); |
my_pause(); |
100 |
return 0; |
return 0; |
101 |
} |
} |
102 |
|
|