00001
00002
00004
00005 #ifndef BHAND_SERIAL_H
00006 #define BHAND_SERIAL_H
00007
00008 #include "BHandDriver.h"
00009
00010
00011 #define BH_MAXCHAR 5000
00012 #define BH_MAXPORT 9
00013
00014
00015 class wxSerialPort;
00016
00017 class BHandSerialDriver : public BHandDriver
00018 {
00019 public:
00020
00022
00024
00025 BHandSerialDriver(BHand *bhand, BHandSupervisoryRealtime *moduleSuperReal, unsigned int comport);
00026 virtual ~BHandSerialDriver();
00027
00028
00029
00030
00032
00034
00035
00036 int Initialize();
00037 void Close();
00038
00039 void SetWaitCallbackFunc(BHCallback waitCallbackFunc);
00040
00041
00042
00043
00045
00047
00048
00049 int ComInitialize(int comport);
00050 int ComOpen(int comport, int baudrate = 9600);
00051 bool ComIsOpen();
00052 void ComClose();
00053
00054 int ComSetBaudrate(int baud);
00055 int ComSetTimeouts(unsigned int readMultiplier, unsigned int readConstant,
00056 unsigned int writeMultiplier, unsigned int writeConstant);
00057
00058 bool ComClear(bool rxOnly = false);
00059 int ComRead(char *rxBuf, int rxNumBytes);
00060 int ComWrite(const char *txBuf, int txNumBytes);
00061
00062
00063 const char * Response();
00064 const char * Buffer();
00065
00066
00067
00068
00070
00072
00073
00074 int RTStart(const char *motor, BHMotorProtection motorProtection = BHMotorTSTOPProtect);
00075 int RTUpdate(bool control = true, bool feedback = true);
00076 int RTAbort();
00077
00078
00079 int RTSetFlags(const char *motor, bool LCV, int LCVC, bool LCPG,
00080 bool LFV, int LFVC, bool LFS, bool LFAP, bool LFDP, int LFDPC);
00081 int RTSetFlags(const char *motor, bool LCV, int LCVC, bool LCPG, bool LCT,
00082 bool LFV, int LFVC, bool LFS, bool LFAP, bool LFDP, int LFDPC,
00083 bool LFBP, bool LFAIN, bool LFDPD, bool LFT);
00084
00085 int RTUpdate(const char *motor, const char *property, int *values);
00086
00087
00088 int RTSetVelocity(const char motor, int velocity);
00089 int RTSetGain(const char motor, int gain);
00090 int RTSetTorque(const char motor, int torque);
00091 int RTSetPosition(const char motor, int position);
00092
00093
00094 char RTGetVelocity(const char motor);
00095 unsigned char RTGetStrain(const char motor);
00096 int RTGetPosition(const char motor);
00097 char RTGetDeltaPos(const char motor);
00098 int RTGetBreakawayPosition(const char motor);
00099 int RTGetTemp();
00100 unsigned char RTGetAIN(const char motor);
00101 void RTGetPPS(const char motor, int *pps, int ppsElements);
00102
00103
00104
00105
00107
00109
00110 static void SetDefaultBaud(unsigned int baud) { defBaud = baud; }
00111
00112
00113 private:
00114
00116
00118
00119
00120 int HandInit(BHMotors bhMotors);
00121 int HandReset(BHMotors bhMotors, bool *responseReceived);
00122
00123
00124 int HandClose(BHMotors bhMotors);
00125 int HandOpen(BHMotors bhMotors);
00126
00127 int HandGoToDefault(BHMotors bhMotors, bool valueIncluded = false, int defaultPosition = 0);
00128 int HandGoToDifferentPositionsHand(const int *encoderPositions, unsigned int numEncoderPositions);
00129 int HandGoToHome(BHMotors bhMotors);
00130 int HandGoToPosition(BHMotors bhMotors, unsigned int encoderPositionTickCount);
00131
00132 int HandStepClose(BHMotors bhMotors, bool valueIncluded = false, int stepAmount = 0);
00133 int HandStepOpen(BHMotors bhMotors, bool valueIncluded = false, int stepAmount = 0);
00134
00135 int HandTorqueClose(BHMotors bhMotors);
00136 int HandTorqueOpen(BHMotors bhMotors);
00137
00138
00139 int HandGet(BHMotors bhMotors, const char *property, int *propertyResult, int *nresults = 0);
00140 int HandSet(BHMotors bhMotors, const char *property, int value);
00141
00142 int HandPGet(const char *property, int *propertyResult);
00143 int HandPSet(const char *property, int value);
00144
00145 int HandDefault(BHMotors bhMotors);
00146 int HandLoad(BHMotors bhMotors);
00147 int HandSave(BHMotors bhMotors);
00148
00149 int HandTemperature(BHMotors bhMotors, int *temperature, unsigned int numTemperatures);
00150
00151
00152 int HandDelay(unsigned int msec);
00153
00154 int HandStopMotor(BHMotors bhMotors);
00155
00156 char * HandCommand(const char *send, int *errorCode);
00157
00158 int HandBaud(unsigned int newbaud);
00159
00160
00161
00162 int ExecuteRealtimeCall();
00163 int HandleSupervisoryCall();
00164
00165
00166
00167 int rtFlags[4][10];
00168 int rtGlobalFlags[1];
00169 int nSend;
00170 int nReceive;
00171 char rtIn[4*8+1];
00172
00173
00174 wxSerialPort *dev;
00175
00176
00177 static int defBaud;
00178 int comPort;
00179 int comBaud;
00180
00181
00182 unsigned int readTotalTimeoutMultiplier;
00183 unsigned int readTotalTimeoutConstant;
00184 unsigned int writeTotalTimeoutMultiplier;
00185 unsigned int writeTotalTimeoutConstant;
00186
00187
00188 unsigned int requestBaud;
00189
00190
00191 char inbuf[BH_MAXCHAR];
00192 int nin;
00193 char outbuf[BH_MAXCHAR];
00194 int nout;
00195
00196
00197 char rtOut[4*4+1];
00198 int rtControl[4][3];
00199 int rtFeedback[4][6];
00200 int rtGlobalFeedback[1];
00201
00202
00204
00206
00207 int Interactive();
00208
00209 };
00210
00211
00212 #endif