/[H7]/branches/linux-serial/serial1.cpp
ViewVC logotype

Contents of /branches/linux-serial/serial1.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (show annotations) (download)
Sun Feb 4 21:22:44 2007 UTC (17 years, 3 months ago) by torben
File size: 1809 byte(s)
Clean the MFC heavy code, so it at least will compile with G++


1 // serial1.cpp : Defines the entry point for the console application.
2 //
3
4 #ifdef _WINDOWS
5 #include "stdafx.h"
6
7 #include "serial1.h"
8 #endif
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
21
22 void my_pause()
23 {
24 char d[1];
25 std::cout << "Press enter to continue" << std::endl;
26 std::cin.getline(d,1);
27
28 }
29
30 int main()
31 {
32 int count = 0;
33 unsigned char c,input;
34 CH7Serial serial("com8", 9600);
35
36 try
37 {
38 // tænd lysdiode S3 / RB1
39 std::cout << "--------------------------------------" << std::endl;
40 serial.writeTarget(0,1);
41 Sleep(2000);
42
43 // sluk lysdiode S3 / RB1
44 std::cout << "--------------------------------------" << std::endl;
45 serial.writeTarget(0,0);
46 Sleep(2000);
47
48 //Aflæser potmeter ved 9600 bps
49 std::cout << "--------------------------------------" << std::endl;
50 std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
51
52 //Skifter hastighed til 19200 bps
53 serial.writeTarget(10, 4);
54 Sleep(100);
55 serial.close();
56 serial.open("com8", 19200);
57
58 //aflæser potmeter ved 19200 bps
59 std::cout << "--------------------------------------" << std::endl;
60 std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
61 Sleep(7000);
62
63 // skiver hastighed tilbage til 9600 bps
64 serial.writeTarget(10,3);
65 Sleep(500);
66
67 serial.close();
68 serial.open("com8",9600);
69
70 //aflæser potmeter igen ved 9600 bps
71 std::cout << "--------------------------------------" << std::endl;
72 std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
73 } catch (std::exception e)
74 {
75 std::cout << "Exception :" << e.what() << std::endl;
76 }
77
78 //std::cout << serial.readTarget(2) << std::endl;
79
80
81 my_pause();
82 return 0;
83 }
84

  ViewVC Help
Powered by ViewVC 1.1.20