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() |
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"); |
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 |
|
|