Skip to content
Snippets Groups Projects
Keithley428.cpp 19.6 KiB
Newer Older
Teresa Nunez's avatar
Teresa Nunez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
static const char *RcsId = "$Id:  $";
//+=============================================================================
//
// file :         Keithley428.cpp
//
// description :  C++ source for the Keithley428 and its commands. 
//                The class is derived from Device. It represents the
//                CORBA servant object which will be accessed from the
//                network. All commands which can be executed on the
//                Keithley428 are implemented in this file.
//
// project :      TANGO Device Server
//
// $Author:  $
//
// $Revision:  $
//
// $Revision:  $
// $Date:  $
//
// SVN only:
// $HeadURL: $
//
// CVS only:
// $Source:  $
// $Log:  $
//
// copyleft :     European Synchrotron Radiation Facility
//                BP 220, Grenoble 38043
//                FRANCE
//
//-=============================================================================
//
//  		This file is generated by POGO
//	(Program Obviously used to Generate tango Object)
//
//         (c) - Software Engineering Group - ESRF
//=============================================================================



//===================================================================
//
//	The following table gives the correspondence
//	between commands and method name.
//
//  Command name        |  Method name
//	----------------------------------------
//  State               |  dev_state()
//  Status              |  dev_status()
//  PerformZeroCorrect  |  perform_zero_correct()
//  FilterOn            |  filter_on()
//  FilterOff           |  filter_off()
//  AutoFilterOn        |  auto_filter_on()
//  AutoFilterOff       |  auto_filter_off()
//
//===================================================================


#include <tango.h>
#ifndef USE_HELPERS_DIR
#include <PogoHelper.h>
#else
#include <helpers/PogoHelper.h>
#endif
#include <Keithley428.h>
#include <Keithley428Class.h>

