Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _CPLSERIAL_H_
00024 #define _CPLSERIAL_H_
00025
00026 #include "common/dllexport.h"
00027 #include "common/exception.h"
00028 #include "KNI/cplBase.h"
00029 #include "KNI/cdlCOMExceptions.h"
00030
00031 #define NUMBER_OF_RETRIES_SEND 3 // Number of retries after a failing in the Communication
00032 #define NUMBER_OF_RETRIES_RECV 3 // Number of retries after a failing in the Communication
00033
00034
00036 const int KATANA_ERROR_FLAG = 192;
00041
00044 class WrongCRCException : public Exception {
00045 public:
00046 WrongCRCException() throw ():
00047 Exception("CRC check failed", -20) {}
00048 };
00049
00052 class FirmwareException : public Exception {
00053 protected:
00054 int _axis_number;
00055 char _command_char;
00056 public:
00057 FirmwareException(const std::string & error, const int error_number, const int axis, const char command) throw ():
00058 Exception("FirmwareException : '" + error + "'", error_number),
00059 _axis_number(axis),
00060 _command_char(command) {}
00061 int axis_number() const throw() {
00062 return _axis_number;
00063 }
00064 char command_char() const throw() {
00065 return _command_char;
00066 }
00067 };
00068
00072
00075 struct THeader {
00076 byte size;
00077 byte data[256];
00078 };
00079
00082 struct TPacket {
00083 byte send_sz;
00084 byte read_sz;
00085 };
00086
00087
00088
00089
00092 class DLLDIR CCplSerial : public CCplBase {
00093
00094 protected:
00095 THeader hdr;
00096 TPacket cmd[256];
00097
00098 byte send_buf[256];
00099 byte read_buf[256];
00100
00101 protected:
00102 virtual bool load_tbl() = 0;
00103 virtual void defineProtocol(byte _kataddr) = 0;
00104 };
00105
00106
00107
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00137 class DLLDIR CCplSerialCRC : public CCplSerial {
00138
00139 protected:
00140 virtual bool load_tbl();
00141 virtual void defineProtocol(byte _kataddr);
00142 virtual void send(byte* send_buf, byte write_sz, short retries = 3);
00143 virtual void recv(byte* read_buf, byte read_sz, byte* size);
00144
00145 public:
00150 virtual bool init(CCdlBase* _device, byte _kataddr = 24);
00151
00156 virtual void comm(const byte* pack, byte* buf, byte* size);
00157
00162 virtual void getMasterFirmware(short* fw, short* rev);
00163
00164 };
00165
00166
00167 #endif //_CPLSERIALZERO_H_
00168