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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63 - (hide annotations) (download)
Tue Feb 6 14:01:59 2007 UTC (17 years, 3 months ago) by torben
File size: 2687 byte(s)
Added another test-case for stress-testing the communication

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 torben 52 int main(int argc, char* argv[])
32 torben 38 {
33     int count = 0;
34     unsigned char c,input;
35 torben 46 CH7Serial serial;
36 torben 52
37     if (argc != 2)
38     {
39     std::cout << "Usage: " << argv[0] << "<serial port>" << std::endl;
40     exit(0);
41     }
42 torben 38
43     try
44     {
45 torben 63 int count =0;
46     serial.open(argv[1], CSerial::Baud9600);
47     while(1)
48     {
49     try{
50     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
51     }
52     catch (timeout_error& e)
53     {
54     std::cout << "Restarting ..." << std::endl;
55     serial.close();
56     Sleep(50);
57     serial.open(argv[1], CSerial::Baud9600);
58     Sleep(50);
59     }
60     std::cout << count++ << std::endl;
61     Sleep(50);
62     }
63 torben 49
64 torben 54 serial.open(argv[1], CSerial::Baud9600);
65     // tænd lysdiode S3&S4 / RB1&RB2
66 torben 38 std::cout << "--------------------------------------" << std::endl;
67 torben 54 serial.writeTarget(0,1);
68     std::cout << "-";
69     serial.writeTarget(1,1);
70 torben 38 Sleep(2000);
71    
72     // sluk lysdiode S3 / RB1
73     std::cout << "--------------------------------------" << std::endl;
74 torben 54 serial.writeTarget(0,0);
75 torben 47 Sleep(200);
76 torben 38
77     //Aflæser potmeter ved 9600 bps
78     std::cout << "--------------------------------------" << std::endl;
79     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
80    
81 torben 54
82 torben 38 //Skifter hastighed til 19200 bps
83     serial.writeTarget(10, 4);
84     Sleep(100);
85     serial.close();
86 torben 54 serial.open(argv[1], CSerial::Baud19200);
87 torben 38
88     //aflæser potmeter ved 19200 bps
89     std::cout << "--------------------------------------" << std::endl;
90     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
91     Sleep(7000);
92    
93     // skiver hastighed tilbage til 9600 bps
94     serial.writeTarget(10,3);
95     Sleep(500);
96    
97     serial.close();
98 torben 54 serial.open(argv[1], CSerial::Baud9600);
99 torben 38
100     //aflæser potmeter igen ved 9600 bps
101     std::cout << "--------------------------------------" << std::endl;
102     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
103 torben 54
104 torben 46 }
105     catch (std::runtime_error& e)
106 torben 38 {
107 torben 46 std::cout << "Error: " << e.what() << std::endl;
108     exit(1);
109 torben 38 }
110 torben 46 catch (std::exception& e)
111     {
112     std::cout << "Exception: " << e.what() << std::endl;
113     exit(2);
114     }
115     catch(...)
116     {
117     std::cout << "asd" << std::endl;
118     exit(3);
119     }
120 torben 38
121     //std::cout << serial.readTarget(2) << std::endl;
122    
123    
124 torben 44 my_pause();
125 torben 38 return 0;
126     }
127    

  ViewVC Help
Powered by ViewVC 1.1.20