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

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

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

trunk/PIC/Testprogram/H7Serial.cpp revision 38 by torben, Thu Feb 1 10:03:52 2007 UTC branches/linux-serial/H7Serial.cpp revision 46 by torben, Sun Feb 4 23:11:02 2007 UTC
# Line 1  Line 1 
1    
2    #ifdef _WINDOWS
3  #include "StdAfx.h"  #include "StdAfx.h"
4  #include ".\h7serial.h"  #endif
5    
6    #include "H7Serial.h"
7    #include <stdexcept>
8    #include <iostream>
9    
10  CH7Serial::CH7Serial(void)  CH7Serial::CH7Serial(void)
11  : CSlipSerial()  : CSlipSerial()
# Line 17  CH7Serial::~CH7Serial(void) Line 23  CH7Serial::~CH7Serial(void)
23    
24  short CH7Serial::readTarget(unsigned char target)  short CH7Serial::readTarget(unsigned char target)
25  {  {
26            using namespace std;
27            cout << "read start" << endl;
28          short retval;          short retval;
29          unsigned char frame[1];          unsigned char frame[1];
30          unsigned char hi_target = (target & 0x0F) << 4;          unsigned char hi_target = (target & 0x0F) << 4;
31          frame[0] = hi_target | 0x00;          frame[0] = hi_target | 0x00;
32    
33          writeFrame(frame,1);          writeFrame(frame,1);
34            cout << "read mid" << endl;
35          Sleep(50); //be nice and wait a little          Sleep(50); //be nice and wait a little
36          std::vector<unsigned char> answer = readFrame();          std::vector<unsigned char> answer = readFrame();
37            cout << "read done" << endl;
38    
39          if (answer.size() == 0)          if (answer.size() == 0)
40                  throw std::exception("No reply");                  throw std::runtime_error("No reply");
41    
42          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK
43                  throw std::exception("Request not acknowledged");                  throw std::runtime_error("Request not acknowledged");
44    
45          if ( (answer[0] & 0xF0) != hi_target)          if ( (answer[0] & 0xF0) != hi_target)
46                  throw std::exception("Incorrect reply");                  throw std::runtime_error("Incorrect reply");
47    
48          if (answer.size() == 2)          if (answer.size() == 2)
49                  retval = answer[1];                  retval = answer[1];
# Line 47  short CH7Serial::readTarget(unsigned cha Line 57  short CH7Serial::readTarget(unsigned cha
57    
58  void CH7Serial::writeTarget(unsigned char target, unsigned char data)  void CH7Serial::writeTarget(unsigned char target, unsigned char data)
59  {  {
60            using namespace std;
61          unsigned char frame[2];          unsigned char frame[2];
62          unsigned char hi_target = (target & 0x0F) << 4;          unsigned char hi_target = (target & 0x0F) << 4;
63          frame[0] = hi_target | 0x01;          frame[0] = hi_target | 0x01;
64          frame[1] = data;          frame[1] = data;
65            cout << "write start" << endl;
66    
67          writeFrame(frame,2);          writeFrame(frame,2);
68            cout << "write mid" << endl;
69          Sleep(50); //be nice and wait a little          Sleep(50); //be nice and wait a little
70          std::vector<unsigned char> answer = readFrame();          std::vector<unsigned char> answer = readFrame();
71            
72            cout << "write stop" << endl;
73          if (answer.size() == 0)          if (answer.size() == 0)
74                  throw std::exception("No reply");                  throw std::runtime_error("No reply");
75    
76          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK          if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK
77                  throw std::exception("Request not acknowledged");                  throw std::runtime_error("Request not acknowledged");
78    
79          if ( (answer[0] & 0xF0) != hi_target)          if ( (answer[0] & 0xF0) != hi_target)
80                  throw std::exception("Incorrect reply");                  throw std::runtime_error("Incorrect reply");
81  }  }
82    
83    

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

  ViewVC Help
Powered by ViewVC 1.1.20