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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (hide annotations) (download)
Mon Feb 5 07:06:43 2007 UTC (17 years, 4 months ago) by torben
File size: 2072 byte(s)
Test against the correct #define macro (_WINDOWS -> _MSC_VER)
1 torben 38 // serial1.cpp : Defines the entry point for the console application.
2     //
3    
4 torben 49 #ifdef _MSC_VER
5 torben 38 #include "serial1.h"
6 torben 44 #endif
7    
8 torben 49 #include "stdafx.h"
9 torben 44
10 torben 49
11 torben 38 #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 torben 46 #include <stdexcept>
21 torben 38
22    
23 torben 44 void my_pause()
24 torben 38 {
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()
32     {
33     int count = 0;
34     unsigned char c,input;
35 torben 46 CH7Serial serial;
36 torben 38
37     try
38     {
39 torben 49
40     serial.open("COM8", 9600);
41 torben 38 // tænd lysdiode S3 / RB1
42     std::cout << "--------------------------------------" << std::endl;
43 torben 47 serial.writeTarget(1,1);
44     std::cout << "-";
45 torben 38 Sleep(2000);
46    
47     // sluk lysdiode S3 / RB1
48     std::cout << "--------------------------------------" << std::endl;
49 torben 47 serial.writeTarget(0,1);
50     Sleep(200);
51 torben 38
52     //Aflæser potmeter ved 9600 bps
53     std::cout << "--------------------------------------" << std::endl;
54     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
55    
56 torben 47 /*
57 torben 38 //Skifter hastighed til 19200 bps
58     serial.writeTarget(10, 4);
59     Sleep(100);
60     serial.close();
61     serial.open("com8", 19200);
62    
63     //aflæser potmeter ved 19200 bps
64     std::cout << "--------------------------------------" << std::endl;
65     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
66     Sleep(7000);
67    
68     // skiver hastighed tilbage til 9600 bps
69     serial.writeTarget(10,3);
70     Sleep(500);
71    
72     serial.close();
73     serial.open("com8",9600);
74    
75     //aflæser potmeter igen ved 9600 bps
76     std::cout << "--------------------------------------" << std::endl;
77     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
78 torben 46 */
79     }
80     catch (std::runtime_error& e)
81 torben 38 {
82 torben 46 std::cout << "Error: " << e.what() << std::endl;
83     exit(1);
84 torben 38 }
85 torben 46 catch (std::exception& e)
86     {
87     std::cout << "Exception: " << e.what() << std::endl;
88     exit(2);
89     }
90     catch(...)
91     {
92     std::cout << "asd" << std::endl;
93     exit(3);
94     }
95 torben 38
96     //std::cout << serial.readTarget(2) << std::endl;
97    
98    
99 torben 44 my_pause();
100 torben 38 return 0;
101     }
102    

  ViewVC Help
Powered by ViewVC 1.1.20