Changeset 11858 for trunk/FACT++/src
- Timestamp:
- 08/09/11 14:20:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/biasctrl.cc
r11852 r11858 62 62 63 63 virtual void UpdateA() 64 { 65 } 66 67 virtual void UpdateV() 64 68 { 65 69 } … … 195 199 196 200 SystemReset(); 197 ReadAllChannels Status();201 ReadAllChannels(); 198 202 } 199 203 … … 258 262 259 263 return data; 260 }261 262 void GlobalSetDac(uint16_t dac)263 {264 PostMessage(GetCmd(0, kCmdGlobalSet, dac));265 AsyncRead(ba::buffer(fBuffer), kCmdGlobalSet);266 264 } 267 265 … … 315 313 } 316 314 317 bool GlobalSet(double voltage) 318 { 319 const uint16_t dac = voltage*4096/90; 315 void SystemReset() 316 { 317 Message("Sending system reset."); 318 PostMessage(GetCmd(0, kCmdReset)); 319 AsyncRead(ba::buffer(fBuffer), kCmdReset); 320 } 321 322 void ReadChannel(int ch) 323 { 324 PostMessage(GetCmd(ch, kCmdRead)); 325 AsyncRead(ba::buffer(fBuffer), kCmdRead|(ch<<4)); 326 } 327 328 329 void ReadAllChannels() 330 { 331 Message("Requesting full system status."); 332 333 // Prepare command to read all channels 334 for (int i=0; i<kNumChannels; i++) 335 ReadChannel(i); 336 337 //vector<char> buf; 338 //AsyncRead(ba::buffer(buf), kCmdPrint); 339 } 340 341 bool GlobalSetDac(uint16_t dac) 342 { 320 343 if (dac>0xfff) 321 344 return false; 322 345 323 GlobalSetDac(dac); 346 PostMessage(GetCmd(0, kCmdGlobalSet, dac)); 347 AsyncRead(ba::buffer(fBuffer), kCmdGlobalSet); 348 349 ReadAllChannels(); 350 351 fVolt.assign(kNumChannels, dac); 352 UpdateV(); 324 353 325 354 return true; 326 355 } 327 356 328 bool ChannelSet(uint16_t ch, double voltage) 329 { 330 const uint16_t dac = voltage*4096/90; 357 bool GlobalSet(double voltage) 358 { 359 return GlobalSetDac(voltage*4096/90); 360 } 361 362 bool ChannelSetDac(uint16_t ch, uint16_t dac) 363 { 331 364 if (dac>0xfff) 332 365 return false; … … 335 368 return false; 336 369 370 if (fVolt[ch]==dac) 371 return true; 372 337 373 PostMessage(GetCmd(ch, kCmdChannelSet, dac)); 338 374 AsyncRead(ba::buffer(fBuffer), kCmdChannelSet|(ch<<4)); 339 375 376 ReadChannel(ch); 377 378 fVolt[ch] = dac; 379 UpdateV(); 380 340 381 return true; 341 382 } 342 383 343 void ReadAllChannelsStatus()344 { 345 Message("Requesting full system status.");346 347 // Prepare command to read all channels 348 for (int i=0; i<kNumChannels; i++)349 350 const vector<char> cmd = GetCmd(i, kCmdRead);351 PostMessage(cmd);352 AsyncRead(ba::buffer(fBuffer), kCmdRead|(i<<4)); 353 }354 355 //vector<char> buf; 356 //AsyncRead(ba::buffer(buf), kCmdPrint);384 bool ChannelSet(uint16_t ch, double voltage) 385 { 386 return ChannelSetDac(ch, voltage*4096/90); 387 } 388 389 void SetVoltage(int ch, int32_t dac) 390 { 391 if (dac<0) 392 dac = 0; 393 394 if (dac>0xfff) 395 dac = 0xfff; 396 397 ChannelSetDac(ch, dac); 357 398 } 358 399 … … 368 409 // const double diffcur = (fRefCurrent[i]-fCurrent[i])*5000/4096 369 410 //const int32_t diffcur = int32_t(fRefCurrent[i]-fCurrent[i])*5000; 370 const int32_t diffvolt = (fRefCurrent[i]-fCurrent[i])*5;371 411 372 412 // Calculate voltage difference … … 376 416 // Calculate new vlaue by onverting voltage difference to DAC units 377 417 //const int32_t dac = fRefVolt[i] + diffvolt*4096/90.0; 378 int32_t dac = fRefVolt[i] + diffvolt/90; 379 380 if (dac<0) 381 dac = 0; 382 if (dac>0xfff) 383 dac = 0xfff; 384 385 if (fVolt[i] == dac) 386 continue; 387 388 PostMessage(GetCmd(i, kCmdChannelSet, dac)); 389 AsyncRead(ba::buffer(fBuffer), kCmdChannelSet|(i<<4)); 390 } 391 } 392 393 void SystemReset() 394 { 395 Message("Sending system reset."); 396 PostMessage(GetCmd(0, kCmdReset)); 397 AsyncRead(ba::buffer(fBuffer), kCmdReset); 418 SetVoltage(i, fRefVolt[i] + (fRefCurrent[i]-fCurrent[i])/18); 419 } 398 420 } 399 421 … … 457 479 { 458 480 fDimCurrent.Update(fCurrent); 459 ConnectionBias::UpdateA(); 460 } 461 462 /* 481 } 482 463 483 void UpdateV() 464 484 { 465 fDim Current.Update(fRefVolt);466 } */485 fDimVoltage.Update(fVolt); 486 } 467 487 468 488 public: 469 489 ConnectionDimBias(ba::io_service& ioservice, MessageImp &imp) : 470 490 ConnectionBias(ioservice, imp), 471 fDimCurrent("BIAS_CONTROL/CURRENT", " F:416", ""),472 fDimVoltage("BIAS_CONTROL/VOLTAGE", " F:416", "")491 fDimCurrent("BIAS_CONTROL/CURRENT", "S:416", ""), 492 fDimVoltage("BIAS_CONTROL/VOLTAGE", "S:416", "") 473 493 { 474 494 } … … 524 544 } 525 545 546 int SetGlobalDac(const EventImp &evt) 547 { 548 if (!CheckEventSize(evt.GetSize(), "SetGlobalDac", 2)) 549 return false; 550 551 if (!fBias.GlobalSetDac(evt.GetUShort())) 552 T::Error("Supplied voltage out of range (0-90)"); 553 554 return T::GetCurrentState(); 555 } 556 526 557 int SetChannel(const EventImp &evt) 527 558 { … … 530 561 531 562 if (!fBias.ChannelSet(evt.GetUShort(), evt.Get<float>(2))) 563 T::Error("Value out of range"); 564 565 return T::GetCurrentState(); 566 } 567 568 int SetChannelDac(const EventImp &evt) 569 { 570 if (!CheckEventSize(evt.GetSize(), "SetChannelDac", 4)) 571 return false; 572 573 if (!fBias.ChannelSetDac(evt.Get<uint16_t>(), evt.Get<uint16_t>(2))) 532 574 T::Error("Value out of range"); 533 575 … … 627 669 628 670 AddEvent("REQUEST_STATUS", kStateConnected) 629 (Wrapper(bind(&ConnectionBias::ReadAllChannels Status, &fBias)))671 (Wrapper(bind(&ConnectionBias::ReadAllChannels, &fBias))) 630 672 (""); 631 673 … … 634 676 (""); 635 677 678 AddEvent("SET_GLOBAL_DAC", "S:1", kStateConnected) 679 (bind(&StateMachineBias::SetGlobalDac, this, _1)) 680 (""); 681 636 682 AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", kStateConnected) 637 683 (bind(&StateMachineBias::SetChannel, this, _1)) 684 (""); 685 686 AddEvent("SET_CHANNEL_DAC", "S:1;S:1", kStateConnected) 687 (bind(&StateMachineBias::SetChannelDac, this, _1)) 638 688 (""); 639 689
Note:
See TracChangeset
for help on using the changeset viewer.