cplSerial.h
Go to the documentation of this file.
1 /*
2  * Katana Native Interface - A C++ interface to the robot arm Katana.
3  * Copyright (C) 2005 Neuronics AG
4  * Check out the AUTHORS file for detailed contact information.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 
22 /******************************************************************************************************************/
23 #ifndef _CPLSERIAL_H_
24 #define _CPLSERIAL_H_
25 /******************************************************************************************************************/
26 #include "common/dllexport.h"
27 #include "common/exception.h"
28 #include "KNI/cplBase.h"
29 #include "KNI/cdlCOMExceptions.h"
30 
31 #define NUMBER_OF_RETRIES_SEND 3 // Number of retries after a failing in the Communication
32 #define NUMBER_OF_RETRIES_RECV 3 // Number of retries after a failing in the Communication
33 /******************************************************************************************************************/
34 
36 const int KATANA_ERROR_FLAG = 192;
41 
44 class WrongCRCException : public Exception {
45 public:
46  WrongCRCException() throw ():
47  Exception("CRC check failed", -20) {}
48 };
49 
52 class FirmwareException : public Exception {
53 protected:
56 public:
57  FirmwareException(const std::string & error, const int error_number, const int axis, const char command) throw ():
58  Exception("FirmwareException : '" + error + "'", error_number),
59  _axis_number(axis),
60  _command_char(command) {}
61  int axis_number() const throw() {
62  return _axis_number;
63  }
64  char command_char() const throw() {
65  return _command_char;
66  }
67 };
68 
72 
75 struct THeader {
77  byte data[256];
78 };
79 
82 struct TPacket {
85 };
86 
87 //----------------------------------------------------------------------------------------------------------------//
88 
89 
92 class DLLDIR CCplSerial : public CCplBase {
93 
94 protected:
96  TPacket cmd[256];
97 
98  byte send_buf[256];
99  byte read_buf[256];
100 
101 protected:
102  virtual bool load_tbl() = 0;
103  virtual void defineProtocol(byte _kataddr) = 0;
104 };
105 
106 //----------------------------------------------------------------------------------------------------------------//
107 
112 // class DLLDIR CCplSerialZero : public CCplSerial {
113 //
114 // protected:
115 // virtual bool load_tbl(); //!< Loads the command table from the robot's firmware.
116 // virtual void defineProtocol(byte _kataddr); //!< Defines the protocol's attributes.
117 //
118 // public:
119 // /*! \brief Initializing function
120 // *
121 // * Init the protocols basic attributes.
122 // */
123 // virtual bool init(CCdlBase* _device, byte _kataddr = 24);
124 //
125 //
126 // /*! \brief Communication function
127 // *
128 // * Sends a communications packet and receives one from the robot.
129 // */
130 // virtual TRetCOMM comm(const byte* _pack, byte* _buf, byte* _size);
131 // };
132 
133 //----------------------------------------------------------------------------------------------------------------//
134 
138 
139 protected:
140  virtual bool load_tbl();
141  virtual void defineProtocol(byte _kataddr);
142  virtual void send(byte* send_buf, byte write_sz, short retries = 3); // Sends a packet.
143  virtual void recv(byte* read_buf, byte read_sz, byte* size); // Receives the packet and checks the CRC.
144 
145 public:
150  virtual bool init(CCdlBase* _device, byte _kataddr = 24);
151 
156  virtual void comm(const byte* pack, byte* buf, byte* size);
157 
162  virtual void getMasterFirmware(short* fw, short* rev);
163 
164 };
165 
166 /******************************************************************************************************************/
167 #endif //_CPLSERIALZERO_H_
168 /******************************************************************************************************************/
unsigned char byte
type specification (8 bit)
Definition: cdlBase.h:29
byte send_sz
send size of the packet
Definition: cplSerial.h:83
Abstract base class for protocol definiton.
Definition: cplBase.h:47
#define DLLDIR
Definition: dllexport.h:30
Implement the Serial-Zero protocol.
Definition: cplSerial.h:137
Exception(const std::string &message, const int error_number)
Exception reported by the firmware.
Definition: cplSerial.h:52
Header of a communication packet.
Definition: cplSerial.h:75
CRC check for the answer package failed.
Definition: cplSerial.h:44
byte size
header size
Definition: cplSerial.h:76
FirmwareException(const std::string &error, const int error_number, const int axis, const char command)
Definition: cplSerial.h:57
char _command_char
the command that caused the error
Definition: cplSerial.h:55
const int KATANA_ERROR_FLAG
defines the error flag number
Definition: cplSerial.h:36
char command_char() const
Definition: cplSerial.h:64
int axis_number() const
Definition: cplSerial.h:61
int _axis_number
axis number, if any
Definition: cplSerial.h:54
THeader hdr
header
Definition: cplSerial.h:95
byte read_sz
read size of the packet
Definition: cplSerial.h:84
int error_number() const
Base class of two different serial protocols.
Definition: cplSerial.h:92
Communication packet.
Definition: cplSerial.h:82
byte size
Definition: kni_wrapper.cpp:35
Abstract base class for devices.
Definition: cdlBase.h:47


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:44