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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 43 by torben, Sun Feb 4 20:11:41 2007 UTC revision 67 by torben, Tue Feb 6 23:37:39 2007 UTC
# Line 1  Line 1 
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
# Line 12  Line 17 
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;
# Line 23  void pause() Line 28  void pause()
28    
29  }  }
30    
31  int main()  int main(int argc, char* argv[])
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            if (argc != 2)
38            {
39                    std::cout << "Usage: " << argv[0] << "<serial port>" << std::endl;
40                    exit(0);
41            }
42                    
43          try          try
44          {          {
45                  // tænd lysdiode S3 / RB1                  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                                    std::cout << "Switch2:" << serial.readTarget(4) << std::endl;
52                            }
53                            catch (timeout_error& e)
54                            {
55                                    std::cout << "Restarting ..." << std::endl;
56                                    serial.close();
57                                    Sleep(50);
58                                    serial.open(argv[1], CSerial::Baud9600);
59                                    Sleep(50);
60                            }
61                            std::cout << count++ << std::endl;
62                            Sleep(50);
63                    }
64    
65                    serial.open(argv[1], CSerial::Baud9600);
66                    // tænd lysdiode S3&S4 / RB1&RB2
67                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
68                  serial.writeTarget(0,1);                  serial.writeTarget(0,1);
69                    std::cout << "-";      
70                    serial.writeTarget(1,1);        
71                  Sleep(2000);                  Sleep(2000);
72    
73                  // sluk lysdiode S3 / RB1                  // sluk lysdiode S3 / RB1
74                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
75                  serial.writeTarget(0,0);                  serial.writeTarget(0,0);
76                  Sleep(2000);                  Sleep(200);
77    
78                  //Aflæser potmeter ved 9600 bps                  //Aflæser potmeter ved 9600 bps
79                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
80                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
81    
82                    
83                  //Skifter hastighed til 19200 bps                  //Skifter hastighed til 19200 bps
84                  serial.writeTarget(10, 4);                  serial.writeTarget(10, 4);
85                  Sleep(100);                  Sleep(100);
86                  serial.close();                  serial.close();
87                  serial.open("com8", 19200);                  serial.open(argv[1], CSerial::Baud19200);
88    
89                  //aflæser potmeter ved 19200 bps                  //aflæser potmeter ved 19200 bps
90                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
# Line 61  int main() Line 96  int main()
96                  Sleep(500);                  Sleep(500);
97    
98                  serial.close();                  serial.close();
99                  serial.open("com8",9600);                  serial.open(argv[1], CSerial::Baud9600);
100    
101                  //aflæser potmeter igen ved 9600 bps                  //aflæser potmeter igen ved 9600 bps
102                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
103                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
104          } catch (std::exception e)                  
105            }
106            catch (std::runtime_error& e)
107            {
108                    std::cout << "Error: " << e.what() << std::endl;
109                    exit(1);
110            }
111            catch (std::exception& e)
112            {
113                    std::cout << "Exception: " << e.what() << std::endl;
114                    exit(2);
115            }
116            catch(...)
117          {          {
118                  std::cout << "Exception :" << e.what() << std::endl;                  std::cout << "asd" << std::endl;
119                    exit(3);
120          }          }
121    
122          //std::cout << serial.readTarget(2) << std::endl;          //std::cout << serial.readTarget(2) << std::endl;
123    
124    
125          pause();          my_pause();
126          return 0;          return 0;
127  }  }
128    

Legend:
Removed from v.43  
changed lines
  Added in v.67

  ViewVC Help
Powered by ViewVC 1.1.20