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

revision 45 by torben, Sun Feb 4 21:22:44 2007 UTC revision 46 by torben, Sun Feb 4 23:11:02 2007 UTC
# Line 5  Line 5 
5    
6  #include "H7Serial.h"  #include "H7Serial.h"
7  #include <stdexcept>  #include <stdexcept>
8    #include <iostream>
9    
10  CH7Serial::CH7Serial(void)  CH7Serial::CH7Serial(void)
11  : CSlipSerial()  : CSlipSerial()
# Line 22  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::runtime_error("No reply");                  throw std::runtime_error("No reply");
# Line 52  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::runtime_error("No reply");                  throw std::runtime_error("No reply");
75    

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

  ViewVC Help
Powered by ViewVC 1.1.20