/[H7]/trunk/PIC/Testprogram/serial1.cpp
ViewVC logotype

Contents of /trunk/PIC/Testprogram/serial1.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations) (download)
Thu Feb 1 10:03:52 2007 UTC (17 years, 3 months ago) by torben
File size: 1792 byte(s)
Added test-program for  serial communication module
1 // serial1.cpp : Defines the entry point for the console application.
2 //
3
4 #include "stdafx.h"
5 #include "serial1.h"
6 #ifdef _DEBUG
7 #define new DEBUG_NEW
8 #endif
9
10 #include "H7Serial.h"
11
12 #include <iostream>
13 #include <iomanip>
14 #include <exception>
15
16 #include <conio.h>
17
18 void pause()
19 {
20 char d[1];
21 std::cout << "Press enter to continue" << std::endl;
22 std::cin.getline(d,1);
23
24 }
25
26 int main()
27 {
28 int count = 0;
29 unsigned char c,input;
30 CH7Serial serial("com8", 9600);
31
32 try
33 {
34 // tænd lysdiode S3 / RB1
35 std::cout << "--------------------------------------" << std::endl;
36 serial.writeTarget(0,1);
37 Sleep(2000);
38
39 // sluk lysdiode S3 / RB1
40 std::cout << "--------------------------------------" << std::endl;
41 serial.writeTarget(0,0);
42 Sleep(2000);
43
44 //Aflæser potmeter ved 9600 bps
45 std::cout << "--------------------------------------" << std::endl;
46 std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
47
48 //Skifter hastighed til 19200 bps
49 serial.writeTarget(10, 4);
50 Sleep(100);
51 serial.close();
52 serial.open("com8", 19200);
53
54 //aflæser potmeter ved 19200 bps
55 std::cout << "--------------------------------------" << std::endl;
56 std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
57 Sleep(7000);
58
59 // skiver hastighed tilbage til 9600 bps
60 serial.writeTarget(10,3);
61 Sleep(500);
62
63 serial.close();
64 serial.open("com8",9600);
65
66 //aflæser potmeter igen ved 9600 bps
67 std::cout << "--------------------------------------" << std::endl;
68 std::cout << "Potmeter: " << serial.readTarget(5) << std::endl;
69 } catch (std::exception e)
70 {
71 std::cout << "Exception :" << e.what() << std::endl;
72 }
73
74 //std::cout << serial.readTarget(2) << std::endl;
75
76
77 pause();
78 return 0;
79 }
80

  ViewVC Help
Powered by ViewVC 1.1.20