22 |
short CH7Serial::readTarget(unsigned char target) |
short CH7Serial::readTarget(unsigned char target) |
23 |
{ |
{ |
24 |
using namespace std; |
using namespace std; |
|
cout << "read start" << endl; |
|
25 |
short retval; |
short retval; |
26 |
unsigned char frame[1]; |
unsigned char frame[1]; |
27 |
unsigned char hi_target = (target & 0x0F) << 4; |
unsigned char hi_target = (target & 0x0F) << 4; |
28 |
frame[0] = hi_target | 0x00; |
frame[0] = hi_target | 0x00; |
29 |
|
|
30 |
writeFrame(frame,1); |
writeFrame(frame,1); |
|
cout << "read mid" << endl; |
|
31 |
Sleep(50); //be nice and wait a little |
Sleep(50); //be nice and wait a little |
32 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
|
cout << "read done" << endl; |
|
33 |
|
|
34 |
if (answer.size() == 0) |
if (answer.size() == 0) |
35 |
throw std::runtime_error("No reply"); |
throw std::runtime_error("No reply"); |
57 |
unsigned char hi_target = (target & 0x0F) << 4; |
unsigned char hi_target = (target & 0x0F) << 4; |
58 |
frame[0] = hi_target | 0x01; |
frame[0] = hi_target | 0x01; |
59 |
frame[1] = data; |
frame[1] = data; |
|
cout << "write start" << endl; |
|
60 |
|
|
61 |
writeFrame(frame,2); |
writeFrame(frame,2); |
|
cout << "write mid" << endl; |
|
62 |
Sleep(50); //be nice and wait a little |
Sleep(50); //be nice and wait a little |
63 |
std::vector<unsigned char> answer = readFrame(); |
std::vector<unsigned char> answer = readFrame(); |
64 |
|
|
|
cout << "write stop" << endl; |
|
65 |
if (answer.size() == 0) |
if (answer.size() == 0) |
66 |
throw std::runtime_error("No reply"); |
throw std::runtime_error("No reply"); |
67 |
|
|