17 |
|
|
18 |
short CH7Serial::readTarget(unsigned char target) |
short CH7Serial::readTarget(unsigned char target) |
19 |
{ |
{ |
20 |
|
serialLock.Lock(); |
21 |
short retval; |
short retval; |
22 |
unsigned char frame[1]; |
unsigned char frame[1]; |
23 |
unsigned char hi_target = (target & 0x0F) << 4; |
unsigned char hi_target = (target & 0x0F) << 4; |
33 |
if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK |
if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK |
34 |
throw std::exception("Request not acknowledged"); |
throw std::exception("Request not acknowledged"); |
35 |
|
|
36 |
if ( (answer[0] & 0xF0) != hi_target) |
// if ( (answer[0] & 0xF0) != hi_target) |
37 |
throw std::exception("Incorrect reply"); |
// throw std::exception("Incorrect reply"); |
38 |
|
|
39 |
|
|
40 |
if (answer.size() == 2) |
if (answer.size() == 2) |
41 |
retval = answer[1]; |
retval = answer[1]; |
44 |
else |
else |
45 |
retval = -1; |
retval = -1; |
46 |
|
|
47 |
|
serialLock.Unlock(); |
48 |
return retval; |
return retval; |
49 |
} |
} |
50 |
|
|
51 |
void CH7Serial::writeTarget(unsigned char target, unsigned char data) |
void CH7Serial::writeTarget(unsigned char target, unsigned char data) |
52 |
{ |
{ |
53 |
|
serialLock.Lock(); |
54 |
unsigned char frame[2]; |
unsigned char frame[2]; |
55 |
unsigned char hi_target = (target & 0x0F) << 4; |
unsigned char hi_target = (target & 0x0F) << 4; |
56 |
frame[0] = hi_target | 0x01; |
frame[0] = hi_target | 0x01; |
68 |
|
|
69 |
if ( (answer[0] & 0xF0) != hi_target) |
if ( (answer[0] & 0xF0) != hi_target) |
70 |
throw std::exception("Incorrect reply"); |
throw std::exception("Incorrect reply"); |
71 |
|
|
72 |
|
serialLock.Unlock(); |
73 |
} |
} |
74 |
|
|
75 |
|
|