1 |
|
|
2 |
#ifdef _WINDOWS |
#include "stdafx.h" |
|
#include "StdAfx.h" |
|
|
#endif |
|
3 |
|
|
4 |
#include "H7Serial.h" |
#include "H7Serial.h" |
5 |
#include <stdexcept> |
#include <stdexcept> |
10 |
{ |
{ |
11 |
} |
} |
12 |
|
|
13 |
CH7Serial::CH7Serial(char* port, int bitrate) |
CH7Serial::CH7Serial(char* port, Baudrate bitrate) |
14 |
: CSlipSerial(port, bitrate) |
: CSlipSerial(port, bitrate) |
15 |
{ |
{ |
16 |
} |
} |
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 |
|
|