DCS_ctrl.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:9k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * DCS_ctrl.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * DC source control function source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <vcl.h>
- #ifndef HP661X_INCLUDE
- #include "hp661x.h"
- #endif
- #ifndef hp663x2_INCLUDE
- #include "hp663x2.h"
- #endif
- #ifndef hpe3631a_INCLUDE
- #include "hpe3631a.h"
- #endif
- #pragma hdrstop
- #ifndef _MFSETUPUTIL_H_
- #include "mfsetuputil.h"
- #endif
- // equipment
- #ifndef _DCS_COMMON_H_
- #include "dcs_common.h"
- #endif
- #ifndef _DCS_CTRL_H_
- #include "dcs_ctrl.h"
- #endif
- #ifndef _KEITHLEY_2306_H_
- #include "keithley_2306.h"
- #endif
- bool IS_AgilentPowerSupply_INITIALISE = false;
- //===========================================================================
- CDCSCTRL::CDCSCTRL( void )
- {
- }
- //---------------------------------------------------------------------------
- CDCSCTRL::~CDCSCTRL()
- {
- }
- //=============================================================================
- bool CDCSCTRL::DCS_Init(S_DCS *p_dcs)
- {
- if( p_dcs->device_type == AGILENT_661x )
- {
- if( hp661x_init( p_dcs->ADD.c_str(), 0, 0, &(p_dcs->vi) ) != VI_SUCCESS )
- {
- p_dcs->vi = NULL;
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_663x2 )
- {
- if( hp663x2_init(p_dcs->ADD.c_str(), 0, 0, &(p_dcs->vi) ) != VI_SUCCESS )
- {
- p_dcs->vi = NULL;
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_E3631A )
- {
- if( hpe3631a_init(p_dcs->ADD.c_str(), 0, 0, &(p_dcs->vi) ) != VI_SUCCESS )
- {
- p_dcs->vi = NULL;
- return false;
- }
- }
- else if( p_dcs->device_type == KEITHLEY_2306 )
- {
- if( kei2306_init(p_dcs->ADD.c_str(), &(p_dcs->RM), 0, 0, &(p_dcs->vi) ) != VI_SUCCESS )
- {
- p_dcs->vi = NULL;
- return false;
- }
- }
-
- IS_AgilentPowerSupply_INITIALISE = true;
- return true;
- }
- //--------------------------------------------------------------------------
- bool CDCSCTRL::DCS_outputVoltCurr( S_DCS *p_dcs, ViReal64 voltLev, ViReal64 currLev)
- {
- if( p_dcs->device_type == AGILENT_661x )
- {
- if( hp661x_outputVoltCurr( p_dcs->vi, voltLev, currLev ) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_663x2 )
- {
- if( hp663x2_outputVoltCurr(p_dcs->vi, voltLev, currLev) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_E3631A )
- {
- if( hpe3631a_current(p_dcs->vi, hpe3631a_VOLT_INST1, currLev) != VI_SUCCESS )
- {
- return false;
- }
- if( hpe3631a_voltage(p_dcs->vi, hpe3631a_VOLT_INST1, voltLev) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == KEITHLEY_2306 )
- {
- if( kei2306_outputVoltCurr( p_dcs->vi, voltLev, currLev) != VI_SUCCESS )
- {
- return false;
- }
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool CDCSCTRL::DCS_measureVolt( S_DCS *p_dcs, ViReal64 &voltLev )
- {
- if( p_dcs->device_type == AGILENT_661x )
- {
- if( hp661x_measureVolt( p_dcs->vi, &voltLev ) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if ( p_dcs->device_type == AGILENT_663x2 )
- {
- if( hp663x2_measureVolt( p_dcs->vi, HP663X2_MEAS_DC, &voltLev ) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_E3631A )
- {
- if( hpe3631a_measureVoltage_Q( p_dcs->vi, hpe3631a_VOLT_MEAS1, &voltLev ) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == KEITHLEY_2306 )
- {
- if( kei2306_measureVolt( p_dcs->vi, &voltLev ) != VI_SUCCESS )
- {
- return false;
- }
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool CDCSCTRL::DCS_close( S_DCS *p_dcs )
- {
- if( p_dcs->vi == NULL ) return true;
- if( p_dcs->device_type == AGILENT_661x )
- {
- if( hp661x_close(p_dcs->vi) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_663x2 )
- {
- if( hp663x2_close(p_dcs->vi) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == AGILENT_E3631A )
- {
- if( hpe3631a_close(p_dcs->vi) != VI_SUCCESS )
- {
- return false;
- }
- }
- else if( p_dcs->device_type == KEITHLEY_2306 )
- {
- if( kei2306_close( p_dcs->RM, p_dcs->vi ) != VI_SUCCESS )
- {
- return false;
- }
- }
- p_dcs->vi = NULL;
-
- return true;
- }
- //===========================================================================
- ////////////////////////// string ///////////////////////////////////
- //===========================================================================
- //---------------------------------------------------------------------------
- int CDCSCTRL::DCS_StringToDeviceType( AnsiString as_str )
- {
- int device_type;
- if( as_str.AnsiCompareIC(AGILENT_661x_STR) == 0 )
- {
- device_type = AGILENT_661x;
- }
- else if( as_str.AnsiCompareIC(AGILENT_663x2_STR) == 0 )
- {
- device_type = AGILENT_663x2;
- }
- else if( as_str.AnsiCompareIC(AGILENT_E3631A_STR) == 0 )
- {
- device_type = AGILENT_E3631A;
- }
- else
- {
- device_type = KEITHLEY_2306;
- }
- return device_type;
- }
- //---------------------------------------------------------------------------
- AnsiString CDCSCTRL::DCS_ReadGPIBAddress( S_DCS *p_dcs )
- {
- AnsiString as_addr = "GPIB0::5::INSTR";
- switch( p_dcs->device_type )
- {
- case AGILENT_661x:
- as_addr = read_661x_GPIB_Address( "MF_setup.txt", Application->ExeName );
- break;
- case AGILENT_663x2:
- as_addr = read_663x2_GPIB_Address( "MF_setup.txt", Application->ExeName );
- break;
- case AGILENT_E3631A:
- as_addr = read_E3631A_GPIB_Address( "MF_setup.txt", Application->ExeName );
- break;
- case KEITHLEY_2306:
- as_addr = read_Keithley2306_GPIB_Address( "MF_setup.txt", Application->ExeName );
- break;
- }
- return as_addr;
- }