--- trunk/PIC/Testprogram/H7Serial.cpp 2007/02/01 10:03:52 38 +++ branches/linux-serial/H7Serial.cpp 2007/02/05 07:16:59 51 @@ -1,5 +1,9 @@ -#include "StdAfx.h" -#include ".\h7serial.h" + +#include "stdafx.h" + +#include "H7Serial.h" +#include +#include CH7Serial::CH7Serial(void) : CSlipSerial() @@ -17,23 +21,27 @@ short CH7Serial::readTarget(unsigned char target) { + using namespace std; + cout << "read start" << endl; short retval; unsigned char frame[1]; unsigned char hi_target = (target & 0x0F) << 4; frame[0] = hi_target | 0x00; writeFrame(frame,1); + cout << "read mid" << endl; Sleep(50); //be nice and wait a little std::vector answer = readFrame(); + cout << "read done" << endl; if (answer.size() == 0) - throw std::exception("No reply"); + throw std::runtime_error("No reply"); if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK - throw std::exception("Request not acknowledged"); + throw std::runtime_error("Request not acknowledged"); if ( (answer[0] & 0xF0) != hi_target) - throw std::exception("Incorrect reply"); + throw std::runtime_error("Incorrect reply"); if (answer.size() == 2) retval = answer[1]; @@ -47,23 +55,27 @@ void CH7Serial::writeTarget(unsigned char target, unsigned char data) { + using namespace std; unsigned char frame[2]; unsigned char hi_target = (target & 0x0F) << 4; frame[0] = hi_target | 0x01; frame[1] = data; + cout << "write start" << endl; writeFrame(frame,2); + cout << "write mid" << endl; Sleep(50); //be nice and wait a little std::vector answer = readFrame(); - + + cout << "write stop" << endl; if (answer.size() == 0) - throw std::exception("No reply"); + throw std::runtime_error("No reply"); if ( (answer[0] & 0x0F) != 0x02) // tjek for ACK - throw std::exception("Request not acknowledged"); + throw std::runtime_error("Request not acknowledged"); if ( (answer[0] & 0xF0) != hi_target) - throw std::exception("Incorrect reply"); + throw std::runtime_error("Incorrect reply"); }