⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dpi515_srq_exdlg.cpp

📁 压力控制器通讯源代码
💻 CPP
字号:
// DPI515_SRQ_ExDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DPI515_SRQ_Ex.h"
#include "DPI515_SRQ_ExDlg.h"
#include "visa.h"
#include "visacomm.h"
#include "dpi515com.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


// event handler parameters
extern ViAddr      uhandle;
extern ViUInt16    SRQStatus;
extern ViSession   Sessionparam;
extern ViEventType EventTypeparam;
extern ViAddr      Addressparam;
extern ViBoolean   stopflag;

//cCommunications theVISA;
cDPI515Communications theDPI515;
extern CDPI515_SRQ_ExApp theApp;
#define TIMER_1	1000

CDPI515_SRQ_ExDlg * pDialog;

void displaySRQMessage(short SRQ);
/////////////////////////////////////////////////////////////////////////////
// CDPI515_SRQ_ExDlg dialog

CDPI515_SRQ_ExDlg::CDPI515_SRQ_ExDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDPI515_SRQ_ExDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDPI515_SRQ_ExDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	pDialog = this;
	m_bControlling = false;
}

void CDPI515_SRQ_ExDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDPI515_SRQ_ExDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDPI515_SRQ_ExDlg, CDialog)
	//{{AFX_MSG_MAP(CDPI515_SRQ_ExDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_FINDRESOURCES, OnFindresources)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_OPEN, OnOpenChannel)
	ON_BN_CLICKED(IDC_VENT, OnVent)
	ON_BN_CLICKED(IDC_GETRANGESBTN, OnGetRanges)
	ON_BN_CLICKED(IDC_CHANGERANGE, OnChangerange)
	ON_BN_CLICKED(IDC_CONTROL, OnControl)
	ON_BN_CLICKED(IDC_SENDSETPOINT, OnSendsetpoint)
	ON_BN_CLICKED(IDC_OK, OnClickedOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDPI515_SRQ_ExDlg message handlers

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

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_viStatus = -1;
	CStatic * pStatic = (CStatic *)GetDlgItem(IDC_PRESSURE);
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight = 40;
	strcpy(lf.lfFaceName, "Arial");
	m_font.CreateFontIndirect(&lf);
	pStatic->SetFont(&m_font);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDPI515_SRQ_ExDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		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;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDPI515_SRQ_ExDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/******************************************************************************/
/* Function:    SRQHandler                                                    */
/* Author:      Alaster Jones                                                 */
/* Purpose:     SRQ Handling function                                         */
/* Inputs:      session, event type, event, user handle                       */
/* Outputs:     status                                                        */
/* Description: The handler function. The instrument session, the type of     */
/*              event, and a handle to the event are passed to the function   */
/*              along with a user handle which is basically a label that      */
/*              could be used to reference the handler. The only thing done   */
/*              in the handler is to set a flag that allows the program to    */
/*              finish.  Always return VI_SUCCESS from your handler.          */
/******************************************************************************/
ViStatus _VI_FUNCH SRQHandler(ViSession vi, ViEventType etype, ViEvent event, ViAddr userHandle)
{
    // ONLY APPLICABLE TO IEEE COMMS
    USHORT srq;
    short sReg = 0;

    stopflag = VI_TRUE;
    Sessionparam = vi;
    EventTypeparam = etype;
    Addressparam = userHandle;

    theDPI515.getStatusByte(vi, &srq);
    SRQStatus = srq;

    if (SRQStatus >= 192) // get the pressure operations register
    {
        theDPI515.getPressureOperationsRegister(&sReg);
		pDialog->displaySRQMessage(sReg);
    }

    return VI_SUCCESS;
}

void CDPI515_SRQ_ExDlg::OnFindresources() 
{
	CButton * pBtn = (CButton*) GetDlgItem(IDC_FINDRESOURCES);
	CListBox * pLB = (CListBox*) GetDlgItem(IDC_INSTRUMENTS);
	
	pLB->ResetContent();
	pBtn->SetWindowText("searching...");
	theDPI515.findResources();

	short numResrc = theDPI515.getnumResources();
	short i = 0;
	while(i <= numResrc)
	{
		pLB->InsertString(-1, theDPI515.getResources(i));
		i++;
	};
	pBtn->SetWindowText("find VISA resources");
}	

void CDPI515_SRQ_ExDlg::Close()
{
	KillTimer(TIMER_1);
	theDPI515.closeCommunications();
}

void CDPI515_SRQ_ExDlg::startTalking()
{
	theDPI515.setIEEE();
	SetTimer(TIMER_1,500, NULL);
}

void CDPI515_SRQ_ExDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	double dPressure = 0.0;
	char strPressure[20];
	theDPI515.getPressure(&dPressure);
	CStatic * pStat = (CStatic *)GetDlgItem(IDC_PRESSURE);
	sprintf(strPressure, "%.3f",dPressure);
	pStat->SetWindowText(strPressure);

	//CDialog::OnTimer(nIDEvent);
}

