/[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

trunk/PIC/Testprogram/serial1.cpp revision 38 by torben, Thu Feb 1 10:03:52 2007 UTC branches/linux-serial/serial1.cpp revision 47 by torben, Mon Feb 5 00:48:02 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
5  #include "stdafx.h"  #include "stdafx.h"
6    
7  #include "serial1.h"  #include "serial1.h"
8    #endif
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 27  int main() Line 32  int main()
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          try          try
38          {          {
39                    serial.open("/dev/ttyUSB0", 9600);
40                  // tænd lysdiode S3 / RB1                  // tænd lysdiode S3 / RB1
41                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
42                  serial.writeTarget(0,1);                  serial.writeTarget(1,1);
43                    std::cout << "-";              
44                  Sleep(2000);                  Sleep(2000);
45    
46                  // sluk lysdiode S3 / RB1                  // sluk lysdiode S3 / RB1
47                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
48                  serial.writeTarget(0,0);                  serial.writeTarget(0,1);
49                  Sleep(2000);                  Sleep(200);
50    
51                  //Aflæser potmeter ved 9600 bps                  //Aflæser potmeter ved 9600 bps
52                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
53                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
54    
55                    /*
56                  //Skifter hastighed til 19200 bps                  //Skifter hastighed til 19200 bps
57                  serial.writeTarget(10, 4);                  serial.writeTarget(10, 4);
58                  Sleep(100);                  Sleep(100);
# Line 66  int main() Line 74  int main()
74                  //aflæser potmeter igen ved 9600 bps                  //aflæser potmeter igen ved 9600 bps
75                  std::cout << "--------------------------------------" << std::endl;                  std::cout << "--------------------------------------" << std::endl;
76                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;                  std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
77          } catch (std::exception e)                  */
78            }
79            catch (std::runtime_error& e)
80            {
81                    std::cout << "Error: " << e.what() << std::endl;
82                    exit(1);
83            }
84            catch (std::exception& e)
85            {
86                    std::cout << "Exception: " << e.what() << std::endl;
87                    exit(2);
88            }
89            catch(...)
90          {          {
91                  std::cout << "Exception :" << e.what() << std::endl;                  std::cout << "asd" << std::endl;
92                    exit(3);
93          }          }
94    
95          //std::cout << serial.readTarget(2) << std::endl;          //std::cout << serial.readTarget(2) << std::endl;
96    
97    
98          pause();          my_pause();
99          return 0;          return 0;
100  }  }
101    

Legend:
Removed from v.38  
changed lines
  Added in v.47

  ViewVC Help
Powered by ViewVC 1.1.20