// Test_CE_DPPDlg.cpp : implementation file // #include "stdafx.h" #include "Test_CE_DPP.h" #include "Test_CE_DPPDlg.h" #include "DppApi.h" #include "ViewDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #endif //Amptek DPP Device Types #define DPPNONE 0x0 #define DPPDP4 0x1 #define DPPPX4 0x2 #define DPPDP4EMUL 0x3 #define DPPDP5 0x4 // CTest_CE_DPPDlg dialog CTest_CE_DPPDlg::CTest_CE_DPPDlg(CWnd* pParent /*=NULL*/) : CDialog(CTest_CE_DPPDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTest_CE_DPPDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CTest_CE_DPPDlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_WM_CLOSE() ON_WM_DESTROY() ON_WM_TIMER() //ON_COMMAND(ID_ACQUISITION, OnAcquisition) ON_COMMAND(ID_ACQUISITION_ATTACHDPP, OnAttachDPP) ON_COMMAND(ID_ACQUISITION_STARTACQUISITION, OnStartAcquisition) ON_COMMAND(ID_ACQUISITION_STOPACQUISITION, OnStopAcquisition) ON_COMMAND(ID_ACQUISITION_CLEARSPECTRUM, OnClearSpectrum) //ON_COMMAND(ID_VIEWSETUP, OnViewSetup) ON_COMMAND(ID_VIEWSETUP_SHOWDPPCONFIGURATION, OnShowDPPConfiguration) ON_COMMAND(ID_VIEWSETUP_SHOWDPPSTATUS, OnShowDPPStatus) ON_COMMAND(ID_VIEWSETUP_LOADConfigurationFILE, OnLoadConfigurationFile) ON_COMMAND(ID_VIEWSETUP_SAVEConfigurationFILE, OnSaveConfigurationFile) ON_COMMAND(ID_VIEWSETUP_TUNEFASTTHRESHOLD, OnTuneFastThreshold) ON_COMMAND(ID_VIEWSETUP_TUNEINPUTOFFSET, OnTuneInputOffset) //End Menubar commands ON_BN_CLICKED(IDC_GETDATA_BUTTON, &CTest_CE_DPPDlg::OnBnClickedGetData) ON_WM_PAINT() END_MESSAGE_MAP() // CTest_CE_DPPDlg message handlers BOOL CTest_CE_DPPDlg::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 //Create 'Pocket PC' type MenuBar SHMENUBARINFO info; info.cbSize = sizeof(info); //info.hwndParent = m_hWnd; info.hwndParent = this->m_hWnd; info.dwFlags = 0; info.nToolBarId = IDR_MENU1; //info.hInstRes = ::AfxGetInstanceHandle(); info.hInstRes = GetModuleHandle(NULL); //info.dwFlags = SHCMBF_HIDESIPBUTTON | SHCMBF_EMPTYBAR; info.dwFlags = SHCMBF_HMENU; info.nBmpId = 0; info.cBmpImages = 0; SHCreateMenuBar(&info); // TODO: Add extra initialization here PenBLACK.CreatePen(PS_SOLID,1,RGB(0,0,0)); PenBLUE.CreatePen(PS_SOLID,1,RGB(0,0,255)); PenRED.CreatePen(PS_SOLID,1,RGB(255,0,0)); PenGREEN.CreatePen(PS_SOLID,1,RGB(0,255,0)); PenYELLOW.CreatePen(PS_SOLID,1,RGB(255,255,0)); for(int idxBuff = 0; idxBuff < MAX_DPP_BUFFER_SIZE; idxBuff++) { PlotBuffer[idxBuff] = 0; //holds y position data for cursor updates } XPlotMAX = 0; YPlotMAX = 0; OptScaleType = false; OptPlotType = false; objDppApi = 0; bAcqData = FALSE; bApiHasCfg = FALSE; m_nTimerId = 0; return TRUE; // return TRUE unless you set the focus to a control } #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) void CTest_CE_DPPDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_TEST_CE_DPP_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_TEST_CE_DPP_DIALOG)); } } #endif void CTest_CE_DPPDlg::OnBnClickedGetData() { GetDlgItem(IDC_GETDATA_BUTTON)->EnableWindow(false); // disable this button until done OnAttachDPP(); GetDlgItem(IDC_GETDATA_BUTTON)->EnableWindow(true); } ////Connect to DPP, Enable MCA, Plot Data //void CTest_CE_DPPDlg::OnBnClickedGetData() //{ // GetDlgItem(IDC_GETDATA_BUTTON)->EnableWindow(false); // disable this button until done // CString dppStat; // WCHAR szStatus[2000]; // CString cstrStatus; // status display string // int NumChan; // number of acquired channels // DPP_STATUS StatusLst; // status structure // CString cstrMsg; // BOOL Dpp80MHzMode; // test message display string // int DppDevice; // // int NumDev; // number of usb devices // NumDev = DlgOpenDppApi(); // if (NumDev > 0) { // GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("StatusStruct")); // GetStatusStruct(objDppApi, true, &StatusLst); // get device status structure // if (StatusLst.SerialNumber < 1) { // GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Device status error.")); // bApiHasCfg = FALSE; // } else if (! StatusLst.SwConfigRcvd) { // GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Please configure device \n before taking data.")); // bApiHasCfg = FALSE; // } else { // //WCHAR szConfig[2000]; // //CString cstrConfig; // config display string // if (!bApiHasCfg) { // DppDevice = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); // if (DppDevice > DPPPX4) { // Dpp80MHzMode = (BOOL) Get80MHzMode(objDppApi); // SetFPGAClockDefault (objDppApi, Dpp80MHzMode, DppDevice); // } // GetConfigFromDpp(objDppApi); // configure px4 from stored configuration // bApiHasCfg = TRUE; // //GetConfigString(objDppApi, szConfig, 2000); // //cstrConfig = szConfig; // } // if (! StatusLst.StatMcaEnabled) { // PauseDppData(objDppApi, false); // enable data acquisition // } // GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("StatusString")); // GetStatusString(objDppApi, 1, szStatus, 2000); // get device status display string // cstrStatus = szStatus; // GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(cstrStatus); // NumChan = GetDppData(objDppApi, DataBuffer); // aquire data // PlotData(DataBuffer, NumChan); // plot data // GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("DATA Updated.")); // } // } // //DlgCloseDppApi(); // GetDlgItem(IDC_GETDATA_BUTTON)->EnableWindow(true); //} void CTest_CE_DPPDlg::UpdateData() { WCHAR szStatus[2000]; CString cstrStatus; // status display string int NumChan; // number of acquired channels DPP_STATUS StatusLst; // status structure int NumDev; // number of usb devices BOOL Dpp80MHzMode; int DppDevice; NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status structure if (StatusLst.SerialNumber < 1) { bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { bApiHasCfg = FALSE; } else { if (!bApiHasCfg) { DppDevice = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); if (DppDevice > DPPPX4) { Dpp80MHzMode = (BOOL) Get80MHzMode(objDppApi); SetFPGAClockDefault (objDppApi, Dpp80MHzMode, DppDevice); } GetConfigFromDpp(objDppApi); // configure px4 from stored configuration bApiHasCfg = TRUE; } GetStatusString(objDppApi, 1, szStatus, 2000); // get device status display string cstrStatus = szStatus; GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(cstrStatus); NumChan = GetDppData(objDppApi, DataBuffer); // aquire data PlotData(DataBuffer, NumChan); // plot data GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("Data Updated.")); } } } void CTest_CE_DPPDlg::MCAEnable(BOOL EnableAcq) { DPP_STATUS StatusLst; // status structure int NumDev; // number of usb devices NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status structure if (StatusLst.SerialNumber < 1) { bApiHasCfg = FALSE; } else { PauseDppData(objDppApi, (!EnableAcq)); // enable data acquisition } } } //------------------------------------------------------------------- // UpdatePlot // Draws the plot display with the current plot buffer //------------------------------------------------------------------- void CTest_CE_DPPDlg::UpdatePlot(CDC *dc) { CRect rect; int YOrg; double YSizer; LONG l_Rect_Bottom; // draw bounding box GetClientRect(&rect); if (rect.Height() > rect.Width()) { YSizer = 2; } else { YSizer = 1.5; } l_Rect_Bottom = (LONG)((((double)rect.bottom) / YSizer ) + 2.0); dc->SelectObject(&PenBLACK); //dc->Rectangle(rect.left,rect.top,rect.right,rect.bottom); dc->Rectangle(rect.left,rect.top,rect.right,l_Rect_Bottom); double XScaleFactor = (double) rect.Width(); if (XPlotMAX > 0) XScaleFactor /= (double)(XPlotMAX + 1); //double YScaleFactor = (double) rect.Height() / 2.0 ; double YScaleFactor = (double) rect.Height() / YSizer ; if (YPlotMAX > 0) YScaleFactor /= (double)(YPlotMAX + 1); //YScaleFactor *= -1.0; //YOrg = (int)((double) rect.Height() / 2.0); YOrg = (int)((double) rect.Height() / YSizer); dc->SelectObject(&PenRED); double y1, y2; for(int X=0; X<=XPlotMAX; X++) { y1 = PlotBuffer[X]; if (y1 < 0) { y1 = 0; } y2 = PlotBuffer[X + 1]; if (y2 < 0) { y2 = 0; } dc->LineTo((int)(X * XScaleFactor), YOrg - (int)(y1 * YScaleFactor)); dc->LineTo((int)((X + 1) * XScaleFactor), YOrg - (int)(y2 * YScaleFactor)); dc->MoveTo((int)(X * XScaleFactor), YOrg - 0); dc->LineTo((int)(X * XScaleFactor), YOrg - (int)(y1 * YScaleFactor)); dc->MoveTo((int)((X + 1) * XScaleFactor), YOrg - 0); dc->LineTo((int)((X + 1) * XScaleFactor), YOrg - (int)(y2 * YScaleFactor)); } } //------------------------------------------------------------------- // PlotData // Calculates and saves the plot buffer data then calls UpdatePlot //------------------------------------------------------------------- void CTest_CE_DPPDlg::PlotData(long *DataBuffer, int NumChan) { int i; long YMAX; XPlotMAX = NumChan - 1; if (NumChan > 0) { //if number of channels > 0 plot data YMAX = 0; for(i = 0; i < NumChan; i++) { //get the largest value to be displayed if (OptScaleType) { //get the Y maximum value for the select scale if (log(0.1 + DataBuffer[i]) > YMAX) { YMAX = (long)log(0.1 + DataBuffer[i]); } } else { if (DataBuffer[i] > YMAX) { YMAX = (long)DataBuffer[i]; } } } if (YMAX < 1) { return; } //if no y scale exit sub if (OptScaleType) { //adjust plot to include entire high peak YMAX = (YMAX * 10) + 10; } else { if (YMAX < 20) { YMAX = YMAX + 2; } else { YMAX = YMAX + 10; } } for (i = 0; i < NumChan;i++ ) { //get the largest value to be displayed if (OptScaleType) { PlotBuffer[i] = (long)log(0.1 + DataBuffer[i]) * 10; } else { PlotBuffer[i] = (long)DataBuffer[i]; } } YPlotMAX = YMAX; RequestRedraw(); } } void CTest_CE_DPPDlg::RequestRedraw() { CRect rect; CClientDC dc(this); GetClientRect(&rect); InvalidateRect(&rect); } void CTest_CE_DPPDlg::OnPaint() { CPaintDC dc(this); // device context for painting UpdatePlot(&dc); // TODO: Add your message handler code here // Do not call CDialog::OnPaint() for painting messages } //void CTest_CE_DPPDlg::OnAcquisition() void CTest_CE_DPPDlg::OnAttachDPP() { int NumDev; // number of usb devices WCHAR szStatus[2000]; CString cstrStatus; // status display string DPP_STATUS StatusLst; // status structure NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("StatStruct")); GetStatusStruct(objDppApi, true, &StatusLst); // get device status structure if (StatusLst.SerialNumber < 1) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Device status error.")); bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Please configure device \n before taking data.")); bApiHasCfg = FALSE; } else { GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("StatString")); GetStatusString(objDppApi, 1, szStatus, 2000); // get device status display string cstrStatus = szStatus; GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(cstrStatus); if (StatusLst.StatMcaEnabled) { OnStartAcquisition(); } else { UpdateData(); } GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("Attached DPP")); } } else { cstrStatus = "No devices found."; GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(cstrStatus); } GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("AttachDPP")); } void CTest_CE_DPPDlg::OnStartAcquisition() { DPP_STATUS StatusLst; int NumDev; BOOL Dpp80MHzMode; int DppDevice; if (bAcqData) { return; } NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status (part 1) if (StatusLst.SerialNumber < 1) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Device status error.")); bApiHasCfg = FALSE; OnStopAcquisition(); } else if (! StatusLst.SwConfigRcvd) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Please configure device \n before taking data.")); bApiHasCfg = FALSE; OnStopAcquisition(); } else { if (! bApiHasCfg ) { DppDevice = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); if (DppDevice > DPPPX4) { Dpp80MHzMode = (BOOL) Get80MHzMode(objDppApi); SetFPGAClockDefault (objDppApi, Dpp80MHzMode, DppDevice); } GetConfigFromDpp(objDppApi); // configure px4 from stored configuration bApiHasCfg = TRUE; } if (! StatusLst.StatMcaEnabled) { PauseDppData(objDppApi, false); // enable data acquisition if necessary } m_nEventId = 1; m_nElapse = 2000; m_nTimerId = SetTimer(m_nEventId, m_nElapse, NULL); // start the data acquisition timer bAcqData = TRUE; GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("Acquiring...")); } } else { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("No device detected.")); OnStopAcquisition(); } } void CTest_CE_DPPDlg::OnStopAcquisition() { CString cstrStatusWin; MCAEnable(FALSE); cstrStatusWin = "Stop Acquisition."; GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(cstrStatusWin); if (m_nTimerId != 0) { //timer with WM_TIMER/eventid KillTimer(m_nEventId); m_nTimerId = 0; bAcqData = FALSE; GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("Stopped.")); } UpdateData(); } void CTest_CE_DPPDlg::OnClearSpectrum() { int NumDev; NumDev = DlgOpenDppApi(); if (NumDev > 0) { for(int idxBuff = 0; idxBuff < MAX_DPP_BUFFER_SIZE; idxBuff++) { PlotBuffer[idxBuff] = 0; //holds y position data for cursor updates } ClearDppData(objDppApi, TRUE); GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("Data Cleared")); RequestRedraw(); } } //void CTest_CE_DPPDlg::OnViewSetup() void CTest_CE_DPPDlg::OnShowDPPConfiguration() { WCHAR szConfig[2000]; CString cstrConfig; // config display string DPP_STATUS StatusLst; int NumDev; CViewDialog dlg; BOOL Dpp80MHzMode; int DppDevice; NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status (part 1) if (StatusLst.SerialNumber < 1) { cstrConfig = "Device status error."; bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { cstrConfig = "Please configure device \n before taking data."; bApiHasCfg = FALSE; } else { DppDevice = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); if (DppDevice > DPPPX4) { Dpp80MHzMode = (BOOL) Get80MHzMode(objDppApi); SetFPGAClockDefault (objDppApi, Dpp80MHzMode, DppDevice); } GetConfigFromDpp(objDppApi); // configure px4 from stored configuration bApiHasCfg = TRUE; GetConfigString(objDppApi, szConfig, 2000); cstrConfig = szConfig; } } else { cstrConfig = "No devices found."; } dlg.cstrConfig = cstrConfig; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } } void CTest_CE_DPPDlg::OnShowDPPStatus() { int NumDev; // number of usb devices WCHAR szStatus[2000]; CString cstrStatus; // status display string DPP_STATUS StatusLst; // status structure CViewDialog dlg; NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetDlgItem(IDC_MSG_EDIT)->SetWindowText(_T("StatStruct")); GetStatusStruct(objDppApi, true, &StatusLst); // get device status structure if (StatusLst.SerialNumber < 1) { cstrStatus = "Device status error."; bApiHasCfg = FALSE; } else { GetStatusString(objDppApi, 1, szStatus, 2000); // get device status display string cstrStatus = szStatus; if (! StatusLst.SwConfigRcvd) { cstrStatus += _T("DPP not configured. \n Please configure device \n before taking data."); bApiHasCfg = FALSE; } } } else { cstrStatus = "No devices found."; } dlg.cstrConfig = cstrStatus; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } } void CTest_CE_DPPDlg::OnLoadConfigurationFile() { WCHAR szConfig[2000]; CString cstrConfig; // config display string DPP_STATUS StatusLst; int NumDev; CString strFileName; long lenFilename; BOOL HaveFileCfg; CViewDialog dlg; int DppDeviceType; HaveFileCfg = FALSE; if(PromptCfgFileName(&strFileName, TRUE)) { NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status (part 1) if (StatusLst.SerialNumber < 1) { cstrConfig = "Device status error."; bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { cstrConfig = "Please configure device \n before taking data."; bApiHasCfg = FALSE; } else { if (AfxMessageBox(_T("Filename:\n") + strFileName + _T("\n Continue?"),MB_YESNO) == IDNO) { return; } lenFilename = strFileName.GetLength(); const LPTSTR lpFname = strFileName.GetBuffer(0); DppDeviceType = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); GetConfigFromFile(objDppApi, lpFname, lenFilename, DppDeviceType); HaveFileCfg = TRUE; GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Configuration loaded from file.")); if (AfxMessageBox(_T("Review Configuration?"),MB_YESNO) == IDYES) { GetConfigString(objDppApi, szConfig, 2000); cstrConfig = szConfig; dlg.cstrConfig = cstrConfig; int nResponse = dlg.DoModal(); } if (AfxMessageBox(_T("Send Configuration \n to DPP?"),MB_YESNO) == IDYES) { SendConfigToDpp(objDppApi); bApiHasCfg = TRUE; GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T( "Configuration sent to DPP.")); } } } else { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("No devices found.")); } } else { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("File open cancelled.")); } } int CTest_CE_DPPDlg::GetDppDeviceType(double dppFirmware, int StatDevInd) { int dppDeviceType; BOOL isDPP5; if (dppFirmware >= 5.0) { // DPP5 20071015 // device is DPP5 if firmware >= 5.0 isDPP5 = TRUE; } else { isDPP5 = FALSE; } dppDeviceType = ((StatDevInd + 1) + ((int)isDPP5 * 2)); // device indicator from status return dppDeviceType; } // saves dpp device configuration to file void CTest_CE_DPPDlg::OnSaveConfigurationFile() { WCHAR szConfig[2000]; CString cstrConfig; // config display string DPP_STATUS StatusLst; int NumDev; CString strFileName; long lenFilename; BOOL Dpp80MHzMode; int DppDevice; CViewDialog dlg; if(PromptCfgFileName(&strFileName, FALSE)) { NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status (part 1) if (StatusLst.SerialNumber < 1) { cstrConfig = "Device status error."; bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { cstrConfig = "Please configure device \n before taking data."; bApiHasCfg = FALSE; } else { DppDevice = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); if (DppDevice > DPPPX4) { Dpp80MHzMode = (BOOL) Get80MHzMode(objDppApi); SetFPGAClockDefault (objDppApi, Dpp80MHzMode, DppDevice); } GetConfigFromDpp(objDppApi); // configure px4 from stored configuration bApiHasCfg = TRUE; GetConfigString(objDppApi, szConfig, 2000); cstrConfig = szConfig; if (AfxMessageBox(_T("Filename:\n") + strFileName + _T("\n Continue?"),MB_YESNO) == IDNO) { return; } //AfxMessageBox(strFileName); //strFileName = "\\My Documents\\DPPCFG.cfg"; lenFilename = strFileName.GetLength(); const LPTSTR lpFname = strFileName.GetBuffer(0); SaveConfigToFile(objDppApi, lpFname, lenFilename); GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Configuration saved to file.")); } } else { cstrConfig = "No devices found."; } } else { cstrConfig = "File save cancelled."; } dlg.cstrConfig = cstrConfig; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } } void CTest_CE_DPPDlg::OnTuneFastThreshold() { DPP_STATUS StatusLst; int NumDev; NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status (part 1) if (StatusLst.SerialNumber < 1) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Device status error.")); bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Please configure device \n before tuning.")); bApiHasCfg = FALSE; } else if (! StatusLst.StatMcaEnabled) { AfxMessageBox(_T("Please start acquisition\nand remove source\nbefore Tuning Fast Threshold")); } else { TuneFastThreshold(objDppApi); AfxMessageBox(_T("Please wait 2 sec.\nReload Config from DPP\nCheck Fast Threshold")); } } else { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("No devices found.")); } } void CTest_CE_DPPDlg::OnTuneInputOffset() { DPP_STATUS StatusLst; int NumDev; NumDev = DlgOpenDppApi(); if (NumDev > 0) { GetStatusStruct(objDppApi, true, &StatusLst); // get device status (part 1) if (StatusLst.SerialNumber < 1) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Device status error.")); bApiHasCfg = FALSE; } else if (! StatusLst.SwConfigRcvd) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Please configure device \n before tuning.")); bApiHasCfg = FALSE; } else if ((! StatusLst.StatDevInd) && (StatusLst.Firmware < 5.0)) { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("DP4 does not have \n input offset tuning.")); } else { //AfxMessageBox(_T("TuneInputOffset")); TuneInputOffset(objDppApi); AfxMessageBox(_T("Please wait 2 sec.\nReload Config from DPP\nCheck Input Offset")); } } else { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("No devices found.")); } } void CTest_CE_DPPDlg::DlgCloseDppApi() { if (m_nTimerId != 0) { //timer with WM_TIMER/eventid KillTimer(m_nEventId); m_nTimerId = 0; bAcqData = FALSE; } if (objDppApi != 0) { CloseUSBDevice (objDppApi); // close usb CloseDppApi (objDppApi); // close DPPAPI objDppApi = 0; } } int CTest_CE_DPPDlg::DlgOpenDppApi() { int NumDev; if (objDppApi == 0) { bApiHasCfg = FALSE; objDppApi = OpenDppApi(); // Create/Open DPPAPI NumDev = OpenUSBDevice(objDppApi); // Open USB communications } else { NumDev = MonitorUSBDppDevices(objDppApi); } if (NumDev == 0) { bApiHasCfg = FALSE; } return NumDev; } void CTest_CE_DPPDlg::OnClose() { // TODO: Add your message handler code here and/or call default //AfxMessageBox(_T("OnClose")); DlgCloseDppApi(); CDialog::OnClose(); } void CTest_CE_DPPDlg::OnDestroy() { CDialog::OnDestroy(); DlgCloseDppApi(); //AfxMessageBox(_T("OnDestroy")); // TODO: Add your message handler code here } CString CTest_CE_DPPDlg::ConfigDoubleValCStr(LPCTSTR lpstrLabel, double dblValue) { CString strVal(""); CString fmtStr(""); fmtStr = fmtStr + lpstrLabel + _T("%.0f\r\n"); strVal.Format((LPCTSTR)fmtStr, dblValue); return strVal; } //------------------------------------------------------------------- // OnTimer // Data acquisition timer, calls for spectrum data when timer fires //------------------------------------------------------------------- void CTest_CE_DPPDlg::OnTimer(UINT nIDEvent) { int NumDev; // number of usb devices //WCHAR szStatus[2000]; // status text CString cstrStatus; // status display string int NumChan; // number of acquired channels DPP_STATUS StatusLst; // holds dpp status in a structure BOOL Dpp80MHzMode; int DppDevice; if (nIDEvent == 1) { NumDev = DlgOpenDppApi(); if (NumDev > 0) { // proceed if a device is attached GetStatusStruct(objDppApi, true, &StatusLst); // get device status structure if (StatusLst.SerialNumber < 1) { // if no serial number device is not ready GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Device status error.")); bApiHasCfg = FALSE; OnStopAcquisition(); } else if (! StatusLst.SwConfigRcvd) { // if dpp not configured display message GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("Please configure device \n before taking data.")); bApiHasCfg = FALSE; OnStopAcquisition(); } else { if (!bApiHasCfg) { DppDevice = GetDppDeviceType(StatusLst.Firmware, StatusLst.StatDevInd); if (DppDevice > DPPPX4) { Dpp80MHzMode = (BOOL) Get80MHzMode(objDppApi); SetFPGAClockDefault (objDppApi, Dpp80MHzMode, DppDevice); } GetConfigFromDpp(objDppApi); // configure px4 from stored configuration bApiHasCfg = TRUE; } if (! StatusLst.StatMcaEnabled) { // check if mca is enabled PauseDppData(objDppApi, false); // enable data acquisition } //GetStatusString(objDppApi, 1, szStatus, 2000); // get device status display string //show only most important 4 status values cstrStatus = ConfigDoubleValCStr(_T("Fast Count = "),StatusLst.FastCount); cstrStatus += ConfigDoubleValCStr(_T("Slow Count = "),StatusLst.SlowCount); cstrStatus += ConfigDoubleValCStr(_T("Accumulation Time = "),StatusLst.AccumulationTime); if (StatusLst.StatMcaEnabled) { cstrStatus += _T("StatMcaEnabled = True\r\n"); } else { cstrStatus += _T("StatMcaEnabled = False\r\n"); } GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(cstrStatus); NumChan = GetDppData(objDppApi, DataBuffer); // aquire data PlotData(DataBuffer, NumChan); // plot data } } else { GetDlgItem(IDC_STATUS_STATIC)->SetWindowText(_T("No USB devices detected")); OnStopAcquisition(); } } CDialog::OnTimer(nIDEvent); } //------------------------------------------------------------------- // PromptFileName // Creates a "file open" dialog with Amptek configuration file filters // BOOL bOpen = TRUE; // open dialog // BOOL bOpen = FALSE; // SaveAs dialog //------------------------------------------------------------------- BOOL CTest_CE_DPPDlg::PromptCfgFileName(CString *m_csCurrentFile, BOOL bOpen = true) { CString csDfltName; CString csFilter; // file extension filter CString csDfltExt; // default extension CString csCfgDisplayStr; // holds copy of last file read for display csFilter = "DPP Setup Files (*.cfg)|*.cfg|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"; csDfltName = "\\My Documents\\DPPCFG.cfg"; csDfltExt = "cfg"; CFileDialog dlg(bOpen, csDfltExt, csDfltName, OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY, csFilter); INT_PTR iResult = dlg.DoModal(); if(iResult == IDOK) { *m_csCurrentFile = dlg.GetPathName(); } else { *m_csCurrentFile = ""; } return (iResult == IDOK); }