找回密码
 注册
搜索

控制电源类设备 VC 程序

已有 120 次阅读2016-1-18 15:48 |个人分类:个人日志| 程序, 电源

主要使用控制电源的库.  hp663x2_32.lib,hp663x2_32.dll,hp663x2_32.h
项目引入即可.

// ResetDeviceDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "ResetDevice.h"
#include "ResetDeviceDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CResetDeviceDlg 对话框

PASDLib_USB m_USBArray[8];
bool thread_pause = false;
//DWORD dwValue;
HANDLE hThread;

CResetDeviceDlg::CResetDeviceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CResetDeviceDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CResetDeviceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CResetDeviceDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
//ON_EN_CHANGE(IDC_EDIT1, &CResetDeviceDlg::OnEnChangeEdit1)
ON_BN_CLICKED(IDOK, &CResetDeviceDlg::OnBnClickedOk)
//ON_BN_CLICKED(IDOK2, &CResetDeviceDlg::OnBnClickedOk2)
//ON_WM_TIMER()
END_MESSAGE_MAP()


// CResetDeviceDlg 消息处理程序

BOOL CResetDeviceDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
//  执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标

GetDlgItem(IDC_EDIT1)->SetWindowText("5");
GetDlgItem(IDC_EDIT2)->SetWindowText("5");
GetDlgItem(IDC_EDIT3)->SetWindowText("0");
GetDlgItem(IDC_EDIT4)->SetWindowText("20");
GetDlgItem(IDC_EDIT5)->SetWindowText("120");
GetDlgItem(IDC_EDIT6)->SetWindowText("1");
GetDlgItem(IDC_EDIT7)->SetWindowText("120");
// TODO: 在此添加额外的初始化代码

return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CResetDeviceDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。
//
HCURSOR CResetDeviceDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}


void CResetDeviceDlg::OnBnClickedOk()
{
//SetTimer(11,2000,NULL);

//hThread = 
AfxBeginThread(ExcuteProc, this);
}

UINT CResetDeviceDlg::ExcuteProc(LPVOID lParam)
{
// dwValue =GetCurrentThreadId(); 
CResetDeviceDlg * pThis = (CResetDeviceDlg *)lParam;
pThis->UpdateData(true);
CString   str1,str2,str3,str4,str5,str6,str7;
int nResult = 0;
int viStatus = 0;
double dbVol1 = 0;
//get data
pThis->GetDlgItemText(IDC_EDIT1,str1);
pThis->GetDlgItemText(IDC_EDIT2,str2);
pThis->GetDlgItemText(IDC_EDIT3,str3);
pThis->GetDlgItemText(IDC_EDIT4,str4);
pThis->GetDlgItemText(IDC_EDIT5,str5);
pThis->GetDlgItemText(IDC_EDIT6,str6);
pThis->GetDlgItemText(IDC_EDIT7,str7);

PowerUnit powerHandle;
memset(&powerHandle,0,sizeof(PowerUnit));
int timespan = 0;
int timespan_close =0;   //关机时间
int cnt = 0;
if ( ( timespan = atoi(str5)) <= 0 || atoi(str2)<= 0  || (cnt =atoi(str4)) <= 0 || (timespan_close = atoi(str7)) <= 0)
{
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("please input time span, Voltage value or times");
return -1;
}


powerHandle.dbVoltage = atoi(str2);//5.0;
powerHandle.nGPIBAddress = atoi(str3);//0;
powerHandle.nPowerAddress = atoi(str1);//5;
powerHandle.nPowerModel = AGILENT_66312;
powerHandle.nStatus = NEED_OPEN;
powerHandle.dbCurrent = atoi(str6);
double  vTemp = powerHandle.dbVoltage;
pThis->GetDlgItem(IDOK)->EnableWindow(false);
//pThis->GetDlgItem(IDCANCEL)->EnableWindow(false);
DWORD start_time = GetTickCount();
DWORD stop_time = start_time;
//DWORD pause_time = start_time;


nResult = PowerOpen(&powerHandle);
if( nResult ==0 )
{
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("PowerOpen Success");
do
{
//
nResult = PowerOutput(&powerHandle,OUTPUT_ON);
if( nResult ==0 )
{
Sleep(400);
viStatus = PowerMeasureVoltage(powerHandle,&dbVol1); //1
powerHandle.dbVoltageOffset = vTemp-dbVol1;//jww,new.//4.2-dbVol1;
if(powerHandle.dbVoltageOffset> 0.1 || powerHandle.dbVoltageOffset < -0.1 )
break;
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("PowerOutput On Success");
Sleep( timespan* 1000);
}else
{
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("PowerOutput On Fail");
break;
}

/*if( thread_pause == true)
break;
*/
nResult = PowerOutput(&powerHandle,OUTPUT_OFF);
if( nResult == 0 )
{
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("PowerOutput Off Success");
Sleep( timespan_close* 1000);
}else
{
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("PowerOutput Off Fail");
break;
}

/*
if( thread_pause == true)
break;
*/
stop_time = GetTickCount();
}while( stop_time - start_time < timespan*cnt*2*60*1000 );
}
else
{
pThis->GetDlgItem(IDC_STATIC)->SetWindowText("PowerOpen Fail");
}
PowerClose(powerHandle);
pThis->GetDlgItem(IDOK)->EnableWindow(true);
pThis->GetDlgItem(IDCANCEL)->EnableWindow(true);

return 0;
}

/*
void CResetDeviceDlg::OnBnClickedOk2()
{
// TODO: 在此添加控件通知处理程序代码
//PostThreadMessage(dwValue, WM_QUIT,0,0);

WaitForSingleObject(hThread, INFINITE); 
//thread_pause = true;
//Sleep(5000);
GetDlgItem(IDOK)->EnableWindow(true);
//GetDlgItem(IDCANCEL)->EnableWindow(true);
return;

}

void CResetDeviceDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值

if(nIDEvent==11)
    {
  WaitForSingleObject(hThread1,2000);
GetDlgItem(IDOK)->EnableWindow(true);
GetDlgItem(IDCANCEL)->EnableWindow(true);
  }


CDialog::OnTimer(nIDEvent);
}
*/

路过

雷人

握手

鲜花

鸡蛋

全部作者的其他最新日志

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-5-18 04:08 , Processed in 0.032479 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部