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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide annotations) (download)
Sun Feb 4 23:11:02 2007 UTC (17 years, 4 months ago) by torben
File size: 2054 byte(s)
First take at making this linux-serial-thingie work...


1 torben 38 // serial1.cpp : Defines the entry point for the console application.
2     //
3    
4 torben 44 #ifdef _WINDOWS
5 torben 38 #include "stdafx.h"
6 torben 44
7 torben 38 #include "serial1.h"
8 torben 44 #endif
9    
10    
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 46 serial.open("/dev/ttyS0", 9600);
40 torben 38 // tænd lysdiode S3 / RB1
41     std::cout << "--------------------------------------" << std::endl;
42     serial.writeTarget(0,1);
43 torben 46 /*
44 torben 38 Sleep(2000);
45    
46     // sluk lysdiode S3 / RB1
47     std::cout << "--------------------------------------" << std::endl;
48     serial.writeTarget(0,0);
49     Sleep(2000);
50    
51     //Aflæser potmeter ved 9600 bps
52     std::cout << "--------------------------------------" << std::endl;
53     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
54    
55     //Skifter hastighed til 19200 bps
56     serial.writeTarget(10, 4);
57     Sleep(100);
58     serial.close();
59     serial.open("com8", 19200);
60    
61     //aflæser potmeter ved 19200 bps
62     std::cout << "--------------------------------------" << std::endl;
63     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
64     Sleep(7000);
65    
66     // skiver hastighed tilbage til 9600 bps
67     serial.writeTarget(10,3);
68     Sleep(500);
69    
70     serial.close();
71     serial.open("com8",9600);
72    
73     //aflæser potmeter igen ved 9600 bps
74     std::cout << "--------------------------------------" << std::endl;
75     std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
76 torben 46 */
77     }
78     catch (std::runtime_error& e)
79 torben 38 {
80 torben 46 std::cout << "Error: " << e.what() << std::endl;
81     exit(1);
82 torben 38 }
83 torben 46 catch (std::exception& e)
84     {
85     std::cout << "Exception: " << e.what() << std::endl;
86     exit(2);
87     }
88     catch(...)
89     {
90     std::cout << "asd" << std::endl;
91     exit(3);
92     }
93 torben 38
94     //std::cout << serial.readTarget(2) << std::endl;
95    
96    
97 torben 44 my_pause();
98 torben 38 return 0;
99     }
100    

  ViewVC Help
Powered by ViewVC 1.1.20