Changeset 925 for trunk/MagicSoft/Cosy/devdrv
- Timestamp:
- 09/07/01 12:44:16 (24 years ago)
- Location:
- trunk/MagicSoft/Cosy/devdrv
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/devdrv/macs.cc
r920 r925 12 12 fPosActive(0), fRpmActive(0) 13 13 { 14 fTimeout = new TTimer(this, 100, kFALSE); // 100ms 14 15 } 15 16 16 17 Macs::~Macs() 17 18 { 19 fTimerOn = kFALSE; 20 delete fTimeout; 18 21 } 19 22 … … 30 33 fVel = val; 31 34 return; 35 36 case 0x4000: 37 switch (subidx) 38 { 39 case 1: 40 cout << "Timeout timer is " << (val?"en":"dis") << "abled." << endl; 41 return; 42 case 2: 43 cout << "Actual timeout time: " << dec << val << "ms" << endl; 44 return; 45 } 46 break; 32 47 33 48 case 0x6004: … … 74 89 75 90 case 0x6002: 76 lout << "- Velocity resolution #" << (int)GetId() << ": " << dec << val << " ticks/min" << endl;91 lout << "- Velocity resolution Node#" << (int)GetId() << ": " << dec << val << " ticks/min" << endl; 77 92 fVelRes = val; 78 93 return; … … 82 97 } 83 98 99 void Macs::SetTimeoutTime(LWORD_t ms) 100 { 101 fTimeoutTime = ms/2; 102 103 SendSDO(0x4000, 2, ms); 104 WaitForSdo(0x4000, 2); 105 } 106 107 void Macs::ReqTimeoutTime() 108 { 109 RequestSDO(0x4000, 2); 110 WaitForSdo(0x4000, 2); 111 } 112 113 void Macs::EnableTimeout(bool enable, LWORDS_t ms) 114 { 115 if (!enable) 116 { 117 SendSDO(0x4000, 1, string('o', 'f', 'f')); 118 WaitForSdo(0x4000, 1); 119 120 cout << "--> Turn Off. " << endl; 121 fTimerOn = kFALSE; 122 } 123 else 124 { 125 if (ms>0) 126 SetTimeoutTime(ms); 127 128 cout << "--> Turn On." << endl; 129 fTimerOn = kTRUE; 130 fTimeout->Start(fTimeoutTime, kTRUE); 131 132 SendSDO(0x4000, 1, string('o', 'n')); 133 WaitForSdo(0x4000, 1); 134 } 135 } 136 84 137 void Macs::ReqVelRes() 85 138 { 86 lout << "- Requesting velocity resolution (velres, 0x 3007) of " << (int)GetId() << endl;139 lout << "- Requesting velocity resolution (velres, 0x6002) of " << (int)GetId() << endl; 87 140 RequestSDO(0x6002); 88 141 WaitForSdo(0x6002); … … 116 169 WaitForSdo(0x2004); 117 170 */ 171 EnableTimeout(kFALSE); 118 172 119 173 lout << "- Requesting Mac Software Version of " << (int)GetId() << endl; … … 126 180 127 181 lout << "- Motor on of " << (int)GetId() << endl; 128 SendSDO(0x3000, string(' O', 'N'));182 SendSDO(0x3000, string('o', 'n')); 129 183 WaitForSdo(0x3000); 130 184 … … 147 201 // Stop the motor and switch off the position control unit 148 202 // 149 SendSDO(0x3000, string(' S','T','O','P'));203 SendSDO(0x3000, string('s','t','o','p')); 150 204 WaitForSdo(0x3000); 151 205 } … … 153 207 void Macs::StopDevice() 154 208 { 209 EnableTimeout(kFALSE); 210 155 211 SetNoWait(FALSE); 156 212 … … 164 220 165 221 lout << "- Motor off of " << (int)GetId() << endl; 166 SendSDO(0x3000, string(' O', 'F', 'F'));222 SendSDO(0x3000, string('o', 'f', 'f')); 167 223 WaitForSdo(0x3000); 168 224 … … 227 283 // SetRpmMode(FALSE) stop the motor, but lets the position control unit on 228 284 // 229 SendSDO(0x3006, 0, mode ? string(' S','T','R','T') : string('S','T','O','P'));285 SendSDO(0x3006, 0, mode ? string('s','t','r','t') : string('s','t','o','p')); 230 286 WaitForSdo(0x3006, 0); 231 287 } … … 250 306 { 251 307 lout << "- Setting NOWAIT " << (flag?"ON":"OFF") << " #" << (int)GetId() << endl; 252 SendSDO(0x3008, flag ? string(' O', 'N') : string('O', 'F', 'F'));308 SendSDO(0x3008, flag ? string('o', 'n') : string('o', 'f', 'f')); 253 309 WaitForSdo(0x3008); 254 310 } … … 261 317 // 262 318 lout << "- Setting Vel Sync Mode #" << (int)GetId() << endl; 263 SendSDO(0x3007, 0, string(' S', 'Y', 'N', 'C'));319 SendSDO(0x3007, 0, string('s', 'y', 'n', 'c')); 264 320 WaitForSdo(0x3007, 0); 265 321 } … … 272 328 // 273 329 lout << "- Setting Pos Sync Mode #" << (int)GetId() << endl; 274 SendSDO(0x3007, 1, string(' S', 'Y', 'N', 'C'));330 SendSDO(0x3007, 1, string('s', 'y', 'n', 'c')); 275 331 WaitForSdo(0x3007, 1); 276 332 } … … 403 459 switch (GetError()) 404 460 { 405 case 6: // home 406 case 8: // control dev 407 case 9: // zero idx 408 case 84: // ON TIME 461 case 6: // home 462 case 8: // control dev 463 case 9: // zero idx 464 case 84: // ON TIME 465 case 100: // timeout 409 466 // Stop program? 410 467 return; … … 457 514 WaitForSdo(0x2000, 3); 458 515 } 516 517 Bool_t Macs::HandleTimer(TTimer *t) 518 { 519 /* 520 Fons: 521 ----- 522 523 timers never trigger at the same time or when in a TTimer::Notify. 524 Little explanation: 525 526 - there are two types of timers synchronous and a-synchronous. 527 - synchronous timers are only handled via the ROOT eventloop 528 (see TUnixSystem::DispatchOneEvent()). If there are no mouse/keyboard 529 events then the synchronous timer queue is checked. So if the processing 530 of a mouse/keyboard event takes a long time synchronous timers are not 531 called for a while. To prevent this from happening one can call in long 532 procedures gSystem->ProcessEvents(). The system schedules only the 533 next timer in the queue when the current one's Notify() has finished. 534 - a-synchronous timers are triggered via SIGALARM, i.e. the program is 535 interupted and execution jumps to the Notify() function. When the 536 notify is finished the next a-sync timer is scheduled and the system 537 resumes from the place where it was initially interrupted. One of the 538 things to remember when using a-sync timers is don't make any graphics 539 calls in them. X11 is not re-entrant and it might be that the SIGALARM 540 signal interrupted the system while being in X11. A-sync timers are best 541 used to set flags that you can test at a convenient and controlled 542 time. 543 */ 544 SendSDO(0x4000); 545 WaitForSdo(0x4000, 0, kDontWait); 546 if (fTimerOn) 547 fTimeout->Start(fTimeoutTime, kTRUE); 548 return kTRUE; 549 } -
trunk/MagicSoft/Cosy/devdrv/macs.h
r920 r925 1 1 #ifndef MACS_H 2 2 #define MACS_H 3 4 #include <TObject.h> 3 5 4 6 #include "nodedrv.h" 5 7 #include "base/timer.h" 6 8 7 class Macs : public NodeDrv 9 class Macs : public NodeDrv, public TObject 8 10 { 9 11 private: … … 22 24 BYTE_t fRpmActive; 23 25 26 TTimer *fTimeout; 27 Bool_t fTimerOn; 28 LWORD_t fTimeoutTime; 29 24 30 LWORD_t string(BYTE_t b0=0, BYTE_t b1=0, BYTE_t b2=0, BYTE_t b3=0) 25 31 { 26 32 return (LWORD_t)(b0<<24 | b1<<16 | b2<<8 | b3); 27 33 } 34 35 Bool_t HandleTimer(TTimer *t); 28 36 29 37 public: … … 70 78 void StartAbsPos(LWORDS_t pos); 71 79 80 void SetTimeoutTime(LWORD_t ms); 81 void ReqTimeoutTime(); 82 83 void EnableTimeout(bool enable=true, LWORDS_t ms=-1); 84 72 85 void StopMotor(); 73 86
Note:
See TracChangeset
for help on using the changeset viewer.