/[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 44 by torben, Sun Feb 4 21:22:44 2007 UTC revision 52 by torben, Mon Feb 5 07:22:10 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  #ifdef _WINDOWS  #ifdef _MSC_VER
 #include "stdafx.h"  
   
5  #include "serial1.h"  #include "serial1.h"
6  #endif  #endif
7    
8    #include "stdafx.h"
9    
10    
11  #ifdef _DEBUG  #ifdef _DEBUG
12  #define new DEBUG_NEW  #define new DEBUG_NEW
# Line 17  Line 17 
17  #include <iostream>  #include <iostream>
18  #include <iomanip>  #include <iomanip>
19  #include <exception>  #include <exception>
20    #include <stdexcept>
21    
22    
23  void my_pause()  void my_pause()
# Line 27  void my_pause() Line 28  void my_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    
46                    serial.open(argv[1], 9600);
47                  // tænd lysdiode S3 / RB1                  // tænd lysdiode S3 / RB1
48                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
49                  serial.writeTarget(0,1);                  serial.writeTarget(1,1);
50                    std::cout << "-";              
51                  Sleep(2000);                  Sleep(2000);
52    
53                  // sluk lysdiode S3 / RB1                  // sluk lysdiode S3 / RB1
54                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
55                  serial.writeTarget(0,0);                  serial.writeTarget(0,1);
56                  Sleep(2000);                  Sleep(200);
57    
58                  //Aflæser potmeter ved 9600 bps                  //Aflæser potmeter ved 9600 bps
59                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
60                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
61    
62                    /*
63                  //Skifter hastighed til 19200 bps                  //Skifter hastighed til 19200 bps
64                  serial.writeTarget(10, 4);                  serial.writeTarget(10, 4);
65                  Sleep(100);                  Sleep(100);
# Line 70  int main() Line 81  int main()
81                  //aflæser potmeter igen ved 9600 bps                  //aflæser potmeter igen ved 9600 bps
82                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
83                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
84          } catch (std::exception e)                  */
85            }
86            catch (std::runtime_error& e)
87            {
88                    std::cout << "Error: " << e.what() << std::endl;
89                    exit(1);
90            }
91            catch (std::exception& e)
92            {
93                    std::cout << "Exception: " << e.what() << std::endl;
94                    exit(2);
95            }
96            catch(...)
97          {          {
98                  std::cout << "Exception :" << e.what() << std::endl;                  std::cout << "asd" << std::endl;
99                    exit(3);
100          }          }
101    
102          //std::cout << serial.readTarget(2) << std::endl;          //std::cout << serial.readTarget(2) << std::endl;

Legend:
Removed from v.44  
changed lines
  Added in v.52

  ViewVC Help
Powered by ViewVC 1.1.20