// vcDP5Dlg.cpp : implementation file // #include "stdafx.h" #include "DppWinUSB.h" #include "vcDP5.h" #include "vcDP5Dlg.h" #include ".\vcdp5dlg.h" #include "SelectDP5.h" #include ".\msectimer.h" #include ".\waitdlg\CmdWaitDlg.h" #include "UserMsgs.h" #include "FileBrowse.h" #include "afxadv.h" // for cfg file clipboard copy #include "TuneSlowThreshold.h" #include "MsgBox.h" #include "AsciiCmdUtilities.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CvcDP5Dlg dialog CvcDP5Dlg::CvcDP5Dlg(CWnd* pParent /*=NULL*/) : CDialog(CvcDP5Dlg::IDD, pParent) { int idxBuffer; m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_PicturePlot.SetCursorPosition(0); // assign the timer values m_nTmrRS232EventId = 1; m_nTmrSpectrumEventId = 2; m_nTmrTimeoutEventId = 3; m_nTmrSpectrumId = 0; m_nTmrRS232Elapse = 100; m_nTmrSpectrumElapse = 1000; m_nTmrTimeoutElapse = 10; HavePlot = FALSE; HaveTrace = FALSE; for(idxBuffer = 0; idxBuffer < 8192; idxBuffer++) { PlotBuffer[idxBuffer] = 0; //holds y position data for cursor updates } for(idxBuffer = 0; idxBuffer < 2048; idxBuffer++) { ScopeBuffer[idxBuffer] = 0; } XPlotMAX = 0; YPlotMAX = 0; m_PicturePlot.OptScaleType = false; m_PicturePlot.OptPlotType = false; //MakeDp5CmdList(&Dp5CmdList); Dp5CmdList = MakeDp5CmdList(); // ascii text command list for adding comments HwCfgDP5 = ""; DP5Proto.SPECTRUM.CHANNELS = 1024; CurrentChannel = 0; } CvcDP5Dlg::~CvcDP5Dlg() { } void CvcDP5Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_PICTURE_PLOT, m_PicturePlot); DDX_Control(pDX, IDC_PICTURE_SCOPE, m_PictureScope); DDX_Control(pDX, IDC_STATIC_SELECT_COMMUNICATIONS, lblSelectCommunications); DDX_Control(pDX, IDC_STATIC_STATUS, lblStatus); DDX_Control(pDX, IDC_STATIC_MISC_STATUS, lblMiscStatus); } BEGIN_MESSAGE_MAP(CvcDP5Dlg, CDialog) ON_MESSAGE(WM_USER_SEND_CONFIG_TO_HW, DppSendConfigToHw) ON_MESSAGE(WM_USER_READ_DPP_CONFIG, CallReadDppConfig) ON_MESSAGE(WM_USER_READ_SCA_CONFIG, CallReadScaConfig) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_DEVICECHANGE() ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_FIND_DEVICE, OnBnClickedButtonFindDevice) ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON_ARM_TRIGGER, OnBnClickedButtonArmTrigger) ON_BN_CLICKED(IDC_BUTTON_SAVE_FILE, OnBnClickedButtonSaveFile) ON_BN_CLICKED(IDC_BUTTON_CLEAR_DATA_AND_GRAPH, OnBnClickedButtonClearDataAndGraph) ON_BN_CLICKED(IDC_BUTTON_SINGLE_UPDATE, OnBnClickedButtonSingleUpdate) ON_BN_CLICKED(IDC_BUTTON_CLEAR_MISC_DATA, OnBnClickedButtonClearMiscData) ON_BN_CLICKED(IDC_BUTTON_READ_MISC_DATA, OnBnClickedButtonReadMiscData) ON_BN_CLICKED(IDC_BUTTON_WRITE_MISC_DATA, OnBnClickedButtonWriteMiscData) ON_BN_CLICKED(IDC_BUTTON_DIAG, OnBnClickedButtonDiag) ON_BN_CLICKED(IDC_BUTTON_SELECT_COMM, OnBnClickedButtonSelectComm) ON_BN_CLICKED(IDC_BUTTON_START_ACQUISITION, OnBnClickedButtonStartAcquisition) ON_BN_CLICKED(IDC_BUTTON_STOP_ACQUISITION, OnBnClickedButtonStopAcquisition) ON_BN_CLICKED(IDC_BUTTON_SHOW_CONFIG, OnBnClickedButtonShowConfig) ON_BN_CLICKED(IDC_RADIO_PLOT_SCALE_LINEAR, OnBnClickedRadioPlotScaleLinear) ON_BN_CLICKED(IDC_RADIO_PLOT_SCALE_LOG, OnBnClickedRadioPlotScaleLog) ON_BN_CLICKED(IDC_RADIO_PLOT_TYPE_SOLID, OnBnClickedRadioPlotTypeSolid) ON_BN_CLICKED(IDC_RADIO_PLOT_TYPE_LINE, OnBnClickedRadioPlotTypeLine) ON_STN_CLICKED(IDC_PICTURE_PLOT, OnStnClickedPlotpicturecontrol) ON_WM_LBUTTONDOWN() ON_BN_CLICKED(IDOK, OnBnClickedOk) ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify) ON_BN_CLICKED(IDC_BUTTON_AUTOTUNE, OnBnClickedButtonAutotune) ON_BN_CLICKED(IDC_CHECK_REPEAT_SPECTRUM, OnBnClickedCheckRepeatSpectrum) END_MESSAGE_MAP() // CvcDP5Dlg message handlers BOOL CvcDP5Dlg::OnInitDialog() { CDialog::OnInitDialog(); EnableToolTips(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString cstrAboutMenu; cstrAboutMenu.LoadString(IDS_ABOUTBOX); if (!cstrAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, cstrAboutMenu); } } lblSelectCommunications .SetFontName("Arial") .SetFontSize(14) .SetTextColor(colorBlack) .SetBkColor(colorAmptekBlue) .SetFontBold(TRUE); lblMiscStatus .SetTextColor(colorBlue) .SetBkColor(colorAmptekBlue); // 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 hWnd_Main = this->GetSafeHwnd(); // TODO: Add extra initialization here WinusbNotify.SetNotificationWindow(this->m_hWnd); DppWinUSB.devInfo.deviceConnected = FALSE; // no device selected upon startup DppWinUSB.isDppFound = FALSE; m_PicturePlot.OptScaleType = BOOL_TO_bool(Profile.isScaleLog); m_PicturePlot.OptPlotType = BOOL_TO_bool(Profile.isPlotLine); if (m_PicturePlot.OptScaleType) { CheckRadioButton(IDC_RADIO_PLOT_SCALE_LINEAR, IDC_RADIO_PLOT_SCALE_LOG, IDC_RADIO_PLOT_SCALE_LOG); } else { CheckRadioButton(IDC_RADIO_PLOT_SCALE_LINEAR, IDC_RADIO_PLOT_SCALE_LOG, IDC_RADIO_PLOT_SCALE_LINEAR); } if (m_PicturePlot.OptPlotType) { CheckRadioButton(IDC_RADIO_PLOT_TYPE_SOLID, IDC_RADIO_PLOT_TYPE_LINE, IDC_RADIO_PLOT_TYPE_LINE); } else { CheckRadioButton(IDC_RADIO_PLOT_TYPE_SOLID, IDC_RADIO_PLOT_TYPE_LINE, IDC_RADIO_PLOT_TYPE_SOLID); } EnableDPPFunctions(FALSE); GetDlgItem(IDC_EDIT_REPEAT_LOOPS)->SetWindowText("10"); GetDlgItem(IDC_EDIT_PRESET_CMD)->SetWindowText("PRET=20;"); //GetDlgItem(IDC_EDIT_PRESET_CMD)->SetWindowText("PRER=60;"); return TRUE; // return TRUE unless you set the focus to a control } bool CvcDP5Dlg::BOOL_TO_bool(BOOL bValue) { if (bValue) { return true; } else { return false; } } void CvcDP5Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 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 CvcDP5Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 { UpdateScope(); CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CvcDP5Dlg::OnQueryDragIcon() { return static_cast(m_hIcon); } BOOL CvcDP5Dlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwData) { //CDialog::OnDeviceChange(nEventType, dwData); string strStatus; string strDevice; switch(nEventType) { case DBT_DEVICEARRIVAL: //return TRUE; lblStatus.SetText(strStatus.c_str()); if (WinusbNotify.GetDevNotifyInfo(dwData, DppWinUSB.devInfo.devicePath)) { strStatus = " "; lblStatus.SetText(strStatus.c_str()); strStatus = ""; lblStatus.SetText(strStatus.c_str()); strStatus = "Device Connected. Reconnecting to device."; lblStatus.SetText(strStatus.c_str()); OnBnClickedButtonFindDevice(); } break; case DBT_DEVICEREMOVECOMPLETE: if (WinusbNotify.GetDevNotifyInfo(dwData, DppWinUSB.devInfo.devicePath)) { EnableDPPFunctions(FALSE); DppWinUSB.devInfo.deviceConnected = FALSE; strStatus = "Device Removed"; lblStatus.SetText(strStatus.c_str()); } break; default: break; //AfxMessageBox("Unknown"); } // TODO: Add your message handler code here return true; } void CvcDP5Dlg::OnResetCommunications() { DppWinUSB.devInfo.deviceConnected = FALSE; DppWinUSB.CloseWinUsbDevice(); WinusbNotify.RemoveDeviceNotification(); } void CvcDP5Dlg::OnDestroy() { isDppConnected = FALSE; CDialog::OnDestroy(); CMSecTimer tmr; Profile.SaveProfile(); if (m_nTmrSpectrumId > 0) { KillTimer(m_nTmrSpectrumId); m_nTmrSpectrumId = 0; tmr.msTimer(1000); // put refresh rate here } OnResetCommunications(); } ULONG CvcDP5Dlg::DataTest() { BOOL bResult; USHORT bufSizeOut = 8; BYTE szBufferOut[8] = { 0xF5, 0xFA, 0x02, 0x03, 0x00, 0x00, 0xFE, 0x0C }; ULONG bytesWritten; USHORT bufSizeIn = 32767; BYTE szBufferIn[32767]; ULONG bytesRead; string bufOut; USHORT idxStatus; bytesRead = 0; bResult = WinUsb_WritePipe(DppWinUSB.devInfo.winUSBHandle, DppWinUSB.devInfo.bulkOutPipe, szBufferOut, bufSizeOut, &bytesWritten, NULL); Sleep(10); if (bResult) { bResult = WinUsb_ReadPipe(DppWinUSB.devInfo.winUSBHandle, DppWinUSB.devInfo.bulkInPipe, szBufferIn, bufSizeIn, &bytesRead, NULL); if (bResult) { if (bytesRead == 840) { for(idxStatus = 0; idxStatus<64; idxStatus++) { DP5Stat.m_DP5_Status.RAW[idxStatus] = szBufferIn[774 + idxStatus]; DP5Stat.Process_Status(&DP5Stat.m_DP5_Status); } bufOut = DppWinUSB.DisplayBufferArray(szBufferIn, bytesRead); DppWinUSB.SaveStringDataToFile(bufOut); } } } return bytesRead; } void CvcDP5Dlg::OnBnClickedButtonFindDevice() { string strUSBStatus; DPP_USB_STATUS USBStatus; //0=do nothing, 1=new connect, 2=cannot connect USBStatus = DppWinUSB.FindUSBDevice(DppWinUSB.CurrentDevice - 1); if (USBStatus != dusbStatNoAction) { strUSBStatus = DppWinUSB.USBStatusString(USBStatus); lblStatus.SetText(strUSBStatus.c_str()); if (USBStatus == dusbStatNewConnect) { EnableDPPFunctions(TRUE); } } } void CvcDP5Dlg::RemCallParsePacket(BYTE PacketIn[]) { ParsePkt.DppState.ReqProcess = ParsePkt.ParsePacket(PacketIn, &DP5Proto.PIN); ParsePacketEx(DP5Proto.PIN, ParsePkt.DppState); } void CvcDP5Dlg::ParsePacketEx(Packet_In PIN, DppStateType DppState) { switch (DppState.ReqProcess) { case preqProcessStatus: ProcessStatusEx(PIN, DppState); break; case preqProcessSpectrum: ProcessSpectrumEx(PIN, DppState); break; case preqProcessScopeData: ProcessScopeDataEx(PIN, DppState); break; case preqProcessTextData: ProcessTextDataEx(PIN, DppState); break; //==================================================================== // case preqProcessScopeDataOverFlow: // ProcessScopeDataEx(PIN, DppState); // //ProcessScopeDataOverFlowEx(PIN, DppState); // break; // case preqProcessInetSettings: // ProcessInetSettingsEx(PIN, DppState); // break; case preqProcessDiagData: ProcessDiagDataEx(PIN, DppState); break; // case preqProcessHwDesc: // rocessHwDescEx(PIN, DppState); // break; case preqProcessCfgRead: ProcessCfgReadEx(PIN, DppState); break; // case preqProcessNetFindRead: // //ProcessNetFindReadEx(PIN, DppState); //break; // case preqProcessSCAData: // ProcessSCADataEx(PIN, DppState); // break; //==================================================================== case preqProcessAck: ProcessAck(PIN.PID2); break; case preqProcessError: DisplayError(PIN, DppState); break; default: //do nothing break; } } void CvcDP5Dlg::DisplayError(Packet_In PIN, DppStateType DppState) { string strError; stringex strfn; ShowStatus(ParsePkt.PID2_TextToString("Received Packet", PIN.STATUS)); // bad PID, assigned by ParsePacket if (PIN.STATUS == PID2_ACK_PID_ERROR) { strError = strfn.Format("Received packet: PID1=0x.2X PID1=0x.2X LEN=%d",PIN.PID1,PIN.PID2,PIN.LEN); ShowStatus(strError); } } void CvcDP5Dlg::ProcessAck(BYTE PID2) { ShowStatus(ParsePkt.PID2_TextToString("ACK", PID2)); } void CvcDP5Dlg::ProcessStatusEx(Packet_In PIN, DppStateType DppState) { long idxStatus; for(idxStatus=0;idxStatus<64;idxStatus++) { DP5Stat.m_DP5_Status.RAW[idxStatus] = PIN.DATA[idxStatus]; } DP5Stat.Process_Status(&DP5Stat.m_DP5_Status); RequestScopeData(DP5Stat.m_DP5_Status.SCOPE_DR); ShowStatus("Received Status"); } void CvcDP5Dlg::ProcessDiagDataEx(Packet_In PIN, DppStateType DppState) { string strDiagData; DP5Stat.Process_Diagnostics(PIN, &DP5Stat.DiagData, Profile.device_type); strDiagData = DP5Stat.DiagnosticsToString(DP5Stat.DiagData, Profile.device_type); GetDlgItem(IDC_EDIT_DIAG)->SetWindowText(strDiagData.c_str()); } void CvcDP5Dlg::ProcessSpectrumEx(Packet_In PIN, DppStateType DppState) { long idxSpectrum; long idxStatus; string strStatus; DP5Proto.SPECTRUM.CHANNELS = (SHORT)(256 * pow(2.0,(((PIN.PID2 - 1) & 14) / 2))); for(idxSpectrum=0;idxSpectrumSetWindowText(strStatus.c_str()); string strMiscInfo; strMiscInfo = "Preset Mode "; strMiscInfo += strPresetCmd; strMiscInfo += "\r\n"; strMiscInfo += "Preset "; strMiscInfo += strPresetVal; strMiscInfo += "\r\n"; lblMiscStatus.SetText(strMiscInfo.c_str()); RequestScopeData(DP5Stat.m_DP5_Status.SCOPE_DR); } m_PicturePlot.DataAcq(DP5Proto.SPECTRUM.DATA, DP5Proto.SPECTRUM.CHANNELS); // plot data } void CvcDP5Dlg::ProcessScopeDataEx(Packet_In PIN, DppStateType DppState) { ScopeDisplay(PIN.DATA); if (IsDlgButtonChecked(IDC_CHECK_AUTO_REARM)) { SendCommand(XMTPT_ARM_DIGITAL_OSCILLOSCOPE); //Call btnArmTrigger_Click } } void CvcDP5Dlg::ProcessTextDataEx(Packet_In PIN, DppStateType DppState) { long idxTextData; string strTextData; string strCh; stringex strfn; // = strfn. strTextData = ""; for(idxTextData=0;idxTextData<512;idxTextData++) { strCh = strfn.Format("%c",PIN.DATA[idxTextData]); strTextData += strCh; } GetDlgItem(IDC_EDIT_MISC_DATA)->SetWindowText(strTextData.c_str()); } void CvcDP5Dlg::RequestScopeData(BOOL ScopeDataReady) { if (ScopeDataReady) { SendCommand(XMTPT_SEND_SCOPE_DATA); } } void CvcDP5Dlg::SendCommand(TRANSMIT_PACKET_TYPE XmtCmd) { BOOL HaveBuffer; BOOL SentPkt; HaveBuffer = SndCmd.DP5_CMD(DP5Proto.BufferOUT, XmtCmd); if (HaveBuffer) { SentPkt = DppWinUSB.SendPacketUSB(DP5Proto.BufferOUT, DppWinUSB.devInfo, DP5Proto.PacketIn); if (SentPkt) { RemCallParsePacket(DP5Proto.PacketIn); } else { //Timer2.Enabled = False } } } //DP5_CMD_Config is for: (requires pc5 and device info) // XMTPT_SEND_CONFIG_PACKET_TO_HW // XMTPT_SEND_CONFIG_PACKET_EX // XMTPT_FULL_READ_CONFIG_PACKET // XMTPT_READ_CONFIG_PACKET // XMTPT_READ_CONFIG_PACKET_EX void CvcDP5Dlg::SendCommandConfig(TRANSMIT_PACKET_TYPE XmtCmd) { BOOL HaveBuffer; BOOL SentPkt; CONFIG_OPTIONS CfgOptions; CfgOptions.DppType = DP5Stat.m_DP5_Status.DEVICE_ID; CfgOptions.HwCfgDP5Out = HwCfgDP5Out; CfgOptions.PC5_PRESENT = DP5Stat.m_DP5_Status.PC5_PRESENT; CfgOptions.SendCoarseFineGain = FALSE; CfgOptions.isDP5_RevDxGains = DP5Stat.m_DP5_Status.isDP5_RevDxGains; CfgOptions.DPP_ECO = DP5Stat.m_DP5_Status.DPP_ECO; HaveBuffer = SndCmd.DP5_CMD_Config(DP5Proto.BufferOUT, XmtCmd, CfgOptions); if (HaveBuffer) { SentPkt = DppWinUSB.SendPacketUSB(DP5Proto.BufferOUT, DppWinUSB.devInfo, DP5Proto.PacketIn); if (SentPkt) { RemCallParsePacket(DP5Proto.PacketIn); } else { //Timer2.Enabled = False } } } string CvcDP5Dlg::CreateSpectrumConfig(string strRawCfgIn) { string strDisplayCfgOut; string strCmdD; strDisplayCfgOut = strRawCfgIn; if (Dp5CmdList.size() > 0) { for (unsigned int idxCmd=0;idxCmd 0) { strDisplayCfgOut = AppendCmdDesc(strCmdD,strDisplayCfgOut); } } } return strDisplayCfgOut; } void CvcDP5Dlg::SendCommandData(TRANSMIT_PACKET_TYPE XmtCmd, BYTE DataOut[]) { BOOL HaveBuffer; BOOL SentPkt; HaveBuffer = SndCmd.DP5_CMD_Data(DP5Proto.BufferOUT, XmtCmd, DataOut); if (HaveBuffer) { SentPkt = DppWinUSB.SendPacketUSB(DP5Proto.BufferOUT, DppWinUSB.devInfo, DP5Proto.PacketIn); if (SentPkt) { RemCallParsePacket(DP5Proto.PacketIn); } else { //Timer2.Enabled = False } } } void CvcDP5Dlg::SetCheckButtonState(int iCheckBox, bool bChecked) { CButton* pCheckBox=(CButton*)GetDlgItem(iCheckBox); if (bChecked) { pCheckBox->SetCheck(BST_CHECKED); } else { pCheckBox->SetCheck(BST_UNCHECKED); } } void CvcDP5Dlg::OnTimer(UINT nIDEvent) { bool bPresetReached = false; if (nIDEvent == m_nTmrSpectrumId) { // 1000ms AutoSpectrum if (IsDlgButtonChecked(IDC_CHECK_DELTA)) { SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); } else { SendCommand(XMTPT_SEND_SPECTRUM_STATUS); // get the spectrum and status if (IsDlgButtonChecked(IDC_CHECK_REPEAT_SPECTRUM)) { if (DP5Stat.m_DP5_Status.MCA_EN && ((DP5Stat.m_DP5_Status.PRECNT_REACHED) // preset counts || (DP5Stat.m_DP5_Status.PresetRtDone) // preset real time || (DP5Stat.m_DP5_Status.PresetLtDone))) { // preset live time bPresetReached = true; } else if (!DP5Stat.m_DP5_Status.MCA_EN) { // preset accum time bPresetReached = true; } if (bPresetReached) { idxCurrentSpectrum++; if (idxCurrentSpectrum <= idxTotalSpectra) { // save spectrum SaveTestSpectrumFile(idxCurrentSpectrum); } if (idxCurrentSpectrum >= idxTotalSpectra) { // we're done if (m_nTmrSpectrumId > 0) { KillTimer(m_nTmrSpectrumId); m_nTmrSpectrumId = 0; } SetCheckButtonState(IDC_CHECK_REPEAT_SPECTRUM,false); OnBnClickedCheckRepeatSpectrum(); ShowRepeatStatus(false); GetDlgItem(IDC_STATIC_STATUS)->SetWindowText("Repeat Spectrum Done"); } else { // get next spectrum SendCommand(XMTPT_DISABLE_MCA_MCS); SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); m_PicturePlot.ClearTrace(); string strStartTime = CreateDTS("%m/%d/%Y %H:%M:%S"); GetDlgItem(IDC_EDIT_START_TIME)->SetWindowText(strStartTime.c_str()); SendCommand(XMTPT_ENABLE_MCA_MCS); ShowRepeatStatus(true); } } } } } else if (nIDEvent == m_nTmrTimeoutId) { // 10ms Comm TimeOut TimeoutFlag = TRUE; } CDialog::OnTimer(nIDEvent); } void CvcDP5Dlg::OnBnClickedButtonArmTrigger() { SendCommand(XMTPT_ARM_DIGITAL_OSCILLOSCOPE); } void CvcDP5Dlg::OnBnClickedButtonClearDataAndGraph() { SetCheckButtonState(IDC_CHECK_REPEAT_SPECTRUM,false); SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); GetDlgItem(IDC_STATIC_REPEAT_STATUS)->SetWindowText(""); m_PicturePlot.ClearTrace(); } void CvcDP5Dlg::OnBnClickedButtonSingleUpdate() { SetCheckButtonState(IDC_CHECK_REPEAT_SPECTRUM,false); if (m_nTmrSpectrumId > 0) { KillTimer(m_nTmrSpectrumId); m_nTmrSpectrumId = 0; } if (IsDlgButtonChecked(IDC_CHECK_DELTA)) { SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); } else { SendCommand(XMTPT_SEND_SPECTRUM_STATUS); } } void CvcDP5Dlg::OnBnClickedButtonClearMiscData() { GetDlgItem(IDC_EDIT_MISC_DATA)->SetWindowText(""); } void CvcDP5Dlg::OnBnClickedButtonReadMiscData() { SendCommand(XMTPT_SEND_512_BYTE_MISC_DATA); } void CvcDP5Dlg::OnBnClickedButtonWriteMiscData() { string strMiscData; BYTE byteMiscData[512]; int idxCh; int DataLen; strMiscData.reserve(512+1); GetDlgItem(IDC_EDIT_MISC_DATA)->GetWindowText((char*)strMiscData.c_str(), 512+1); DataLen = (int)strMiscData.length(); for(idxCh=0;idxCh<512;idxCh++) { if (idxCh < DataLen) { byteMiscData[idxCh] = (BYTE)strMiscData.at(idxCh); } else { byteMiscData[idxCh] = 0; } } SendCommandData(XMTPT_WRITE_512_BYTE_MISC_DATA, byteMiscData); } void CvcDP5Dlg::ShowStatus(string strStatus) { GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strStatus.c_str()); } //------------------------------------------------------------------- // UpdateScope // Draws the scope display with the current scope buffer //------------------------------------------------------------------- void CvcDP5Dlg::UpdateScope() { CDC *dc=m_PictureScope.GetDC(); // device context for plot CRect rect; CPen pen,*oldpen; m_PictureScope.GetClientRect(&rect); // get plot client area // Draw background rectangle if (HaveTrace) { pen.CreatePen(PS_SOLID,1,RGB(0xFF,0x00,0x00)); // drawing pen color } else { pen.CreatePen(PS_SOLID,1,RGB(0xFF,0xFF,0xFF)); // drawing pen color } oldpen=dc->SelectObject(&pen); // save old pen to restore CBrush WorkSpaceBrush( RGB(0xFF,0xFF,0xFF) ); // fill brush color CBrush *oldbrush = dc->SelectObject(&WorkSpaceBrush); // save old brush to restore dc->Rectangle(&rect); dc->Draw3dRect(&rect, (COLORREF)GetSysColor(COLOR_3DSHADOW), (COLORREF)GetSysColor(COLOR_3DHILIGHT)); // === needs to be updated, dc->SetMapMode(MM_ANISOTROPIC); // x!=y dc->SetViewportOrg(0,rect.Height()); // move 0,0 to bottom left dc->SetWindowExt(2048, -256); // 2048 scope channels, 256 levels (invert y scale) dc->SetViewportExt(rect.Width(), rect.Height()); // viewport is pic control size //double y1, y2; for(int X=0; X<2047; X++) { dc->MoveTo(X, ScopeBuffer[X]); dc->LineTo(X+1, ScopeBuffer[X+1]); } dc->SelectObject(oldpen); pen.DeleteObject(); dc->SelectObject(oldbrush); WorkSpaceBrush.DeleteObject(); m_PictureScope.ReleaseDC(dc); } //------------------------------------------------------------------- // ScopeDisplay // Calculates and saves the plot buffer data then calls UpdatePlot //------------------------------------------------------------------- void CvcDP5Dlg::ScopeDisplay(BYTE ScopeData[2048]) { int i; for (i = 0; i < 2048;i++ ) { //get the largest value to be displayed ScopeBuffer[i] = ScopeData[i]; } HaveTrace = TRUE; UpdateScope(); } void CvcDP5Dlg::EnableDPPFunctions(BOOL isEnabled) { // Config GetDlgItem(IDC_BUTTON_SHOW_CONFIG)->EnableWindow(isEnabled); //CONFIG // MCA functions GetDlgItem(IDC_BUTTON_SINGLE_UPDATE)->EnableWindow(isEnabled); //Single Update GetDlgItem(IDC_BUTTON_START_ACQUISITION)->EnableWindow(isEnabled); //Start Acquire GetDlgItem(IDC_BUTTON_STOP_ACQUISITION)->EnableWindow(isEnabled); //Stop Acquire GetDlgItem(IDC_BUTTON_CLEAR_DATA_AND_GRAPH)->EnableWindow(isEnabled); //Clear Data and Graph GetDlgItem(IDC_BUTTON_SAVE_FILE)->EnableWindow(isEnabled); //Save File // Scope GetDlgItem(IDC_BUTTON_ARM_TRIGGER)->EnableWindow(isEnabled); //Arm Trigger //Text Data Buttons GetDlgItem(IDC_BUTTON_READ_MISC_DATA)->EnableWindow(isEnabled); //Read GetDlgItem(IDC_BUTTON_WRITE_MISC_DATA)->EnableWindow(isEnabled); //Write GetDlgItem(IDC_BUTTON_CLEAR_MISC_DATA)->EnableWindow(isEnabled); //Clear // diagnostics GetDlgItem(IDC_BUTTON_DIAG)->EnableWindow(isEnabled); //CONFIG } void CvcDP5Dlg::OnBnClickedButtonDiag() { SendCommand(XMTPT_SEND_DIAGNOSTIC_DATA); } void CvcDP5Dlg::OnBnClickedButtonSelectComm() { string strSelected; CSelectDP5 SelectDP5; CMSecTimer tmr; cWaitDialog dlg; // display dialog box dlg.m_Text = "Adjusting Communications...please wait"; dlg.Show(); strSelected = "Select Communications"; if (m_nTmrSpectrumId > 0) { KillTimer(m_nTmrSpectrumId); m_nTmrSpectrumId = 0; tmr.msTimer(1000); // put refresh rate here } OnResetCommunications(); tmr.msTimer(200); dlg.Close(); // close wait dlg INT_PTR nResponse = SelectDP5.DoModal(); if (nResponse == IDOK) { EnableDPPFunctions(FALSE); if (DppWinUSB.devInfo.deviceConnected) { strSelected = "USB - WinUSB"; EnableDPPFunctions(TRUE); } isConnectedTest(); lblSelectCommunications.SetText(strSelected.c_str()); } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } } string CvcDP5Dlg::GetDeviceNameFromVal(int DeviceTypeVal) { string strDeviceType; switch(DeviceTypeVal) { case dppDP5: strDeviceType = "DP5"; break; case dppPX5: strDeviceType = "PX5"; break; case dppDP5G: strDeviceType = "DP5G"; break; case dppMCA8000D: strDeviceType = "MCA8000D"; break; case dppTB5: strDeviceType = "TB5"; break; default: //if unknown set to DP5 strDeviceType = "DP5"; break; } return strDeviceType; } // sets/returns if DPP is connected based on USB Interface and isDppFound[] BOOL CvcDP5Dlg::isConnectedTest() { BOOL isDppFound; CMSecTimer tmr; isDppFound = DppWinUSB.isDppFound; isDppConnected = isDppFound; if (isDppConnected ) { SendCommand(XMTPT_SEND_STATUS); // request status tmr.msTimer(500); Profile.device_type = DP5Stat.m_DP5_Status.DEVICE_ID; DeviceType = DP5Stat.m_DP5_Status.DEVICE_ID; Profile.strDevice = GetDeviceNameFromVal(Profile.device_type); return isDppFound; } else { isDppConnected = FALSE; return FALSE; } } void CvcDP5Dlg::ShowRepeatStatus(bool bShowStatus = false) { string strStatus(""); stringex strfn; // = strfn. if (bShowStatus) { // display count strStatus = strfn.Format("%d of %d", idxCurrentSpectrum+1, idxTotalSpectra); } GetDlgItem(IDC_STATIC_REPEAT_STATUS)->SetWindowText(strStatus.c_str()); } void CvcDP5Dlg::OnBnClickedButtonStartAcquisition() { string strCmd(""); string strLoops(""); bSpectraTestRunning = false; idxCurrentSpectrum = 0; idxTotalSpectra = 0; if (IsDlgButtonChecked(IDC_CHECK_REPEAT_SPECTRUM)) { strLoops.reserve(10); GetDlgItem(IDC_EDIT_REPEAT_LOOPS)->GetWindowText((char*)strLoops.c_str(),10); idxTotalSpectra = atoi(strLoops.c_str()); string strStartTime = CreateDTS("%m/%d/%Y %H:%M:%S"); GetDlgItem(IDC_EDIT_START_TIME)->SetWindowText(strStartTime.c_str()); strLoops.reserve(20); GetDlgItem(IDC_EDIT_PRESET_CMD)->GetWindowText((char*)strCmd.c_str(),20); HwCfgDP5Out = strCmd.c_str(); HwCfgReady = TRUE; SendCommandConfig(XMTPT_SEND_CONFIG_PACKET_EX); // send the packet HwCfgExReady = FALSE; SendCommand(XMTPT_DISABLE_MCA_MCS); SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); m_PicturePlot.ClearTrace(); bSpectraTestRunning = true; CMSecTimer tmr; ShowRepeatStatus(true); tmr.msTimer(200); DP5Stat.m_DP5_Status.PRECNT_REACHED = FALSE; // preset counts DP5Stat.m_DP5_Status.PresetRtDone = FALSE; // preset real time DP5Stat.m_DP5_Status.PresetLtDone = FALSE; // preset live time } SendCommand(XMTPT_ENABLE_MCA_MCS); m_nTmrSpectrumId = SetTimer(m_nTmrSpectrumEventId, m_nTmrSpectrumElapse, NULL); } void CvcDP5Dlg::OnBnClickedButtonStopAcquisition() { SetCheckButtonState(IDC_CHECK_REPEAT_SPECTRUM,false); SendCommand(XMTPT_DISABLE_MCA_MCS); } LRESULT CvcDP5Dlg::DppSendConfigToHw(WPARAM wParam, LPARAM lParam) { if (isDppConnected ) { if (HwCfgReady) { SendCommandConfig(XMTPT_SEND_CONFIG_PACKET_TO_HW); // send the packet HwCfgReady = FALSE; } else if (HwCfgExReady) { SendCommandConfig(XMTPT_SEND_CONFIG_PACKET_EX); // send the packet HwCfgExReady = FALSE; } } CMSecTimer tmr; if (isDppConnected ) { tmr.msTimer(20); SendCommandConfig(XMTPT_READ_CONFIG_PACKET); // get info for display tmr.msTimer(20); } return (Default()); } LRESULT CvcDP5Dlg::CallReadDppConfig(WPARAM wParam, LPARAM lParam) { if (isDppConnected ) { CfgReadBack = TRUE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); } return (Default()); } LRESULT CvcDP5Dlg::CallReadScaConfig(WPARAM wParam, LPARAM lParam) { if (isDppConnected ) { ScaReadBack = TRUE; SendCommand(XMTPT_SCA_READ_CONFIG_PACKET); } return (Default()); } void CvcDP5Dlg::ProcessCfgReadEx(Packet_In PIN, DppStateType DppState) { string strRawCfgIn; string strRawCfgOut; string strCh; string strCmdData; strRawCfgIn = ""; string strCmdD; string strCfg; BOOL isScaCfg = FALSE; string strDisplayCfgOut; stringex strfn; // = strfn. strRawCfgOut = ""; // ========================================================== // ===== Create Raw Configuration Buffer From Hardware ====== for (int idxCfg=0;idxCfg 0) { strDisplayCfgOut = ReplaceCmdDesc(strCmdD,strDisplayCfgOut); } } CopyDp5CfgToClip(strCfg,strDisplayCfgOut); CMsgBox MsgBox; MsgBox.m_strTitle = "DPP Configuration"; MsgBox.m_strMessage = strDisplayCfgOut; MsgBox.m_strDelimiter = ";"; MsgBox.DoModal(); return; } else if (CfgReadBack) { CfgReadBack = FALSE; HwCfgDP5 = strRawCfgIn; HwCfgReady = TRUE; } SaveCfg = FALSE; PrintCfg = FALSE; DisplayCfg = FALSE; CfgReadBack = FALSE; isScaCfg = (BOOL)(ScaReadBack || DisplaySca); ScaReadBack = FALSE; DisplaySca = FALSE; if (isScaCfg) { return; } strCmdData = GetCmdData("MCAS",strRawCfgIn); // mca mode strCmdData = GetCmdData("MCAC",strRawCfgIn); // channels if ((atoi(strCmdData.c_str()) > 0) && (atoi(strCmdData.c_str()) <= 8192)) { mcaCH = atoi(strCmdData.c_str()); } else { mcaCH = 1024; } strCmdData = GetCmdData("THSL",strRawCfgIn); // LLD thresh SlowThresholdPct = atof(strCmdData.c_str()); strCmdData = GetCmdData("THFA",strRawCfgIn); // fast thresh FastChThreshold = atoi(strCmdData.c_str()); strCmdData = GetCmdData("TPEA",strRawCfgIn); // peak time RiseUS = atof(strCmdData.c_str()); strCmdData = GetCmdData("GAIN",strRawCfgIn); // gain strGainDisplayValue = strCmdData + "x"; strPresetCmd = ""; strPresetVal = ""; strCmdData = GetCmdData("PREC",strRawCfgIn); //preset count PresetCount = atoi(strCmdData.c_str()); if (PresetCount > 0) { if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } if (strPresetVal.length() > 0) { strPresetVal += "/"; } strPresetCmd += "Cnt"; strPresetVal += strCmdData; } strCmdData = GetCmdData("PRET",strRawCfgIn); //preset actual time PresetAcq = atof(strCmdData.c_str()); if (PresetAcq > 0) { if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } if (strPresetVal.length() > 0) { strPresetVal += "/"; } strPresetCmd += "Acq"; strPresetVal += strCmdData; } strCmdData = GetCmdData("PRER",strRawCfgIn); // preset real time PresetRt = atof(strCmdData.c_str()); if (PresetRt > 0) { if (strPresetCmd.length() > 0) { strPresetCmd += "/"; } if (strPresetVal.length() > 0) { strPresetVal += "/"; } strPresetCmd += "Real"; strPresetVal += strCmdData; } if (strPresetCmd.length() == 0) { strPresetCmd += "None"; } if (strPresetVal.length() == 0) { //strPresetVal += ""; } strCmdData = GetCmdData("CLCK",strRawCfgIn); // fpga clock mode if (atoi(strCmdData.c_str()) == 80) { b80MHzMode = TRUE; } else { b80MHzMode = FALSE; } // DP5 oscilloscope support strCmdData = GetCmdData("INOF",strRawCfgIn); // osc. Input offset strInputOffset = strCmdData; strCmdData = GetCmdData("DACO",strRawCfgIn); // osc. DAC output strAnalogOut = strCmdData; strCmdData = GetCmdData("DACF",strRawCfgIn); // osc. DAC offset strOutputOffset = strCmdData; strCmdData = GetCmdData("AUO1",strRawCfgIn); // osc. AUX_OUT1 strTriggerSource = strCmdData; strCmdData = GetCmdData("SCOE",strRawCfgIn); // osc. Scope trigger edge strTriggerSlope = strCmdData; strCmdData = GetCmdData("SCOT",strRawCfgIn); // osc. Scope trigger position strTriggerPosition = strCmdData; strCmdData = GetCmdData("SCOG",strRawCfgIn); // osc. Scope gain strScopeGain = strCmdData; strCmdData = GetCmdData("MCAS",strRawCfgIn); // Acq Mode AcqMode = 0; strMcaMode = "MCA"; if (strCmdData == "NORM") { strMcaMode = "MCA"; } else if (strCmdData == "MCS") { strMcaMode = "MCS"; AcqMode = 1; } else if (strCmdData.length() > 0) { strMcaMode = strCmdData; } UpdateScopeCfg = TRUE; } string CvcDP5Dlg::GetCmdData(string strCmd, string strCfgData) { int iStart,iEnd,iCmd; string strCmdData; strCmdData = ""; if (strCfgData.length() < 7) { return strCmdData; } // no data if (strCmd.length() != 4) { return strCmdData; } // bad command iCmd = (int)strCfgData.find(strCmd+"=",0); if (iCmd == -1) { return strCmdData; } // cmd not found iStart = (int)strCfgData.find("=",iCmd); if (iStart == -1) { return strCmdData; } // data start not found iEnd = (int)strCfgData.find(";",iCmd); if (iEnd == -1) {return strCmdData; } // data end found if (iStart >= iEnd) { return strCmdData; } // data error strCmdData = strCfgData.substr(iStart+1,(iEnd - (iStart+1))); return strCmdData; } string CvcDP5Dlg::ReplaceCmdDesc(string strCmd, string strCfgData) { int iStart,iCmd; //iEnd, string strNew; string strDesc; strNew = ""; if (strCfgData.length() < 7) { return strCfgData; } // no data if (strCmd.length() != 4) { return strCfgData; } // bad command iCmd = (int)strCfgData.find(strCmd+"=",0); if (iCmd == -1) { return strCfgData; } // cmd not found strDesc = GetCmdDesc(strCmd); if (strDesc.length() == 0) { return strCfgData; } // cmd desc not found iStart = (int)strCfgData.find("=",iCmd); if (iStart != (iCmd + 4)) { return strCfgData; } // data start not found if (iCmd <= 0) { // usually left string has iCmd-1 iCmd = 1; // in this case left has 0 chars, set offset } strNew = strCfgData.substr(0,iCmd-1) + strDesc + strCfgData.substr(iStart); return strNew; } string CvcDP5Dlg::AppendCmdDesc(string strCmd, string strCfgData) { int iStart,iEnd,iCmd; string strNew; string strDesc; strNew = ""; if (strCfgData.length() < 7) { return strCfgData; } // no data if (strCmd.length() != 4) { return strCfgData; } // bad command iCmd = (int)strCfgData.find(strCmd+"=",0); if (iCmd == -1) { return strCfgData; } // cmd not found iEnd = (int)strCfgData.find(";",iCmd); if (iEnd == -1) {return strCfgData; } // data end found iStart = (int)strCfgData.find("=",iCmd); if (iStart != (iCmd + 4)) { return strCfgData; } // data start not found if (iStart >= iEnd) { return strCfgData; } // data error strDesc = GetCmdDesc(strCmd); if (strDesc.length() == 0) { return strCfgData; } // cmd desc not found strNew = strCfgData.substr(0,iEnd+1) + " " + strDesc + strCfgData.substr(iEnd+1); return strNew; } vector CvcDP5Dlg::MakeDp5CmdList() { vector cstrCfgArr; cstrCfgArr.clear(); cstrCfgArr.push_back("RESC"); cstrCfgArr.push_back("CLCK"); cstrCfgArr.push_back("TPEA"); cstrCfgArr.push_back("GAIF"); cstrCfgArr.push_back("GAIN"); cstrCfgArr.push_back("RESL"); cstrCfgArr.push_back("TFLA"); cstrCfgArr.push_back("TPFA"); cstrCfgArr.push_back("PURE"); cstrCfgArr.push_back("RTDE"); cstrCfgArr.push_back("MCAS"); cstrCfgArr.push_back("MCAC"); cstrCfgArr.push_back("SOFF"); cstrCfgArr.push_back("AINP"); cstrCfgArr.push_back("INOF"); cstrCfgArr.push_back("GAIA"); cstrCfgArr.push_back("CUSP"); cstrCfgArr.push_back("PDMD"); cstrCfgArr.push_back("THSL"); cstrCfgArr.push_back("TLLD"); cstrCfgArr.push_back("THFA"); cstrCfgArr.push_back("DACO"); cstrCfgArr.push_back("DACF"); cstrCfgArr.push_back("RTDS"); cstrCfgArr.push_back("RTDT"); cstrCfgArr.push_back("BLRM"); cstrCfgArr.push_back("BLRD"); cstrCfgArr.push_back("BLRU"); cstrCfgArr.push_back("GATE"); cstrCfgArr.push_back("AUO1"); cstrCfgArr.push_back("PRET"); cstrCfgArr.push_back("PRER"); cstrCfgArr.push_back("PREL"); cstrCfgArr.push_back("PREC"); cstrCfgArr.push_back("PRCL"); cstrCfgArr.push_back("PRCH"); cstrCfgArr.push_back("HVSE"); cstrCfgArr.push_back("TECS"); cstrCfgArr.push_back("PAPZ"); cstrCfgArr.push_back("PAPS"); cstrCfgArr.push_back("SCOE"); cstrCfgArr.push_back("SCOT"); cstrCfgArr.push_back("SCOG"); cstrCfgArr.push_back("MCSL"); cstrCfgArr.push_back("MCSH"); cstrCfgArr.push_back("MCST"); cstrCfgArr.push_back("AUO2"); cstrCfgArr.push_back("TPMO"); cstrCfgArr.push_back("GPED"); cstrCfgArr.push_back("GPIN"); cstrCfgArr.push_back("GPME"); cstrCfgArr.push_back("GPGA"); cstrCfgArr.push_back("GPMC"); cstrCfgArr.push_back("MCAE"); cstrCfgArr.push_back("VOLU"); cstrCfgArr.push_back("CON1"); cstrCfgArr.push_back("CON2"); cstrCfgArr.push_back("BOOT"); return cstrCfgArr; } string CvcDP5Dlg::GetCmdDesc(string strCmd) { string strCmdName = ""; if (strCmd == "RESC") { strCmdName = "Reset Configuration"; } else if (strCmd == "CLCK") { strCmdName = "20MHz/80MHz"; } else if (strCmd == "TPEA") { strCmdName = "peaking time"; } else if (strCmd == "GAIF") { strCmdName = "Fine gain"; } else if (strCmd == "GAIN") { strCmdName = "Total Gain (analog * fine)"; } else if (strCmd == "RESL") { strCmdName = "Detector Reset lockout"; } else if (strCmd == "TFLA") { strCmdName = "Flat top"; } else if (strCmd == "TPFA") { strCmdName = "Fast channel peaking time"; } else if (strCmd == "RTDE") { strCmdName = "RTD on/off"; } else if (strCmd == "MCAS") { strCmdName = "MCA Source"; } else if (strCmd == "RTDD") { strCmdName = "Custom RTD oneshot delay"; } else if (strCmd == "RTDW") { strCmdName = "Custom RTD oneshot width"; } else if (strCmd == "PURE") { strCmdName = "PUR interval on/off"; } else if (strCmd == "SOFF") { strCmdName = "Set spectrum offset"; } else if (strCmd == "INOF") { strCmdName = "Input offset"; } else if (strCmd == "ACKE") { strCmdName = "ACK / Don't ACK packets with errors"; } else if (strCmd == "AINP") { strCmdName = "Analog input pos/neg"; } else if (strCmd == "AUO1") { strCmdName = "AUX_OUT selection"; } else if (strCmd == "AUO2") { strCmdName = "AUX_OUT2 selection"; } else if (strCmd == "BLRD") { strCmdName = "BLR down correction"; } else if (strCmd == "BLRM") { strCmdName = "BLR mode"; } else if (strCmd == "BLRU") { strCmdName = "BLR up correction"; } else if (strCmd == "BOOT") { strCmdName = "Turn supplies on/off at power up"; } else if (strCmd == "CUSP") { strCmdName = "Non-trapezoidal shaping"; } else if (strCmd == "DACF") { strCmdName = "DAC offset"; } else if (strCmd == "DACO") { strCmdName = "DAC output"; } else if (strCmd == "GAIA") { strCmdName = "Analog gain index"; } else if (strCmd == "GATE") { strCmdName = "Gate control"; } else if (strCmd == "GPED") { strCmdName = "G.P. counter edge"; } else if (strCmd == "GPGA") { strCmdName = "G.P. counter uses GATE?"; } else if (strCmd == "GPIN") { strCmdName = "G.P. counter input"; } else if (strCmd == "GPMC") { strCmdName = "G.P. counter cleared with MCA counters?"; } else if (strCmd == "GPME") { strCmdName = "G.P. counter uses MCA_EN?"; } else if (strCmd == "HVSE") { strCmdName = "HV set"; } else if (strCmd == "MCAC") { strCmdName = "MCA/MCS channels"; } else if (strCmd == "MCAE") { strCmdName = "MCA/MCS enable"; } else if (strCmd == "MCSL") { strCmdName = "MCS low threshold"; } else if (strCmd == "MCSH") { strCmdName = "MCS high threshold"; } else if (strCmd == "MCST") { strCmdName = "MCS timebase"; } else if (strCmd == "PAPS") { strCmdName = "preamp 8.5/5 (N/A)"; } else if (strCmd == "PAPZ") { strCmdName = "Pole-Zero"; } else if (strCmd == "PDMD") { strCmdName = "Peak detect mode (min/max)"; } else if (strCmd == "PRCL") { strCmdName = "Preset counts low threshold"; } else if (strCmd == "PRCH") { strCmdName = "Preset counts high threshold"; } else if (strCmd == "PREC") { strCmdName = "Preset counts"; } else if (strCmd == "PRER") { strCmdName = "Preset Real Time"; } else if (strCmd == "PRET") { strCmdName = "Preset time"; } else if (strCmd == "RTDS") { strCmdName = "RTD sensitivity"; } else if (strCmd == "RTDT") { strCmdName = "RTD threshold"; } else if (strCmd == "SCAH") { strCmdName = "SCAx high threshold"; } else if (strCmd == "SCAI") { strCmdName = "SCA index"; } else if (strCmd == "SCAL") { strCmdName = "SCAx low theshold"; } else if (strCmd == "SCAO") { strCmdName = "SCAx output (SCA1-8 only)"; } else if (strCmd == "SCAW") { strCmdName = "SCA pulse width (not indexed - SCA1-8)"; } else if (strCmd == "SCOE") { strCmdName = "Scope trigger edge"; } else if (strCmd == "SCOG") { strCmdName = "Digital scope gain"; } else if (strCmd == "SCOT") { strCmdName = "Scope trigger position"; } else if (strCmd == "TECS") { strCmdName = "TEC set"; } else if (strCmd == "THFA") { strCmdName = "Fast threshold"; } else if (strCmd == "THSL") { strCmdName = "Slow threshold"; } else if (strCmd == "TLLD") { strCmdName = "LLD threshold"; } else if (strCmd == "TPMO") { strCmdName = "Test pulser on/off"; } else if (strCmd == "VOLU") { strCmdName = "Speaker On/Off"; } else if (strCmd == "CON1") { strCmdName = "Connector 1"; } else if (strCmd == "CON2") { strCmdName = "Connector 2"; } return strCmdName; } void CvcDP5Dlg::CopyDp5CfgToClip(string strCfg, string strDesc) { string strConfig; strConfig = "[DP5 Configuration File]\r\n" + strCfg + "\r\n" + "\r\n" + strDesc; AfxGetApp()->m_pMainWnd->OpenClipboard() ; EmptyClipboard(); CSharedFile sf(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT); sf.Write(strConfig.c_str(), (unsigned int)strConfig.length()); HGLOBAL hMem = sf.Detach(); if (!hMem) return; SetClipboardData(CF_TEXT, hMem); CloseClipboard(); } void CvcDP5Dlg::OnBnClickedButtonShowConfig() { if (isDppConnected ) { DisplayCfg = TRUE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); } } // ON_BN_CLICKED(IDC_BUTTON_READ_CONFIG, OnBnClickedButtonReadConfig) // GetDlgItem(IDC_BUTTON_READ_CONFIG)->EnableWindow(bEnable); // #define IDC_BUTTON_READ_CONFIG 1921 // PUSHBUTTON "Open Configuration File",IDC_BUTTON_READ_CONFIG,19,78,117,14 void CvcDP5Dlg::SendConfigFromFileToDpp() { CFileBrowse BR; CAsciiCmdUtilities AsciiCmdUtil; //ASCII command utility library CString cstrDfltExt("txt"); CString cstrFilename(""); string strFilename(""); std::string strCfg(""); BOOL isFileOk=FALSE; isFileOk = BR.DoModal(BR.OPEN,"Open Configuration",BR.CfgFileFilter,cstrDfltExt,_T(""),&cstrFilename); if (isFileOk) { strFilename = cstrFilename; strCfg = AsciiCmdUtil.GetDP5CfgStr(strFilename); } } void CvcDP5Dlg::ButtonSendStringCfgToHardware(CString strCfgIn) { CMSecTimer tmr; CString strCfgMFC(""); std::string strCfg(""); bool isPC5Present=false; //Needed to remove pc5 commands int DppType=0; //Needed to remove CAsciiCmdUtilities AsciiCmdUtil; //ASCII command utility library long lCfgLen=0; //ASCII Configuration Command String Length int idxSplitCfg=0; //Configuration split position, only if necessary bool bSplitCfg=false; //Configuration split flag std::string strSplitCfg(""); //Configuration split string second buffer bool isDP5_RevDxGains; unsigned char DPP_ECO; strCfgMFC = strCfgIn; DppType = DP5Stat.m_DP5_Status.DEVICE_ID; isPC5Present = DP5Stat.m_DP5_Status.PC5_PRESENT; isDP5_RevDxGains = DP5Stat.m_DP5_Status.isDP5_RevDxGains; DPP_ECO = DP5Stat.m_DP5_Status.DPP_ECO; HwCfgReady = FALSE; HwCfgExReady = FALSE; HwCfgDP5Out = ""; strCfg = strCfgMFC; // Configuration Oversize Fix 20141224 // The hardware cannot handle ASCII Configurations Larger than 512 Bytes // The original solution was to separately send the SCA Commands // Now the number of command excluding SCA command may exceed 512 Bytes // New methods of controlling the size of the cfg string are needed // 1. Run the RemoveCmdByDeviceType here (is also in CSendCommand::WM_USER_SEND_CONFIG_TO_HW) // --> RemoveCmdByDeviceType is done here to accurately measure size. // 2. Measure final ASCII cfg string size strCfg = AsciiCmdUtil.RemoveCmdByDeviceType(strCfg, isPC5Present, DppType, isDP5_RevDxGains, DPP_ECO); lCfgLen = (long)strCfg.length(); //Test configuration size // 3. If needed shorten cmds, ReMeasure final ASCII cfg string size if (lCfgLen > 512) { //configuration is too large, try to reduce strCfg = AsciiCmdUtil.ReplaceCmdText(strCfg, "US;", ";"); strCfg = AsciiCmdUtil.ReplaceCmdText(strCfg, "OFF;", "OF;"); strCfg = AsciiCmdUtil.ReplaceCmdText(strCfg, "RISING;", "RI;"); strCfg = AsciiCmdUtil.ReplaceCmdText(strCfg, "FALLING;", "FA;"); lCfgLen = (long)strCfg.length(); //Test configuration size // 4. If needed split cmd string, send cfg in two blocks if (lCfgLen > 512) { //configuration is still too large, split cfg bSplitCfg = true; idxSplitCfg = AsciiCmdUtil.GetCmdChunk(strCfg); strSplitCfg = strCfg.substr(idxSplitCfg); strCfg = strCfg.substr(0, idxSplitCfg); } } strCfgMFC = strCfg.c_str(); HwCfgDP5Out = strCfgMFC; if (HwCfgDP5Out.length() >0 ) { HwCfgReady = TRUE; // filter out messages by device, gain, and option types ::PostMessage(hWnd_Main,WM_USER_SEND_CONFIG_TO_HW,0L,0L); } if (bSplitCfg) { tmr.msTimer(500); HwCfgReady = FALSE; HwCfgExReady = FALSE; strCfgMFC = strSplitCfg.c_str(); HwCfgDP5Out = strCfgMFC; if (HwCfgDP5Out.length() >0 ) { HwCfgReady = TRUE; // filter out messages by device, gain, and option types ::PostMessage(hWnd_Main,WM_USER_SEND_CONFIG_TO_HW,0L,0L); } } //if (SCAEnabled) { // tmr.msTimer(500); // HwCfgReady = FALSE; // HwCfgExReady = FALSE; // HwCfgDP5Out = s.scafn.SCAStringALL(s.sca, TRUE); // if (HwCfgDP5Out.GetLength() >0 ) { // HwCfgExReady = TRUE; // bypass command filters for scas // ::PostMessage(s.hWnd_Main,WM_USER_SEND_CONFIG_TO_HW,0L,0L); // } //} } //------------------------------------------------------------------- // OnBnClickedPlotscaleradiolinear // Selects linear plot scale //------------------------------------------------------------------- void CvcDP5Dlg::OnBnClickedRadioPlotScaleLinear() { m_PicturePlot.OptScaleType = LINEAR_PLOT_SCALE; CheckRadioButton(IDC_RADIO_PLOT_SCALE_LINEAR, IDC_RADIO_PLOT_SCALE_LOG, IDC_RADIO_PLOT_SCALE_LINEAR); Profile.isScaleLog = FALSE; } //------------------------------------------------------------------- // OnBnClickedPlotscaleradiolog // Selects log plot scale //------------------------------------------------------------------- void CvcDP5Dlg::OnBnClickedRadioPlotScaleLog() { m_PicturePlot.OptScaleType = LOG_PLOT_SCALE; CheckRadioButton(IDC_RADIO_PLOT_SCALE_LINEAR, IDC_RADIO_PLOT_SCALE_LOG, IDC_RADIO_PLOT_SCALE_LOG); Profile.isScaleLog = TRUE; } //------------------------------------------------------------------- // OnBnClickedPlottyperadiosolid // Selects solid (bar) plot type //------------------------------------------------------------------- void CvcDP5Dlg::OnBnClickedRadioPlotTypeSolid() { m_PicturePlot.OptPlotType = SOLID_PLOT_TYPE; CheckRadioButton(IDC_RADIO_PLOT_TYPE_SOLID, IDC_RADIO_PLOT_TYPE_LINE, IDC_RADIO_PLOT_TYPE_SOLID); Profile.isPlotLine = FALSE; } //------------------------------------------------------------------- // OnBnClickedPlottyperadioline // Selects line plot type //------------------------------------------------------------------- void CvcDP5Dlg::OnBnClickedRadioPlotTypeLine() { m_PicturePlot.OptPlotType = LINE_PLOT_TYPE; CheckRadioButton(IDC_RADIO_PLOT_TYPE_SOLID, IDC_RADIO_PLOT_TYPE_LINE, IDC_RADIO_PLOT_TYPE_LINE); Profile.isPlotLine = TRUE; } // Saving spectrum file void CvcDP5Dlg::SaveTestSpectrumFile(int iFileIndex) { string strSpectrum; // holds final spectrum file SpectrumFileType sfInfo; string strFilename; string strIndex; stringex strfn; // = strfn. string sCurrentDir = AfxGetApp()->m_pszHelpFilePath; sCurrentDir = sCurrentDir.substr(0,sCurrentDir.find_last_of('\\')); CfgReadBack = TRUE; DisplayCfg = FALSE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); sfInfo.strSpectrumConfig = CreateSpectrumConfig(HwCfgDP5); // append configuration comments sfInfo.strTag.reserve(20); GetDlgItemText(IDC_EDIT_TAG,(char*)sfInfo.strTag.c_str(),20); // tag if (sfInfo.strTag.length() == 0) { sfInfo.strTag = "TestTag"; } sfInfo.strDescription.reserve(128); GetDlgItemText(IDC_EDIT_DESCRIPTION, (char*)sfInfo.strDescription.c_str(),128); // description if (sfInfo.strDescription.length() == 0) { sfInfo.strDescription = "Amptek Spectrum File"; } sfInfo.strStartTime.reserve(40); GetDlgItemText(IDC_EDIT_START_TIME, (char*)sfInfo.strStartTime.c_str(),40); // save last status after acquisition sfInfo.strSpectrumStatus = DP5Stat.ShowStatusValueStrings(DP5Stat.m_DP5_Status); sfInfo.m_iNumChan = DP5Proto.SPECTRUM.CHANNELS; // number channels in spectrum sfInfo.SerialNumber = DP5Stat.m_DP5_Status.SerialNumber; // dpp serial number // create spectrum file, save file to string strSpectrum = CreateMCAData(DP5Proto.SPECTRUM.DATA,sfInfo,DP5Stat.m_DP5_Status); strIndex = strfn.Format("%03d",iFileIndex); strFilename = sCurrentDir + "\\TestSpectrum_" + strIndex + ".mca"; SaveMCAFile(strFilename, strSpectrum); // save spectrum file string to file } // SaveSpectrum(SPECTRUM, STATUS, CommonDialog1) void CvcDP5Dlg::OnBnClickedButtonSaveFile() { CFileBrowse BR; CString strDfltExt; string strSpectrum; // holds final spectrum file SpectrumFileType sfInfo; CString strFilename; CfgReadBack = TRUE; DisplayCfg = FALSE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); sfInfo.strSpectrumConfig = CreateSpectrumConfig(HwCfgDP5); // append configuration comments sfInfo.strTag.reserve(20); GetDlgItemText(IDC_EDIT_TAG, (char*)sfInfo.strTag.c_str(),20); // tag if (sfInfo.strTag.length() == 0) { sfInfo.strTag = "TestTag"; } sfInfo.strDescription.reserve(128); GetDlgItemText(IDC_EDIT_DESCRIPTION, (char*)sfInfo.strDescription.c_str(),128); // description if (sfInfo.strDescription.length() == 0) { sfInfo.strDescription = "Amptek Spectrum File"; } sfInfo.strStartTime.reserve(64); GetDlgItemText(IDC_EDIT_START_TIME, (char*)sfInfo.strStartTime.c_str(),64); // save last status after acquisition sfInfo.strSpectrumStatus = DP5Stat.ShowStatusValueStrings(DP5Stat.m_DP5_Status); sfInfo.m_iNumChan = DP5Proto.SPECTRUM.CHANNELS; // number channels in spectrum sfInfo.SerialNumber = DP5Stat.m_DP5_Status.SerialNumber; // dpp serial number // create spectrum file, save file to string strSpectrum = CreateMCAData(DP5Proto.SPECTRUM.DATA,sfInfo,DP5Stat.m_DP5_Status); if (strSpectrum.length() > 256) { strDfltExt = _T("mca"); if (BR.DoModal(BR.SAVE, "Save Spectrum", BR.McaFileFilter, strDfltExt, _T(""), &strFilename)) { std::string stdstrFilename(strFilename, strFilename.GetLength()); SaveMCAFile(stdstrFilename, strSpectrum); // save spectrum file string to file } } } void CvcDP5Dlg::SaveMCAFile(string strFilename, string strMCA) { CFile cf(strFilename.c_str(), CFile::modeCreate | CFile::modeWrite); cf.Write(strMCA.c_str(), (unsigned int)strMCA.length()); cf.Close(); } string CvcDP5Dlg::CreateMCAData(long m_larDataBuffer[], SpectrumFileType sfInfo, DP4_FORMAT_STATUS cfgStatusLst) { string strMCA; string strText; string strADC; long idxChan; string strData; stringex strfn; // = strfn. if (cfgStatusLst.SerialNumber <= 0) { return (""); } strText = ""; strMCA = ""; switch(sfInfo.m_iNumChan){ case 16384: strADC = "6"; break; case 8192: strADC = "5"; break; case 4096: strADC = "4"; break; case 2048: strADC = "3"; break; case 1024: strADC = "2"; break; case 512: strADC = "1"; break; case 256: strADC = "0"; break; } strMCA += "<>\r\n"; strMCA += "TAG - " + sfInfo.strTag + "\r\n"; strMCA += "DESCRIPTION - " + sfInfo.strDescription + "\r\n"; strMCA += "GAIN - " + strADC + "\r\n"; strMCA += "THRESHOLD - 0\r\n"; strMCA += "LIVE_MODE - 0\r\n"; strMCA += "PRESET_TIME - \r\n"; strText = strfn.Format("%lf", cfgStatusLst.AccumulationTime); strMCA += "LIVE_TIME - " + strText + "\r\n"; strText = strfn.Format("%lf", cfgStatusLst.RealTime); strMCA += "REAL_TIME - " + strText + "\r\n"; strMCA += "START_TIME - \r\n"; strText = strfn.Format("%i", sfInfo.SerialNumber); strMCA += "SERIAL_NUMBER - " + strText + "\r\n"; strMCA += "<>\r\n"; for (idxChan=0;idxChan 12) && (CursorPosition.x < 443)) && ((CursorPosition.y > 12) && (CursorPosition.y < 260))) { m_PicturePlot.SetCursorPosition(CursorPosition.x-14); //14=sprite pointer offset string strCursorPos; strCursorPos = strfn.Format("%d,%d",CursorPosition.x,CursorPosition.y); //GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strCursorPos); m_PicturePlot.DrawCursor(); SetPlotChannel(); } CDialog::OnLButtonDown(nFlags, point); } BOOL CvcDP5Dlg::PreTranslateMessage(MSG* pMsg) { POINT pt; string strCursorPos; stringex strfn; // = strfn. if (pMsg->message == WM_KEYDOWN) { GetCursorPos(&pt); // Get the cursor position for a screen ScreenToClient(&pt); // Convert to window co-ordinates strCursorPos = strfn.Format("%d,%d",pt.x,pt.y); //GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strCursorPos); if (((pt.x > 12) && (pt.x < 443)) && ((pt.y > 12) && (pt.y < 260))) { if(pMsg->message == WM_KEYDOWN){ // DIRECTION if (pMsg->wParam == 37) //left { CursorPosition.x--; } if (pMsg->wParam == 39) //right { CursorPosition.x++; } } if (CursorPosition.x < 12) { CursorPosition.x = 12; } if (CursorPosition.x > 443) { CursorPosition.x = 443; } SetPlotChannel(); return TRUE; } } return CDialog::PreTranslateMessage(pMsg); } void CvcDP5Dlg::SetPlotChannel() { double m_xCursorData; // Cursor position (channels) stringex strfn; // = strfn. m_PicturePlot.SetCursorPosition(CursorPosition.x - 14); //14=sprite pointer offset m_PicturePlot.DrawCursor(); CRect rect; m_PicturePlot.GetClientRect(&rect); int x_min = 0; int x_max = rect.Width(); if (DP5Proto.SPECTRUM.CHANNELS < 256) { DP5Proto.SPECTRUM.CHANNELS = 1024; } double pixperchan = (double)DP5Proto.SPECTRUM.CHANNELS / (double)x_max; if ((CursorPosition.x - 14) < 0) { CursorPosition.x = 14; } if ((CursorPosition.x - 14) > x_max) { CursorPosition.x = x_max + 14; } m_xCursorData = (double)(CursorPosition.x - 14) * pixperchan; string strChan; int CurChan = (int)(m_xCursorData + 0.5); if (CurChan > DP5Proto.SPECTRUM.CHANNELS - 1) { CurChan = DP5Proto.SPECTRUM.CHANNELS - 1; } CurrentChannel = CurChan; strChan = strfn.Format("Channel %d",CurChan); GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strChan.c_str()); } double CvcDP5Dlg::GetPixPerChannel() { CRect rect; m_PicturePlot.GetClientRect(&rect); int x_min = 0; int x_max = rect.Width(); if (DP5Proto.SPECTRUM.CHANNELS < 256) { DP5Proto.SPECTRUM.CHANNELS = 1024; } double pixperchan = (double)DP5Proto.SPECTRUM.CHANNELS / (double)x_max; return pixperchan; } void CvcDP5Dlg::OnBnClickedOk() { OnOK(); } void CvcDP5Dlg::OnBnClickedCancel() { OnCancel(); } //EnableToolTips(); //ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify) //afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult); BOOL CvcDP5Dlg::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult) { TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR; UINT_PTR CtrlHandle = pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) { UINT_PTR nID = ::GetDlgCtrlID(HWND(CtrlHandle)); CWnd *p = CWnd::FromHandle(pNMHDR->hwndFrom); p->SendMessage(TTM_SETMAXTIPWIDTH, 0, 300); switch(nID) { case IDC_BUTTON_SELECT_COMM: pTTT->lpszText = _T("Open Connect Dialog \r\nto select Amptek DPP device."); break; case IDC_RADIO_PLOT_TYPE_LINE: pTTT->lpszText = _T("Line Plot Type"); break; default: //pTTT->lpszText = _T("Default Tooltip"); break; } return TRUE; } else { AfxMessageBox("!"); } return FALSE; } ////////////////////////////////////////////////////////////////////// // Function: TuneFastSlowThresh // Calls CalcFastThresh and CalcSlowThresh usb functions // Arguments: // none // Returns: // Default ////////////////////////////////////////////////////////////////////// void CvcDP5Dlg::TuneFastSlowThresh() { if (! isDppConnected ) { return; } CMSecTimer tmr; // fast threshold vars DWORD MaxTime = 5000; // max timeout for tuning int LoopCounter = 0; // slow threshold vars bool WasInMCAMode = false; int SlowThreshCh = 0; double UpperChCounts = 0.0; double UpperChMax = 0.0; CTuneSlowThreshold TuneSlowThresh; int mcaCh; stringex strfn; cWaitDialog dlg; dlg.m_Text = "Tuning...please wait"; dlg.Show(); tmr.msTimer(200); if (m_nTmrSpectrumId == 0) { // acquire Status != ACQUIRING dlg.Close(); tmr.msTimer(100); AfxMessageBox("Please start an acquisition then remove the source before setting the thresholds.", MB_TOPMOST | MB_OK | MB_ICONSTOP); return; } // Status byte 23, D6=0 -> auto fast threshold not locked; =1 -> locked DP5Stat.m_DP5_Status.AFAST_LOCKED = FALSE; // reset flag before call SendCommand(XMTPT_AUTOSET_FAST_THRESHOLD); // call tune fast thresh tmr.msTimer(50); MaxTime += GetCurrentTime(); // monitor flag until done or timeout while ((GetCurrentTime() < MaxTime) && (!DP5Stat.m_DP5_Status.AFAST_LOCKED)) { tmr.msTimer(100); LoopCounter++; if (LoopCounter > 5) { LoopCounter = 0; SendCommand(XMTPT_SEND_STATUS); } } if (!DP5Stat.m_DP5_Status.AFAST_LOCKED) { dlg.Close(); AfxMessageBox("Tune fast threshold error.\nPlease remove source if present.\nSet thresholds manually if out of auto tuning range.", MB_TOPMOST | MB_OK | MB_ICONSTOP); return; } ::SendMessage(hWnd_Main,WM_USER_READ_DPP_CONFIG,0L,0L); tmr.msTimer(200); tmr.msTimer(200); if (! isDeltaMode) { // check delta mode, if not in delta, set to delta WasInMCAMode = true; isDeltaMode = (! isDeltaMode); TuneSlowThresh.DelayTask(1000); // 1 second to convert to delta mode } mcaCh = (int)DP5Proto.SPECTRUM.CHANNELS; double FSReal; FSReal = TuneSlowThresh.SetSlowThreshToChPos(0, mcaCh); // set slow thresh to 0 if (isDppConnected) { HwCfgDP5Out = strfn.Format("THSL=%.2f;",(FSReal * 100.0)); HwCfgReady = TRUE; ::PostMessage(hWnd_Main,WM_USER_SEND_CONFIG_TO_HW,0L,0L); } TuneSlowThresh.DelayTask(1200); // wait 1 sec to settle HGLOBAL hGlobal; double *SpectrumBuffer; hGlobal = GlobalAlloc( GPTR, 16384 * sizeof(double) ); if (!hGlobal) { dlg.Close(); tmr.msTimer(100); AfxMessageBox("Tune slow threshold error.\nMemory allocation error.\nPlease try again.", MB_TOPMOST | MB_OK | MB_ICONSTOP); return; } SpectrumBuffer = (double *)GlobalLock( hGlobal ); // allocate spectrum buffer TuneSlowThresh.GetSpectrumData(SpectrumBuffer, DP5Proto.SPECTRUM.DATA, mcaCh); UpperChCounts = TuneSlowThresh.GetUpperChCounts(SpectrumBuffer, mcaCh); // this can be used ave noise UpperChMax = TuneSlowThresh.GetUpperChMax(SpectrumBuffer, mcaCh); // this is the max noise SlowThreshCh = TuneSlowThresh.GetSlowThreshCalStart(SpectrumBuffer, UpperChMax, mcaCh); double dblPixPerChan = GetPixPerChannel(); int CurPos = TuneSlowThresh.UpdatePlotCursorPosFromIntChPos(SlowThreshCh, dblPixPerChan); m_PicturePlot.SetCursorPosition(CurPos); m_PicturePlot.DrawCursor(); FSReal = TuneSlowThresh.SetSlowThreshToChPos(SlowThreshCh, mcaCh); // set the calculated setting if (isDppConnected) { HwCfgDP5Out = strfn.Format("THSL=%.2f;",(FSReal * 100.0)); HwCfgReady = TRUE; ::PostMessage(hWnd_Main,WM_USER_SEND_CONFIG_TO_HW,0L,0L); } GlobalUnlock( hGlobal ); GlobalFree( hGlobal ); if (WasInMCAMode) { // set old delta mode, if in mca, set to delta to false isDeltaMode = false; } dlg.Close(); tmr.msTimer(200); OnBnClickedButtonClearDataAndGraph(); } void CvcDP5Dlg::OnBnClickedButtonAutotune() { DisplayCfg = FALSE; TuneFastSlowThresh(); } //CTime theTime = CTime::GetCurrentTime(); //string strTime = theTime.Format( "%m/%d/%Y %H:%M:%S" ); //StartTime = strTime; //#include string CvcDP5Dlg::CreateDTS(string strFormat) { //string strFormat("_%Y%m%d_%H%M%S"); // for append filename dts //string strFormat("%m/%d/%Y %H:%M:%S"); // for spectrum dts char buffer[256]; time_t rawtime; struct tm * timeinfo; string str(""); stringex strfn; time (&rawtime); timeinfo = localtime (&rawtime); strftime(buffer, sizeof(buffer), strFormat.c_str(), timeinfo); str = strfn.Format("%s",buffer); return str; } void CvcDP5Dlg::OnBnClickedCheckRepeatSpectrum() { if (IsDlgButtonChecked(IDC_CHECK_REPEAT_SPECTRUM)) { GetDlgItem(IDC_BUTTON_START_ACQUISITION)->SetWindowText("Repeat Spectrum"); } else { GetDlgItem(IDC_BUTTON_START_ACQUISITION)->SetWindowText("Start Acquisition"); ShowRepeatStatus(false); } } ////////////////////////////////////////////////////////////////////// // ParsePerformanceNotes formats a test string into an Additional Note ////////////////////////////////////////////////////////////////////// CString CvcDP5Dlg::ParsePerformanceNotes(CString str) { int iStart,iHvBias,iEnd; CString strNote(""); iStart = 0; iHvBias = 0; iEnd = 0; //Test the prefix + first four characters iStart = str.Find("T = ",0); // test for the first line if (iStart == -1) { iStart = str.Find("Ampt",0); // test for the last line if (iStart == 0) { // the line starts at 0 strNote = str.Mid(0, 34) + "\r\n"; if (strNote.GetLength() == 36) { // found detector part number return (strNote); } } } else { if (iStart == 0) { // the line starts at 0 iHvBias = str.Find("HV Bias:",0); // test for the first line if (iHvBias > -1) { // the line end test starts at iHvBias iEnd = str.Find(",",iHvBias); // test for the end of line if (iEnd > -1) { strNote = str.Mid(0,iEnd+1) + " \r\n"; return (strNote); } } } } if (iStart == -1) { return (""); } // string not found return (""); // string found with parse error } ////////////////////////////////////////////////////////////////////// // TextToBlockString(CString &str, char *prefix) // ------------------------------------------------------------------- // Formats Additional Notes Line into TextBlock String // ------------------------------------------------------------------- // Similar function to SaveMultiString(ar, m_attr.notesNotes, ""); ////////////////////////////////////////////////////////////////////// CString CvcDP5Dlg::TextToBlockString(CString &str, char *prefix) { int pos; int length; int endPos; CString out; CString TextBlock; endPos = (int)strlen(str); out = ""; TextBlock = ""; for (pos = 0 ; pos < endPos; ) { length = str.Mid(pos).Find("\r"); if (length == -1) length = endPos - pos; out = prefix + str.Mid(pos, length) + "\r\n"; if (prefix == "") { out = ParsePerformanceNotes(out); } TextBlock += out; out = ""; pos += length + 2; } return (TextBlock); } ////////////////////////////////////////////////////////////////////// // Parses TextBlock Additional Manufacturing Notes from DPP ////////////////////////////////////////////////////////////////////// void CvcDP5Dlg::ParseTextBlockNotes(CString strTextBlock) { CString strNote; CStringArray strNotes; int idxNote = 0; CString strDisplay; strDisplay = ""; // last argument is the delimitter //while (AfxExtractSubString(strNote,strTextBlock,idxNote,_T('\n'))) CString generalNotes(""); // "" CString systemNotes(""); // "" CString notesNotes(""); // "" while (ExtractNote(strNote,strTextBlock,idxNote,_T('\n'))) { if (strNote.GetLength() > 3) { if (strNote.Find("") == 0) { generalNotes += strNote.Mid(5); } else if (strNote.Find("") == 0) { systemNotes += strNote.Mid(5); } else if (strNote.Find("") == 0) { notesNotes += strNote.Mid(5); } strNotes.Add(strNote); //AfxMessageBox(strNote); } ++idxNote; } for (int i = 0; i <= strNotes.GetUpperBound(); i++) strDisplay += strNotes[i]+"\n"; //CopyTextToClip(strDisplay); int iPos = 0; int lCount = 0 ; for (idxNote = 0; idxNote <= strDisplay.GetLength(); idxNote++) { iPos = strDisplay.Find("\n",iPos + 1); if (iPos >= 0) { lCount +=1; } else { break; } } strNote.Format("%d",lCount); //AfxMessageBox(strNote); //AfxMessageBox(strDisplay); } ////////////////////////////////////////////////////////////////////// // Reads/Extracts One Additional Note Text Line from text block of Additional Notes ////////////////////////////////////////////////////////////////////// BOOL CvcDP5Dlg::ExtractNote(CString& rString, LPCTSTR lpszFullString, int iSubString, TCHAR chSep) { if (lpszFullString == NULL) return FALSE; while (iSubString--) { lpszFullString = _tcschr(lpszFullString, chSep); if (lpszFullString == NULL) { rString.Empty(); // return empty string as well return FALSE; } lpszFullString++; // point past the separator } LPCTSTR lpchEnd = _tcschr(lpszFullString, chSep); int nLen = (lpchEnd == NULL) ? lstrlen(lpszFullString) : (int)(lpchEnd - lpszFullString); ASSERT(nLen >= 0); memcpy(rString.GetBufferSetLength(nLen), lpszFullString, nLen*sizeof(TCHAR)); rString.ReleaseBuffer(); // Need to call ReleaseBuffer // after calling GetBufferSetLength return TRUE; } ////////////////////////////////////////////////////////////////////// // Copies Text to clipboard -- not needed for TextBlock -- testing only ////////////////////////////////////////////////////////////////////// void CvcDP5Dlg::CopyTextToClip(CString strTextIn) { CString strText; strText = strTextIn; AfxGetApp()->m_pMainWnd->OpenClipboard() ; EmptyClipboard(); CSharedFile sf(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT); sf.Write(strText, strText.GetLength()); HGLOBAL hMem = sf.Detach(); if (!hMem) return; SetClipboardData(CF_TEXT, hMem); CloseClipboard(); } //X-123 S/N: X014487, AXRCR S/N: 158334 //T = 240.0 Degrees K, FWHM@5894.960keV:234.779keV, Tested with 6.4uS Peak Time, HV Bias: 180.0 Volts, //Amptek Code # ZY-FS43AMD-G3SP CString CvcDP5Dlg::CreateTextBlockTest() { CString strGeneral; CString strNotes; CString strTextBlock; strGeneral = "X-123 S/N: X014487, AXRCR S/N: 158334\r\n"; strTextBlock += TextToBlockString(strGeneral, ""); strNotes = "T = 240.0 Degrees K, FWHM@5894.960keV:234.779keV, Tested with 6.4uS Peak Time, HV Bias: 180.0 Volts, \r\n"; strNotes += "Amptek Code # ZY-FS43AMD-G3SP\r\n"; strTextBlock += TextToBlockString(strNotes, ""); //AfxMessageBox(strTextBlock); return (strTextBlock); } // strLowerTextBlock bytes 0-255 // strInfoTextBlock bytes 256-511 void CvcDP5Dlg::SendDppInfoTextBlock(CString strLowerTextBlock, CString strInfoTextBlock) { BYTE byteMiscData[512]; int idxCh; int DataLen; //GetDlgItem(IDC_EDIT_MISC_DATA)->GetWindowText(strMiscData); DataLen = strLowerTextBlock.GetLength(); for(idxCh=0;idxCh<256;idxCh++) { if (idxCh < DataLen) { byteMiscData[idxCh] = (BYTE)strLowerTextBlock.GetAt(idxCh); } else { byteMiscData[idxCh] = 0; } } DataLen = strInfoTextBlock.GetLength(); for(idxCh=0;(idxCh+256)<512;idxCh++) { if (idxCh < DataLen) { byteMiscData[idxCh+256] = (BYTE)strInfoTextBlock.GetAt(idxCh); } else { byteMiscData[idxCh+256] = 0; } } SendCommandData(XMTPT_WRITE_512_BYTE_MISC_DATA, byteMiscData); } void CvcDP5Dlg::WriteTextBlock() { CString strInfoTextBlock(""); strInfoTextBlock = CreateTextBlockTest(); // get lower text block CString strLowerTextBlock("PX5 ATE Test"); SendDppInfoTextBlock(strLowerTextBlock, strInfoTextBlock); //////CString strMiscData; //////BYTE byteMiscData[512]; //////int idxCh; //////int DataLen; //////GetDlgItem(IDC_EDIT_MISC_DATA)->GetWindowText(strMiscData); //////DataLen = strMiscData.GetLength(); //////for(idxCh=0;idxCh<512;idxCh++) { ////// if (idxCh < DataLen) { ////// byteMiscData[idxCh] = (BYTE)strMiscData.GetAt(idxCh); ////// } else { ////// byteMiscData[idxCh] = 0; ////// } //////} ////// SendCommandData(XMTPT_WRITE_512_BYTE_MISC_DATA, byteMiscData); } ////////////////////////////////////////////////////////////////////// // Functions to be completed ////////////////////////////////////////////////////////////////////// // when writing the text block in the future // 1. Read the Whole Text Block // 2. Overwrite/edit the lower half (256 bytes) only // 3. Save the upper half as is // when reading the user text block // 1. Read the Whole Text Block // 2. Only display/edit the lower half (256 bytes) only // 3. Save the upper half as is // when reading the manufacturing test information // 1. Read the Whole Text Block // 2. Only read the upper half of the buffer // 3. The upper half is only edited during manufacturing test ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Send Manufacturing Text Block Test // ---------------------------------- // 20150928 TextBlock // Test DPP Notes Here for Text Block Save // if (General Notes (generalNotes) -> ((X-123 S/N: or PX5 S/N: or PC5 S/N:) // AND have performance notes (notesNotes) // parse notesNotes // save generalNotes and parsed notesNotes // save data to text block ////////////////////////////////////////////////////////////////////// bool CvcDP5Dlg::SendManufacturingTextBlock(CString generalNotes) { int iPX5=-1; //px5 int iX123=-1; //x123 int iPC5=-1; //dp5 with pc5 CString strPX5("PX5 S/N:"); //px5 CString strX123("X-123 S/N:"); //x123 CString strPC5("PC5 S/N:"); //dp5 with pc5 bool bSendBlock=false; iPX5 = generalNotes.Find(strPX5,0); iX123 = generalNotes.Find(strX123,0); iPC5 = generalNotes.Find(strPC5,0); if ((iPX5 >= 0) || (iX123 >= 0) || (iPC5 >= 0)) { bSendBlock = true; } return bSendBlock; }