namespace Keithley428_ns
{

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::Keithley428(string &s)
// 
// description : 	constructor for simulated Keithley428
//
// in : - cl : Pointer to the DeviceClass object
//      - s : Device name 
//
//-----------------------------------------------------------------------------
Keithley428::Keithley428(Tango::DeviceClass *cl,string &s)
    :Tango::Device_4Impl(cl,s.c_str())
{
    init_device();
}

Keithley428::Keithley428(Tango::DeviceClass *cl,const char *s)
    :Tango::Device_4Impl(cl,s)
{
    init_device();
}

Keithley428::Keithley428(Tango::DeviceClass *cl,const char *s,const char *d)
    :Tango::Device_4Impl(cl,s,d)
{
    init_device();
}
//+----------------------------------------------------------------------------
//
// method : 		Keithley428::delete_device()
// 
// description : 	will be called at device destruction or at init command.
//
//-----------------------------------------------------------------------------
void Keithley428::delete_device()
{
    //	Delete device allocated objects

    DELETE_DEVSTRING_ATTRIBUTE(attr_GainStr_read);
    DELETE_SCALAR_ATTRIBUTE(attr_Overloaded_read);
    DELETE_DEVSTRING_ATTRIBUTE(attr_filterState_read);
    DELETE_DEVSTRING_ATTRIBUTE(attr_autoFilterState_read);

    if (gpib_device != NULL)
        delete gpib_device; 

    if (buffer != NULL)
        delete buffer; 
}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::init_device()
// 
// description : 	will be called at device initialization.
//
//-----------------------------------------------------------------------------
void Keithley428::init_device()
{
    INFO_STREAM << "Keithley428::Keithley428() create device " << device_name << endl;

    // Initialise variables to default values
    //--------------------------------------------
    get_device_property();

    CREATE_DEVSTRING_ATTRIBUTE(attr_GainStr_read,MAX_STRING_LENGTH);
    CREATE_SCALAR_ATTRIBUTE(attr_Overloaded_read);
    CREATE_DEVSTRING_ATTRIBUTE(attr_filterState_read,MAX_STRING_LENGTH);
    CREATE_DEVSTRING_ATTRIBUTE(attr_autoFilterState_read,MAX_STRING_LENGTH);

    gpib_device = NULL;
    try
    {
        gpib_device = new Tango::DeviceProxy(gpibDevice);
        gpib_device->ping();
        set_state(Tango::ON);
        set_status("Keithley428 is ON");
    } 
    catch (Tango::DevFailed &e)
    {
        set_state(Tango::FAULT);
        set_status("Not able to connect to Gpib Device");
    }

    buffer = new char[180]; 
    memset(buffer,0, 180);

    if(gpibDeviceType == 1)
    {
        m_write_read    = "GPIBWriteRead";
        m_write         = "GPIBWrite";
    }
    else
    {
        m_write_read    = "WriteRead";
        m_write         = "Write";
    }
}


//+----------------------------------------------------------------------------
//
// method : 		Keithley428::get_device_property()
// 
// description : 	Read the device properties from database.
//
//-----------------------------------------------------------------------------
void Keithley428::get_device_property()
{
    //	Initialize your default values here (if not done with  POGO).
    //------------------------------------------------------------------

    //	Read device properties from database.(Automatic code generation)
    //------------------------------------------------------------------
	Tango::DbData	dev_prop;
	dev_prop.push_back(Tango::DbDatum("GpibDevice"));
	dev_prop.push_back(Tango::DbDatum("GpibDeviceType"));

	//	Call database and extract values
	//--------------------------------------------
	if (Tango::Util::instance()->_UseDb==true)
		get_db_device()->get_property(dev_prop);
	Tango::DbDatum	def_prop, cl_prop;
	Keithley428Class	*ds_class =
		(static_cast<Keithley428Class *>(get_device_class()));
	int	i = -1;

	//	Try to initialize GpibDevice from class property
	cl_prop = ds_class->get_class_property(dev_prop[++i].name);
	if (cl_prop.is_empty()==false)	cl_prop  >>  gpibDevice;
	else {
		//	Try to initialize GpibDevice from default device value
		def_prop = ds_class->get_default_device_property(dev_prop[i].name);
		if (def_prop.is_empty()==false)	def_prop  >>  gpibDevice;
	}
	//	And try to extract GpibDevice value from database
	if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  gpibDevice;

	//	Try to initialize GpibDeviceType from class property
	cl_prop = ds_class->get_class_property(dev_prop[++i].name);
	if (cl_prop.is_empty()==false)	cl_prop  >>  gpibDeviceType;
	else {
		//	Try to initialize GpibDeviceType from default device value
		def_prop = ds_class->get_default_device_property(dev_prop[i].name);
		if (def_prop.is_empty()==false)	def_prop  >>  gpibDeviceType;
	}
	//	And try to extract GpibDeviceType value from database
	if (dev_prop[i].is_empty()==false)	dev_prop[i]  >>  gpibDeviceType;



    //	End of Automatic code generation
    //------------------------------------------------------------------

}
//+----------------------------------------------------------------------------
//
// method : 		Keithley428::always_executed_hook()
// 
// description : 	method always executed before any command is executed
//
//-----------------------------------------------------------------------------
void Keithley428::always_executed_hook()
{

}
//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_attr_hardware
// 
// description : 	Hardware acquisition for attributes.
//
//-----------------------------------------------------------------------------
void Keithley428::read_attr_hardware(vector<long> &attr_list)
{
    DEBUG_STREAM << "Keithley428::read_attr_hardware(vector<long> &attr_list) entering... "<< endl;
    //	Add your own code here
}
//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_filterState
// 
// description : 	Extract real attribute values for filterState acquisition result.
//
//-----------------------------------------------------------------------------
void Keithley428::read_filterState(Tango::Attribute &attr)
{
	DEBUG_STREAM << "Keithley428::read_filterState(Tango::Attribute &attr) entering... "<< endl;

    DeviceData din;
    DeviceData dout;

    string tmp_string;
    string selected_str;
    string attr_str;
    size_t pos;

    int r_v;
    int w_v;

    sprintf(tmp_buffer,"U0X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    dout = gpib_device->command_inout(m_write_read.c_str(),din);  

    dout >> tmp_string;

    pos = tmp_string.find("P");
    pos = pos + 1;
    selected_str = tmp_string.substr(pos);
    r_v = atoi(selected_str.c_str());

    switch(r_v)
    {
    case 0:
        attr_str = "OFF";
        break;
    case 1:
        attr_str = "ON";
        break;
    default:
        attr_str = "BAD_VALUE";
        break;
    }

    strcpy(*attr_filterState_read,attr_str.c_str());
    attr.set_value( attr_filterState_read);
}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_autoFilterState
// 
// description : 	Extract real attribute values for autoFilterState acquisition result.
//
//-----------------------------------------------------------------------------
void Keithley428::read_autoFilterState(Tango::Attribute &attr)
{
	DEBUG_STREAM << "Keithley428::read_autoFilterState(Tango::Attribute &attr) entering... "<< endl;

    DeviceData din;
    DeviceData dout;

    string tmp_string;
    string selected_str;
    string attr_str;
    size_t pos;

    int r_v;
    int w_v;

    sprintf(tmp_buffer,"U0X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    dout = gpib_device->command_inout(m_write_read.c_str(),din);  

    dout >> tmp_string;

    pos = tmp_string.find("Z");
    pos = pos + 1;
    selected_str = tmp_string.substr(pos);
    r_v = atoi(selected_str.c_str());

    switch(r_v)
    {
    case 0:
        attr_str = "OFF";
        break;
    case 1:
        attr_str = "ON";
        break;
    default:
        attr_str = "BAD_VALUE";
        break;
    }

    strcpy(*attr_autoFilterState_read,attr_str.c_str());
    attr.set_value( attr_autoFilterState_read);
}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_Bypass
// 
// description : 	Extract real attribute values for Bypass acquisition result.
//
//-----------------------------------------------------------------------------
void Keithley428::read_Bypass(Tango::Attribute &attr)
{
    DEBUG_STREAM << "Keithley428::read_Bypass(Tango::Attribute &attr) entering... "<< endl; 

    DeviceData din;
    DeviceData dout;

    string tmp_string;
    string selected_str;
    size_t pos;

    int c_v;

    sprintf(tmp_buffer,"U0X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    dout = gpib_device->command_inout(m_write_read.c_str(),din);  

    dout >> tmp_string;

    pos = tmp_string.find("C");
    pos = pos + 1;
    selected_str = tmp_string.substr(pos);
    c_v = atoi(selected_str.c_str());

    attr_Bypass_write = c_v;

    attr.set_value( &attr_Bypass_write); 
}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::write_Bypass
// 
// description : 	Write Bypass attribute values to hardware.
//
//-----------------------------------------------------------------------------
void Keithley428::write_Bypass(Tango::WAttribute &attr)
{
    DEBUG_STREAM << "Keithley428::write_Bypass(Tango::WAttribute &attr) entering... "<< endl;

    DeviceData din;

    attr.get_write_value( attr_Bypass_write);

    if( (attr_Bypass_write < 0) || (attr_Bypass_write > 1) ){
        Tango::Except::throw_exception ((const char *)"Keithley428 error",
            (const char *)"Value out of range (off -> 0, on -> 1)",
            (const char *)"write_Bypass");
    }

    sprintf(tmp_buffer,"C%dX", attr_Bypass_write);
    strcpy(buffer,tmp_buffer);
    din << buffer;

    gpib_device->command_inout(m_write.c_str(),din);

}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_Overloaded
// 
// description : 	Extract real attribute values for Overloaded acquisition result.
//
//-----------------------------------------------------------------------------
void Keithley428::read_Overloaded(Tango::Attribute &attr)
{
    DEBUG_STREAM << "Keithley428::read_Overloaded(Tango::Attribute &attr) entering... "<< endl;  

    DeviceData din;
    DeviceData dout;

    string tmp_string;
    string selected_str;
    size_t pos;

    int overload_flag;

    sprintf(tmp_buffer,"U1X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    dout = gpib_device->command_inout(m_write_read.c_str(),din);  

    dout >> tmp_string;

    pos = 12;
    selected_str = tmp_string.substr(pos,1);
    overload_flag = atoi(selected_str.c_str());

    *attr_Overloaded_read = overload_flag;

    attr.set_value(attr_Overloaded_read); 
}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_GainStr
// 
// description : 	Extract real attribute values for GainStr acquisition result.
//
//-----------------------------------------------------------------------------
void Keithley428::read_GainStr(Tango::Attribute &attr)
{
    DEBUG_STREAM << "Keithley428::read_GainStr(Tango::Attribute &attr) entering... "<< endl;

    DeviceData din;
    DeviceData dout;

    string tmp_string;


    sprintf(tmp_buffer,"U3X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    dout = gpib_device->command_inout(m_write_read.c_str(),din);  

    dout >> tmp_string;

    strcpy(*attr_GainStr_read,tmp_string.c_str());

    attr.set_value( attr_GainStr_read);
}


//+----------------------------------------------------------------------------
//
// method : 		Keithley428::read_Gain
// 
// description : 	Extract real attribute values for Gain acquisition result.
//
//-----------------------------------------------------------------------------
void Keithley428::read_Gain(Tango::Attribute &attr)
{
    DEBUG_STREAM << "Keithley428::read_Gain(Tango::Attribute &attr) entering... "<< endl;

    DeviceData din;
    DeviceData dout;

    string tmp_string;
    string selected_str;
    size_t pos;

    int r_v;
    int w_v;

    sprintf(tmp_buffer,"U0X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    dout = gpib_device->command_inout(m_write_read.c_str(),din);  

    dout >> tmp_string;

    pos = tmp_string.find("R");
    pos = pos + 1;
    selected_str = tmp_string.substr(pos);
    r_v = atoi(selected_str.c_str());

    pos = tmp_string.find("W");
    pos = pos + 1;
    selected_str = tmp_string.substr(pos);
    w_v = atoi(selected_str.c_str());

    if(w_v == 0){
        attr_Gain_write = r_v;
    } else {
        attr_Gain_write = r_v + 1;
    }

    attr.set_value( &attr_Gain_write); 

}

//+----------------------------------------------------------------------------
//
// method : 		Keithley428::write_Gain
// 
// description : 	Write Gain attribute values to hardware.
//
//-----------------------------------------------------------------------------
void Keithley428::write_Gain(Tango::WAttribute &attr)
{
    DEBUG_STREAM << "Keithley428::write_Gain(Tango::WAttribute &attr) entering... "<< endl;

    DeviceData din;

    attr.get_write_value( attr_Gain_write);

    if( (attr_Gain_write < 0) || (attr_Gain_write > 11) ){
        Tango::Except::throw_exception ((const char *)"Keithley428 error",
            (const char *)"Value out of range (0-11)",
            (const char *)"write_Gain");
    }


    if(attr_Gain_write < 11){
        sprintf(tmp_buffer,"W0XR%dX", (int)attr_Gain_write);
        strcpy(buffer,tmp_buffer);
        din << buffer;
    } else {
        sprintf(tmp_buffer,"W1XR10X");
        strcpy(buffer,tmp_buffer);
        din << buffer;
    }


    gpib_device->command_inout(m_write.c_str(),din);

}



//+------------------------------------------------------------------
/**
 *	method:	Keithley428::perform_zero_correct
 *
 *	description:	method to execute "PerformZeroCorrect"
 *	Perform Zero correction.
 *
 *
 */
//+------------------------------------------------------------------
void Keithley428::perform_zero_correct()
{
    DEBUG_STREAM << "Keithley428::perform_zero_correct(): entering... !" << endl;

    //	Add your own code to control device here

    DeviceData din;

    sprintf(tmp_buffer,"C2X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    gpib_device->command_inout(m_write.c_str(),din);

}

//+------------------------------------------------------------------
/**
 *	method:	Keithley428::filter_on
 *
 *	description:	method to execute "FilterOn"
 *	Turn the filter ON
 *
 *
 */
//+------------------------------------------------------------------
void Keithley428::filter_on()
{
	DEBUG_STREAM << "Keithley428::filter_on(): entering... !" << endl;

	//	Add your own code to control device here

    DeviceData din;

    sprintf(tmp_buffer,"P1X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    gpib_device->command_inout(m_write.c_str(),din);

}

//+------------------------------------------------------------------
/**
 *	method:	Keithley428::filter_off
 *
 *	description:	method to execute "FilterOff"
 *	Turn the filter OFF
 *
 *
 */
//+------------------------------------------------------------------
void Keithley428::filter_off()
{
	DEBUG_STREAM << "Keithley428::filter_off(): entering... !" << endl;

	//	Add your own code to control device here

    DeviceData din;

    sprintf(tmp_buffer,"P0X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    gpib_device->command_inout(m_write.c_str(),din);

}

//+------------------------------------------------------------------
/**
 *	method:	Keithley428::auto_filter_on
 *
 *	description:	method to execute "AutoFilterOn"
 *	Enable Auto Filter
 *
 *
 */
//+------------------------------------------------------------------
void Keithley428::auto_filter_on()
{
	DEBUG_STREAM << "Keithley428::auto_filter_on(): entering... !" << endl;

	//	Add your own code to control device here

    //- read the current filterState
	Tango::Attribute &filterState = dev_attr->get_attr_by_name("filterState");
	this->read_filterState(filterState);

    string filter_state = *attr_filterState_read;

    if(filter_state == "ON")
    {
        Tango::Except::throw_exception(
				(const char *)"OPERATION_NOT_ALLOWED",
				(const char *)"Auto filter ON is not allowed when filter is already ON",
				(const char *)"Keithley428::auto_filter_on");
    }

    DeviceData din;

    sprintf(tmp_buffer,"Z1X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    gpib_device->command_inout(m_write.c_str(),din);

}

//+------------------------------------------------------------------
/**
 *	method:	Keithley428::auto_filter_off
 *
 *	description:	method to execute "AutoFilterOff"
 *	Disable Auto Filter
 *
 *
 */
//+------------------------------------------------------------------
void Keithley428::auto_filter_off()
{
	DEBUG_STREAM << "Keithley428::auto_filter_off(): entering... !" << endl;

	//	Add your own code to control device here

    DeviceData din;

    sprintf(tmp_buffer,"Z0X");
    strcpy(buffer,tmp_buffer);
    din << buffer;

    gpib_device->command_inout(m_write.c_str(),din);

}


}	//	namespace