void CDPI515_SRQ_ExDlg::OnOpenChannel() 
{
	// TODO: Add your control notification handler code here
	CButton * pBtn = (CButton*) GetDlgItem(IDC_OPEN);	
	CListBox * pLB = (CListBox*) GetDlgItem(IDC_INSTRUMENTS);
	char strChannel[100];
	pLB->GetText(pLB->GetCurSel(), strChannel);
	m_viStatus = theDPI515.openCommsChannel(strChannel);//.operator LPCTSTR);
	theDPI515.instrumentInitialisation();
	startTalking();
	pBtn->DestroyWindow();
}

void CDPI515_SRQ_ExDlg::OnVent() 
{
	// TODO: Add your control notification handler code here
	theDPI515.setVent(TRUE);
}

void CDPI515_SRQ_ExDlg::OnGetRanges() 
{
	// TODO: Add your control notification handler code here
	short i = 0;
	CListBox * pLB = (CListBox*) GetDlgItem(IDC_RANGES);
	pLB->ResetContent();
	theDPI515.getInstrumentRanges();
	while(i <= theDPI515.getnumRanges())
	{
		pLB->InsertString(-1, theDPI515.getinstrRange(i));
		i++;
	}
}

void CDPI515_SRQ_ExDlg::OnChangerange() 
{
	// TODO: Add your control notification handler code here
	CListBox * pLB = (CListBox*) GetDlgItem(IDC_RANGES);
	char  strRange[20];
	pLB->GetText(pLB->GetCurSel(), strRange);
	theDPI515.setCurrentRange(strRange);	
}

void CDPI515_SRQ_ExDlg::displaySRQMessage(short SRQ)
{
	char strMesg[100];
	
	sprintf(strMesg, "SRQ returned: %d, ", SRQ);
	switch(SRQ)
	{
	case SRQ_VENT: // VENT
		strcat(strMesg,"Vent complete");
		break;
	case SRQ_RANGE: // RANGE CHANGE
		strcat(strMesg,"Range change complete");
		break;
	case SRQ_INLIMITS: // IN LIMITS
		strcat(strMesg,"In limits");
		break;
	case SRQ_ZERO: // ZERO
		strcat(strMesg,"Zero complete");
		break;
	case SRQ_AUTOZERO: // AUTO ZERO
		strcat(strMesg,"Auto zero complete");
		break;
	case SRQ_FILLTIMEOUT: // FILL TIMEOUT
		strcat(strMesg,"Fill timeout");
		break;
	case SRQ_IDLETIMEOUT: // IDLE TIMEOUT
		strcat(strMesg,"Idle timeout");
		break;
	case SRQ_SWITCH: // SWITCH
		strcat(strMesg,"Switch contacts changed state");
		break;
	}

	MessageBox(strMesg);
}

void CDPI515_SRQ_ExDlg::OnControl() 
{
	CButton * pBtn = (CButton*) GetDlgItem(IDC_CONTROL);

	if(m_bControlling)
	{
		theDPI515.setControllerOnOff(0); // turn off
		pBtn->SetWindowText("Control");
		m_bControlling = FALSE;
	}
	else
	{
		theDPI515.setControllerOnOff(1); // turn on
		pBtn->SetWindowText("Measure");
		m_bControlling = TRUE;
	}
}

void CDPI515_SRQ_ExDlg::OnSendsetpoint() 
{
	CEdit * pEdit = (CEdit *) GetDlgItem(IDC_SETPOINT);
	//pEdit->UpdateData(TRUE);
	char strVal[12];
	pEdit->GetWindowText(strVal, 10);
	m_Setpoint = atof(strVal);
	TRACE("Setpoint value: %f", pDialog->m_Setpoint);
	theDPI515.setSetpoint(m_Setpoint);	
}

void CDPI515_SRQ_ExDlg::OnOK() 
{
}

void CDPI515_SRQ_ExDlg::OnClickedOk() 
{
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -