// vcDP5Dlg.cpp : implementation file // #include "stdafx.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 "DppGain.h" #include "afxadv.h" // for cfg file clipboard copy #include "TuneSlowThreshold.h" #include "MsgBox.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 s.HwCfgDP5 = ""; s.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_DPPCOMM_RCV_CHAR, OnCommunication) ON_MESSAGE(WM_DPPSOCKET_RCV_BUFFER, OnReceive) ON_MESSAGE(WM_USER_SEND_CONFIG_TO_HW, DppSendConfigToHw) ON_MESSAGE(WM_USER_READ_DPP_CONFIG, CallReadDppConfig) ON_MESSAGE(WM_USER_READ_DPP_CONFIG_EX, CallReadDppConfigEx) 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_EDIT_CONFIG, OnBnClickedButtonEditConfig) 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_BN_CLICKED(IDC_BUTTON_CLEAR_ROI, OnBnClickedButtonClearRoi) ON_BN_CLICKED(IDC_BUTTON_ROI_END, OnBnClickedButtonRoiEnd) ON_BN_CLICKED(IDC_BUTTON_ROI_START, OnBnClickedButtonRoiStart) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipNotify) ON_BN_CLICKED(IDC_BUTTON_AUTOTUNE, OnBnClickedButtonAutotune) 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 strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } 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 s.hWnd_Main = this->GetSafeHwnd(); // TODO: Add extra initialization here s.WinusbNotify.SetNotificationWindow(this->m_hWnd); s.DppWinUSB.devInfo.deviceConnected = FALSE; // no device selected upon startup s.isDppFound[RS232] = FALSE; s.isDppFound[USB] = FALSE; s.isDppFound[ETHERNET] = FALSE; m_PicturePlot.OptScaleType = BOOL_TO_bool(s.isScaleLog); m_PicturePlot.OptPlotType = BOOL_TO_bool(s.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); 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); CString strStatus; CString strDevice; switch(nEventType) { case DBT_DEVICEARRIVAL: //return TRUE; lblStatus.SetText(strStatus); if (s.WinusbNotify.GetDevNotifyInfo(dwData, s.DppWinUSB.devInfo.devicePath)) { strStatus = " "; lblStatus.SetText(strStatus); strStatus = ""; lblStatus.SetText(strStatus); strStatus = "Device Connected. Reconnecting to device."; lblStatus.SetText(strStatus); OnBnClickedButtonFindDevice(); } break; case DBT_DEVICEREMOVECOMPLETE: if (s.WinusbNotify.GetDevNotifyInfo(dwData, s.DppWinUSB.devInfo.devicePath)) { EnableDPPFunctions(FALSE); s.DppWinUSB.devInfo.deviceConnected = FALSE; strStatus = "Device Removed"; lblStatus.SetText(strStatus); } break; default: break; //AfxMessageBox("Unknown"); } // TODO: Add your message handler code here return true; } void CvcDP5Dlg::OnResetCommunications() { //Sleep(1000); // make sure timer is done //s.SaveProfile(); s.DppWinUSB.devInfo.deviceConnected = FALSE; s.DppWinUSB.CloseWinUsbDevice(); s.WinusbNotify.RemoveDeviceNotification(); if (s.m_DppPort.IsPortOpen()) { // close the port s.m_DppPort.ClosePort(); } if (s.m_DppSck.IsSocketOpen()) { // close the port s.m_DppSck.CloseSocket(); } } void CvcDP5Dlg::OnDestroy() { s.isDppConnected = FALSE; CDialog::OnDestroy(); CMSecTimer tmr; s.SaveProfile(); if (m_nTmrSpectrumId > 0) { KillTimer(m_nTmrSpectrumId); m_nTmrSpectrumId = 0; tmr.msTimer(1000); // put refresh rate here } OnResetCommunications(); } unsigned long CvcDP5Dlg::DataTest() { BOOL bResult; USHORT bufSizeOut = 8; unsigned char szBufferOut[8] = { 0xF5, 0xFA, 0x02, 0x03, 0x00, 0x00, 0xFE, 0x0C }; unsigned long bytesWritten; USHORT bufSizeIn = 32767; unsigned char szBufferIn[32767]; unsigned long bytesRead; string bufOut; USHORT idxStatus; bytesRead = 0; bResult = WinUsb_WritePipe(s.DppWinUSB.devInfo.winUSBHandle, s.DppWinUSB.devInfo.bulkOutPipe, szBufferOut, bufSizeOut, &bytesWritten, NULL); Sleep(10); if (bResult) { bResult = WinUsb_ReadPipe(s.DppWinUSB.devInfo.winUSBHandle, s.DppWinUSB.devInfo.bulkInPipe, szBufferIn, bufSizeIn, &bytesRead, NULL); if (bResult) { if (bytesRead == 840) { for(idxStatus = 0; idxStatus<64; idxStatus++) { s.DP5Stat.m_DP5_Status.RAW[idxStatus] = szBufferIn[774 + idxStatus]; s.DP5Stat.Process_Status(&s.DP5Stat.m_DP5_Status); } bufOut = s.DppWinUSB.DisplayBufferArray(szBufferIn, bytesRead); s.DppWinUSB.SaveStringDataToFile(bufOut); } } } return bytesRead; } void CvcDP5Dlg::OnBnClickedButtonFindDevice() { string strUSBStatus; DPP_USB_STATUS USBStatus; //0=do nothing, 1=new connect, 2=cannot connect USBStatus = s.DppWinUSB.FindUSBDevice(s.DppWinUSB.CurrentDevice - 1); if (USBStatus != dusbStatNoAction) { strUSBStatus = s.DppWinUSB.USBStatusString(USBStatus); lblStatus.SetText(strUSBStatus.c_str()); if (USBStatus == dusbStatNewConnect) { EnableDPPFunctions(TRUE); } } } void CvcDP5Dlg::RemCallParsePacket(unsigned char PacketIn[]) { s.ParsePkt.DppState.ReqProcess = s.ParsePkt.ParsePacket(PacketIn, &s.DP5Proto.PIN); ParsePacketEx(s.DP5Proto.PIN, s.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) { CString strError; ShowStatus(s.ParsePkt.PID2_TextToString("Received Packet", PIN.STATUS).c_str()); // bad PID, assigned by ParsePacket if (PIN.STATUS == PID2_ACK_PID_ERROR) { strError.Format("Received packet: PID1=0x.2X PID1=0x.2X LEN=%d",PIN.PID1,PIN.PID2,PIN.LEN); ShowStatus(strError); } } void CvcDP5Dlg::ProcessAck(unsigned char PID2) { ShowStatus(s.ParsePkt.PID2_TextToString("ACK", PID2).c_str()); } void CvcDP5Dlg::ProcessStatusEx(Packet_In PIN, DppStateType DppState) { long idxStatus; for(idxStatus=0;idxStatus<64;idxStatus++) { s.DP5Stat.m_DP5_Status.RAW[idxStatus] = PIN.DATA[idxStatus]; } s.DP5Stat.Process_Status(&s.DP5Stat.m_DP5_Status); ConvertStatusDP5ToDP4(s.DP5Stat.m_DP5_Status); RequestScopeData(s.DP5Stat.m_DP5_Status.SCOPE_DR); ShowStatus("Received Status"); } // holds dp4/px4/dp5(px4emul) status and configuration // will be replaced by DP5 or generic status/config classes void CvcDP5Dlg::ConvertStatusDP5ToDP4(DP4_FORMAT_STATUS m_DP5_Status) { //================================================= // DP5 DP4 Status Values //================================================= s.DppConfig.SetFastThreshDone = m_DP5_Status.AFAST_LOCKED; //BOOL //================================================= //dp4/px4/dp5(px4emul) status and configuration //================================================= s.DppConfig.SerialNumber = m_DP5_Status.SerialNumber; //unsigned long s.DppConfig.FastCount = m_DP5_Status.FastCount; //double s.DppConfig.SlowCount = m_DP5_Status.SlowCount; //double s.DppConfig.FPGA = m_DP5_Status.FPGA; //unsigned char s.DppConfig.Firmware = m_DP5_Status.Firmware; //unsigned char s.DppConfig.Build = m_DP5_Status.Build; //unsigned char s.DppConfig.AccumulationTime = m_DP5_Status.AccumulationTime; //double s.DppConfig.HVMonitor = m_DP5_Status.HV; //double s.DppConfig.HVMonitorCStr.Format("%.0fV",s.DppConfig.HVMonitor); s.DppConfig.TECMonitor = m_DP5_Status.DET_TEMP; //double s.DppConfig.TECMonitorCStr.Format("%.0fK",s.DppConfig.TECMonitor); s.DppConfig.BoardTemp = (int)m_DP5_Status.DP5_TEMP; //double s.DppConfig.BoardTempCStr.Format("%d°C",s.DppConfig.BoardTemp); //acquisition flags -> mca/mcs/preset status s.DppConfig.StatMcaEnabled = m_DP5_Status.MCA_EN; //BOOL s.DppConfig.MCSDone = m_DP5_Status.MCS_DONE; //BOOL s.DppConfig.PresetCountExpired = m_DP5_Status.PRECNT_REACHED; //BOOL s.DppConfig.PresetRtDone = m_DP5_Status.PresetRtDone; //BOOL s.DppConfig.RealTime = m_DP5_Status.RealTime; s.DppConfig.b80MHzMode = m_DP5_Status.b80MHzMode; s.DppConfig.bFPGAAutoClock = m_DP5_Status.bFPGAAutoClock; //// configuration indicator support // GammaRad HV s.DppConfig.bGammaRadHVMode = (BOOL)(m_DP5_Status.DEVICE_ID == 2); // PC5 connected/PX5 HV Pwr Error s.DppConfig.bPC5Detected = m_DP5_Status.PC5_PRESENT; //BOOL // HV Polarity from status packet s.DppConfig.bBootHVPolarity = m_DP5_Status.PC5_HV_POL; //BOOL } void CvcDP5Dlg::ProcessDiagDataEx(Packet_In PIN, DppStateType DppState) { string strDiagData; s.DP5Stat.Process_Diagnostics(PIN, &s.DP5Stat.DiagData, s.profile->device_type); strDiagData = s.DP5Stat.DiagnosticsToString(s.DP5Stat.DiagData, s.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; s.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 += s.DppConfig.strPresetCmd; strMiscInfo += "\r\n"; strMiscInfo += "Preset "; strMiscInfo += s.DppConfig.strPresetVal; strMiscInfo += "\r\n"; lblMiscStatus.SetText(strMiscInfo.c_str()); RequestScopeData(s.DP5Stat.m_DP5_Status.SCOPE_DR); } m_PicturePlot.DataAcq(s.DP5Proto.SPECTRUM.DATA, s.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; CString strTextData; CString strCh; strTextData = ""; for(idxTextData=0;idxTextData<512;idxTextData++) { strCh.Format("%c",PIN.DATA[idxTextData]); strTextData += strCh; } GetDlgItem(IDC_EDIT_MISC_DATA)->SetWindowText(strTextData); } void CvcDP5Dlg::RequestScopeData(BOOL ScopeDataReady) { if (ScopeDataReady) { SendCommand(XMTPT_SEND_SCOPE_DATA); } } void CvcDP5Dlg::SendCommand(TRANSMIT_PACKET_TYPE XmtCmd) { BOOL HaveBuffer; BOOL SentPkt; //CONFIG_OPTIONS CfgOptions; //CfgOptions.DppType = s.DP5Stat.m_DP5_Status.DEVICE_ID; //CfgOptions.HwCfgDP5Out = s.HwCfgDP5Out; //CfgOptions.PC5_PRESENT = s.DP5Stat.m_DP5_Status.PC5_PRESENT; //CfgOptions.SendCoarseFineGain = FALSE; HaveBuffer = s.SndCmd.DP5_CMD(s.DP5Proto.BufferOUT, XmtCmd); if (HaveBuffer) { switch (s.CurrentInterface) { case RS232: memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); // flush input s.DP5Proto.RS232BytesInBuffer = 0; s.DP5Proto.RS232HeaderReceived = FALSE; s.DP5Proto.RS232_RThreshold = 8; s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.m_DppPort.SendPacketRS232(s.DP5Proto.BufferOUT, &s.m_DppPort); break; case USB: s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.DppWinUSB.SendPacketUSB(s.DP5Proto.BufferOUT, s.DppWinUSB.devInfo, s.DP5Proto.PacketIn); if (SentPkt) { RemCallParsePacket(s.DP5Proto.PacketIn); } else { //Timer2.Enabled = False } break; case ETHERNET: memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); s.m_DppSck.RcvTotal = 0; // reset vars s.m_DppSck.RcvCount = 0; s.m_DppSck.HaveHeader = FALSE; s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.m_DppSck.SendPacketInet(s.DP5Proto.BufferOUT, &s.m_DppSck); break; default: break; } } } //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 = s.DP5Stat.m_DP5_Status.DEVICE_ID; CfgOptions.HwCfgDP5Out = s.HwCfgDP5Out; CfgOptions.PC5_PRESENT = s.DP5Stat.m_DP5_Status.PC5_PRESENT; CfgOptions.SendCoarseFineGain = FALSE; CfgOptions.isDP5_RevDxGains = s.DP5Stat.m_DP5_Status.isDP5_RevDxGains; CfgOptions.DPP_ECO = s.DP5Stat.m_DP5_Status.DPP_ECO; HaveBuffer = s.SndCmd.DP5_CMD_Config(s.DP5Proto.BufferOUT, XmtCmd, CfgOptions); if (HaveBuffer) { // SentPkt = s.DppWinUSB.SendPacketUSB(s.DP5Proto.BufferOUT, s.DppWinUSB.devInfo, s.DP5Proto.PacketIn); // if (SentPkt) { // RemCallParsePacket(s.DP5Proto.PacketIn); //} else { // //Timer2.Enabled = False // } switch (s.CurrentInterface) { case RS232: memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); // flush input s.DP5Proto.RS232BytesInBuffer = 0; s.DP5Proto.RS232HeaderReceived = FALSE; s.DP5Proto.RS232_RThreshold = 8; s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.m_DppPort.SendPacketRS232(s.DP5Proto.BufferOUT, &s.m_DppPort); break; case USB: s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.DppWinUSB.SendPacketUSB(s.DP5Proto.BufferOUT, s.DppWinUSB.devInfo, s.DP5Proto.PacketIn); if (SentPkt) { RemCallParsePacket(s.DP5Proto.PacketIn); } else { //Timer2.Enabled = False } break; case ETHERNET: memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); s.m_DppSck.RcvTotal = 0; // reset vars s.m_DppSck.RcvCount = 0; s.m_DppSck.HaveHeader = FALSE; s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.m_DppSck.SendPacketInet(s.DP5Proto.BufferOUT, &s.m_DppSck); break; default: break; } } } 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, unsigned char DataOut[]) { BOOL HaveBuffer; BOOL SentPkt; HaveBuffer = s.SndCmd.DP5_CMD_Data(s.DP5Proto.BufferOUT, XmtCmd, DataOut); if (HaveBuffer) { switch (s.CurrentInterface) { case RS232: memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); // flush input s.DP5Proto.RS232BytesInBuffer = 0; s.DP5Proto.RS232HeaderReceived = FALSE; s.DP5Proto.RS232_RThreshold = 8; s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.m_DppPort.SendPacketRS232(s.DP5Proto.BufferOUT, &s.m_DppPort); break; case USB: s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.DppWinUSB.SendPacketUSB(s.DP5Proto.BufferOUT, s.DppWinUSB.devInfo, s.DP5Proto.PacketIn); if (SentPkt) { RemCallParsePacket(s.DP5Proto.PacketIn); } else { //Timer2.Enabled = False } break; case ETHERNET: memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); s.m_DppSck.RcvTotal = 0; // reset vars s.m_DppSck.RcvCount = 0; s.m_DppSck.HaveHeader = FALSE; s.DP5Proto.ACK_Received = false; s.DP5Proto.Packet_Received = false; // a response packet is always expected s.DP5Proto.PIN.STATUS = 0xFF; // packet invalid - will be overwritten soon by response/ACK packet SentPkt = s.m_DppSck.SendPacketInet(s.DP5Proto.BufferOUT, &s.m_DppSck); break; default: break; } } } void CvcDP5Dlg::OnTimer(UINT nIDEvent) { if (nIDEvent == m_nTmrRS232Id) { //100ms RS232 //m_nTmrRS232Id = SetTimer(m_nTmrRS232EventId, m_nTmrRS232Elapse, NULL); //MSComm1.RThreshold = 8 ' 8 byte ACK packet expected //KillTimer(m_nTmrRS232Id); } else if (nIDEvent == m_nTmrSpectrumId) { // 1000ms AutoSpectrum if (IsDlgButtonChecked(IDC_CHECK_DELTA)) { SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); } else { SendCommand(XMTPT_SEND_SPECTRUM_STATUS); } } else if (nIDEvent == m_nTmrTimeoutId) { // 10ms Comm TimeOut //m_nTmrTimeoutId = SetTimer(m_nTmrTimeoutEventId, m_nTmrTimeoutElapse, NULL); TimeoutFlag = TRUE; } CDialog::OnTimer(nIDEvent); } void CvcDP5Dlg::OnBnClickedButtonArmTrigger() { SendCommand(XMTPT_ARM_DIGITAL_OSCILLOSCOPE); } void CvcDP5Dlg::OnBnClickedButtonClearDataAndGraph() { SendCommand(XMTPT_SEND_CLEAR_SPECTRUM_STATUS); m_PicturePlot.ClearTrace(); } void CvcDP5Dlg::OnBnClickedButtonSingleUpdate() { 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() { CString strMiscData; unsigned char 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] = (unsigned char)strMiscData.GetAt(idxCh); } else { byteMiscData[idxCh] = 0; } } SendCommandData(XMTPT_WRITE_512_BYTE_MISC_DATA, byteMiscData); } void CvcDP5Dlg::ShowStatus(CString strStatus) { GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strStatus); } //------------------------------------------------------------------- // 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(unsigned char 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) { // find device is always enabled //GetDlgItem(IDC_BUTTON_FIND_DEVICE)->EnableWindow(isEnabled); //Find Device // Config //GetDlgItem(IDC_BUTTON_EDIT_CONFIG)->EnableWindow(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() { CString 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); // TODO: Place code here to handle when the dialog is // dismissed with OK // update communications controls if (s.CurrentInterface == RS232) { if (s.isDppFound[RS232]) { Sleep(100); if (s.m_DppPort.IsPortOpen()) { // close the port s.m_DppPort.ClosePort(); } Sleep(100); if (!s.m_DppPort.IsPortOpen()) { // init the port if (s.m_DppPort.Settings(this, s.ComPort, 115200, 'N', 8, 1, EV_RXCHAR, 1024)) { s.m_DppPort.OpenPort(); } } Sleep(100); if (s.m_DppPort.IsPortOpen()) { // success strSelected.Format("RS232 - COM%d", s.ComPort); EnableDPPFunctions(TRUE); } Sleep(100); } } if (s.CurrentInterface == USB) { if (s.DppWinUSB.devInfo.deviceConnected) { strSelected = "USB - WinUSB"; EnableDPPFunctions(TRUE); } } else if (s.CurrentInterface == ETHERNET) { if (s.isDppFound[ETHERNET]) { strSelected = "IP " + s.strSockAddr; s.m_DppSck.CloseSocket(); s.m_DppSck.CreateSocket(this); s.m_DppSck.m_Owner = sockownMainDlg; EnableDPPFunctions(TRUE); } } isConnectedTest(); lblSelectCommunications.SetText(strSelected); } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } } CString CvcDP5Dlg::GetDeviceNameFromVal(int DeviceTypeVal) { CString 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; case dppDP5X: strDeviceType = "DP5-X"; break; default: //if unknown set to DP5 strDeviceType = "DP5"; break; } return strDeviceType; } // sets/returns if DPP is connected based on CurrentInterface and isDppFound[] BOOL CvcDP5Dlg::isConnectedTest() { unsigned char CurrentInterface; BOOL isDppFound; CMSecTimer tmr; // test if CurrentInterface is set if ((s.CurrentInterface >= RS232) && (s.CurrentInterface <= ETHERNET)) { // test if unit is found CurrentInterface = s.CurrentInterface; isDppFound = s.isDppFound[CurrentInterface]; s.isDppConnected = isDppFound; if (s.isDppConnected) { SendCommand(XMTPT_SEND_STATUS); // request status tmr.msTimer(500); } s.profile->device_type = s.DP5Stat.m_DP5_Status.DEVICE_ID; s.DppConfig.DeviceType = s.DP5Stat.m_DP5_Status.DEVICE_ID; s.profile->strDevice = GetDeviceNameFromVal(s.profile->device_type); s.DppCommStatusInd = (int)(s.CurrentInterface * 2) + (int)isDppFound; return isDppFound; } else { s.isDppConnected = FALSE; return FALSE; } } // Serial Comm Port Character Received Event LONG CvcDP5Dlg::OnCommunication(WPARAM ch, LPARAM Bytes) { DWORD BytesRead; BytesRead = (DWORD)Bytes; if (BytesRead == 0) return -1; s.DP5Proto.PacketIn[s.DP5Proto.RS232BytesInBuffer]=(unsigned char)ch; s.DP5Proto.RS232BytesInBuffer+=BytesRead; // this calls OnComm for RxChar Events if (s.DP5Proto.RS232_RThreshold == 0) { // always call if thresh == 0 OnComm(); } else if (s.DP5Proto.RS232BytesInBuffer >= s.DP5Proto.RS232_RThreshold) { OnComm(); } return 0; } // Serial Comm Port Bulk Character Processing void CvcDP5Dlg::OnComm() { long pktLen; if (s.DP5Proto.RS232HeaderReceived) { s.DP5Proto.RS232HeaderReceived = FALSE; // the buffer should have the data, oncomm only call when rthresh bytes if (s.DP5Proto.RS232BytesInBuffer == s.DP5Proto.RS232_RThreshold) { //KillTimer(m_nTmrRS232Id); RemCallParsePacket(s.DP5Proto.PacketIn); } s.DP5Proto.RS232_RThreshold = 8; // reset oncomm for next message } else { if (s.DP5Proto.RS232BytesInBuffer >= s.DP5Proto.RS232_RThreshold) { if ((s.DP5Proto.PacketIn[0] == 0xF5) && (s.DP5Proto.PacketIn[1] == 0xFA)) { pktLen = (long)((s.DP5Proto.PacketIn[4] * 256) + s.DP5Proto.PacketIn[5] + 8); // temporarily save the length field if (pktLen > 0) { s.DP5Proto.RS232_RThreshold = pktLen; // additional bytes to read = data length //SetDataRcvTimer(RS232_RThreshold); s.DP5Proto.RS232HeaderReceived = TRUE; } else { //ParsePacket(DataIn[]); } } else { memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); // flush the buffer by emptying it } } } } //void CvcDP5Dlg::OnReceive(int nErrorCode) LONG CvcDP5Dlg::OnReceive(WPARAM ch, LPARAM Bytes) { CString SourceIPAddr; UINT SourcePort; unsigned char buffer[1024] = {0}; int RcvBytes; int idxNewData; long pktLen; CString strStatus; BOOL HavePkt; memset(&buffer, 0, sizeof(buffer)); // flush the buffer by emptying it RcvBytes = s.m_DppSck.ReceiveFrom(&buffer, sizeof(buffer), SourceIPAddr, SourcePort); // Check for errors if(RcvBytes > sizeof(buffer)){ // buffer overflow // Handle Error return 0; //return; } else if((s.m_DppSck.RcvCount + RcvBytes) > sizeof(s.DP5Proto.PacketIn)){ // Handle Error // buffer overflow return 0; //return; } else if(RcvBytes == SOCKET_ERROR) { // Call GetLastError To Get Message // Handle Error return 0; //return; } if((s.m_DppSck.RcvCount + RcvBytes) > sizeof(s.DP5Proto.PacketIn)){ // Handle Error // buffer overflow return 0; //return; } HavePkt = FALSE; if (s.m_DppSck.HaveHeader) { // have header and new data, add data to packet for(idxNewData=0;idxNewData= s.m_DppSck.RcvTotal) { HavePkt = TRUE; RemCallParsePacket(s.DP5Proto.PacketIn); // have packet, process packet s.m_DppSck.RcvTotal = 0; // reset vars s.m_DppSck.RcvCount = 0; s.m_DppSck.HaveHeader = FALSE; } } else { // no header found yet, get packet info if (RcvBytes >= 8) { // 1st packet must always have header, check header/length if ((buffer[0] == 0xF5) && (buffer[1] == 0xFA)) { pktLen = (long)((buffer[4] * 256) + buffer[5] + 8); // temporarily save the length field s.m_DppSck.RcvTotal = pktLen; // additional bytes to read = data length s.m_DppSck.RcvCount = 0; // haven't saved the data yet s.m_DppSck.HaveHeader = TRUE; for(idxNewData=0;idxNewData= s.m_DppSck.RcvTotal)) { RemCallParsePacket(s.DP5Proto.PacketIn); // have packet, process packet s.m_DppSck.RcvTotal = 0; // reset vars s.m_DppSck.RcvCount = 0; s.m_DppSck.HaveHeader = FALSE; } } else { // this is an error //// flush the buffer by emptying it (PacketIn should already be empty) memset(&s.DP5Proto.PacketIn, 0, sizeof(s.DP5Proto.PacketIn)); s.m_DppSck.RcvTotal = 0; // reset vars s.m_DppSck.RcvCount = 0; s.m_DppSck.HaveHeader = FALSE; } } } return 0; //return; } void CvcDP5Dlg::OnBnClickedButtonStartAcquisition() { SendCommand(XMTPT_ENABLE_MCA_MCS); m_nTmrSpectrumId = SetTimer(m_nTmrSpectrumEventId, m_nTmrSpectrumElapse, NULL); } void CvcDP5Dlg::OnBnClickedButtonStopAcquisition() { SendCommand(XMTPT_DISABLE_MCA_MCS); } void CvcDP5Dlg::OnBnClickedButtonEditConfig() { CDP5CfgWnd *m_pdlg; s.DppConfig.b80MHzModeCfg = s.DppConfig.b80MHzMode; m_pdlg = new CDP5CfgWnd(IDS_CAPTION); INT_PTR nResponse = m_pdlg->DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } delete m_pdlg; } LRESULT CvcDP5Dlg::DppSendConfigToHw(WPARAM wParam, LPARAM lParam) { if (s.isDppConnected) { if (s.HwCfgReady) { SendCommandConfig(XMTPT_SEND_CONFIG_PACKET_TO_HW); // send the packet s.HwCfgReady = FALSE; //AfxMessageBox("Config Sent To HW"); } else if (s.HwCfgExReady) { SendCommandConfig(XMTPT_SEND_CONFIG_PACKET_EX); // send the packet s.HwCfgExReady = FALSE; } } CMSecTimer tmr; if (s.isDppConnected) { tmr.msTimer(20); //Sleep(20); // wait a short time SendCommandConfig(XMTPT_READ_CONFIG_PACKET); // get info for display tmr.msTimer(20); } return (Default()); } LRESULT CvcDP5Dlg::CallReadDppConfig(WPARAM wParam, LPARAM lParam) { if (s.isDppConnected) { s.DppConfig.CfgReadBack = TRUE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); } return (Default()); } LRESULT CvcDP5Dlg::CallReadDppConfigEx(WPARAM wParam, LPARAM lParam) { if (s.isDppConnected) { s.DppConfig.CfgReadBack = TRUE; SendCommandConfig(XMTPT_READ_CONFIG_PACKET_EX); } return (Default()); } LRESULT CvcDP5Dlg::CallReadScaConfig(WPARAM wParam, LPARAM lParam) { if (s.isDppConnected) { s.DppConfig.ScaReadBack = TRUE; SendCommand(XMTPT_SCA_READ_CONFIG_PACKET); } return (Default()); } void CvcDP5Dlg::ProcessCfgReadEx(Packet_In PIN, DppStateType DppState) { CString strRawCfgIn; CString strRawCfgOut; CString strCh; CString strCmdData; strRawCfgIn = ""; CString strCmdD; CString strCfg; BOOL isScaCfg = FALSE; CString strDisplayCfgOut; strRawCfgOut = ""; // ========================================================== // ===== Create Raw Configuration Buffer From Hardware ====== for (int idxCfg=0;idxCfg 0) { strDisplayCfgOut = ReplaceCmdDescMS(strCmdD,strDisplayCfgOut); } } CopyDp5CfgToClip(strCfg,strDisplayCfgOut); CMsgBox MsgBox; MsgBox.m_strTitle = "DPP Configuration"; MsgBox.m_strMessage = strDisplayCfgOut; MsgBox.m_strDelimiter = ";"; MsgBox.DoModal(); return; } else if (s.DppConfig.CfgReadBack) { s.DppConfig.CfgReadBack = FALSE; s.HwCfgDP5 = strRawCfgIn; s.HwCfgReady = TRUE; } else if (s.DppConfig.ScaReadBack) { //s.HwCfgDP5 = strRawCfgIn; //s.strRawCfgIn = strRawCfgIn; s.scafn.SCACfgParser(&s.sca, strRawCfgOut); s.HwCfgReady = TRUE; //if (s.DppConfig.DisplaySCA) { //AfxMessageBox(SCAStringALLDisplay(sca)); //} } s.DppConfig.SaveCfg = FALSE; s.DppConfig.PrintCfg = FALSE; s.DppConfig.DisplayCfg = FALSE; s.DppConfig.CfgReadBack = FALSE; isScaCfg = (BOOL)(s.DppConfig.ScaReadBack || s.DppConfig.DisplaySca); s.DppConfig.ScaReadBack = FALSE; s.DppConfig.DisplaySca = FALSE; if (isScaCfg) { return; } strCmdData = GetCmdDataMS("MCAS",strRawCfgIn); // mca mode strCmdData = GetCmdDataMS("MCAC",strRawCfgIn); // channels if ((atoi(strCmdData) > 0) && (atoi(strCmdData) <= 8192)) { s.DppConfig.mcaCH = atoi(strCmdData); } else { s.DppConfig.mcaCH = 1024; } strCmdData = GetCmdDataMS("THSL",strRawCfgIn); // LLD thresh s.DppConfig.SlowThresholdPct = atof(strCmdData); strCmdData = GetCmdDataMS("THFA",strRawCfgIn); // fast thresh s.DppConfig.FastChThreshold = atoi(strCmdData); strCmdData = GetCmdDataMS("TPEA",strRawCfgIn); // peak time s.DppConfig.RiseUS = atof(strCmdData); strCmdData = GetCmdDataMS("GAIN",strRawCfgIn); // gain s.DppConfig.strGainDisplayValue = strCmdData + "x"; s.DppConfig.strPresetCmd = ""; s.DppConfig.strPresetVal = ""; strCmdData = GetCmdDataMS("PREC",strRawCfgIn); //preset count s.DppConfig.PresetCount = atoi(strCmdData); if (s.DppConfig.PresetCount > 0) { if (s.DppConfig.strPresetCmd.GetLength() > 0) { s.DppConfig.strPresetCmd += "/"; } if (s.DppConfig.strPresetVal.GetLength() > 0) { s.DppConfig.strPresetVal += "/"; } s.DppConfig.strPresetCmd += "Cnt"; s.DppConfig.strPresetVal += strCmdData; } strCmdData = GetCmdDataMS("PRET",strRawCfgIn); //preset actual time s.DppConfig.PresetAcq = atof(strCmdData); if (s.DppConfig.PresetAcq > 0) { if (s.DppConfig.strPresetCmd.GetLength() > 0) { s.DppConfig.strPresetCmd += "/"; } if (s.DppConfig.strPresetVal.GetLength() > 0) { s.DppConfig.strPresetVal += "/"; } s.DppConfig.strPresetCmd += "Acq"; s.DppConfig.strPresetVal += strCmdData; } strCmdData = GetCmdDataMS("PRER",strRawCfgIn); // preset real time s.DppConfig.PresetRt = atof(strCmdData); if (s.DppConfig.PresetRt > 0) { if (s.DppConfig.strPresetCmd.GetLength() > 0) { s.DppConfig.strPresetCmd += "/"; } if (s.DppConfig.strPresetVal.GetLength() > 0) { s.DppConfig.strPresetVal += "/"; } s.DppConfig.strPresetCmd += "Real"; s.DppConfig.strPresetVal += strCmdData; } if (s.DppConfig.strPresetCmd.GetLength() == 0) { s.DppConfig.strPresetCmd += "None"; } if (s.DppConfig.strPresetVal.GetLength() == 0) { //s.DppConfig.strPresetVal += ""; } strCmdData = GetCmdDataMS("CLCK",strRawCfgIn); // fpga clock mode if (atoi(strCmdData) == 80) { s.DppConfig.b80MHzMode = TRUE; } else { s.DppConfig.b80MHzMode = FALSE; } // DP5 oscilloscope support strCmdData = GetCmdDataMS("INOF",strRawCfgIn); // osc. Input offset s.DppConfig.strInputOffset = strCmdData; strCmdData = GetCmdDataMS("DACO",strRawCfgIn); // osc. DAC output s.DppConfig.strAnalogOut = strCmdData; strCmdData = GetCmdDataMS("DACF",strRawCfgIn); // osc. DAC offset s.DppConfig.strOutputOffset = strCmdData; strCmdData = GetCmdDataMS("AUO1",strRawCfgIn); // osc. AUX_OUT1 s.DppConfig.strTriggerSource = strCmdData; strCmdData = GetCmdDataMS("SCOE",strRawCfgIn); // osc. Scope trigger edge s.DppConfig.strTriggerSlope = strCmdData; strCmdData = GetCmdDataMS("SCOT",strRawCfgIn); // osc. Scope trigger position s.DppConfig.strTriggerPosition = strCmdData; strCmdData = GetCmdDataMS("SCOG",strRawCfgIn); // osc. Scope gain s.DppConfig.strScopeGain = strCmdData; strCmdData = GetCmdDataMS("MCAS",strRawCfgIn); // Acq Mode s.DppConfig.AcqMode = 0; s.DppConfig.strMcaMode = "MCA"; if (strCmdData == "NORM") { s.DppConfig.strMcaMode = "MCA"; } else if (strCmdData == "MCS") { s.DppConfig.strMcaMode = "MCS"; s.DppConfig.AcqMode = 1; } else if (strCmdData.GetLength() > 0) { s.DppConfig.strMcaMode = strCmdData; } s.DppConfig.UpdateScopeCfg = TRUE; } CString CvcDP5Dlg::GetCmdDataMS(CString strCmd, CString strCfgData) { int iStart,iEnd,iCmd; CString strCmdData; strCmdData = ""; if (strCfgData.GetLength() < 7) { return strCmdData; } // no data if (strCmd.GetLength() != 4) { return strCmdData; } // bad command iCmd = strCfgData.Find(strCmd+"=",0); if (iCmd == -1) { return strCmdData; } // cmd not found iStart = strCfgData.Find("=",iCmd); if (iStart == -1) { return strCmdData; } // data start not found iEnd = strCfgData.Find(";",iCmd); if (iEnd == -1) {return strCmdData; } // data end found if (iStart >= iEnd) { return strCmdData; } // data error strCmdData = strCfgData.Mid(iStart+1,(iEnd - (iStart+1))); //AfxMessageBox(strCmdData); return strCmdData; } 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; } CString CvcDP5Dlg::ReplaceCmdDescMS(CString strCmd, CString strCfgData) { int iStart,iCmd; //iEnd, CString strNew; CString strDesc; strNew = ""; if (strCfgData.GetLength() < 7) { return strCfgData; } // no data if (strCmd.GetLength() != 4) { return strCfgData; } // bad command iCmd = strCfgData.Find(strCmd+"=",0); if (iCmd == -1) { return strCfgData; } // cmd not found strDesc = GetCmdDescMS(strCmd); if (strDesc.GetLength() == 0) { return strCfgData; } // cmd desc not found iStart = 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.Left(iCmd-1) + strDesc + strCfgData.Mid(iStart); return strNew; } 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; } CString CvcDP5Dlg::GetCmdDescMS(CString strCmd) { CString 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; } 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(CString strCfg, CString strDesc) { CString 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, strConfig.GetLength()); HGLOBAL hMem = sf.Detach(); if (!hMem) return; SetClipboardData(CF_TEXT, hMem); CloseClipboard(); } void CvcDP5Dlg::OnBnClickedButtonShowConfig() { if (s.isDppConnected) { s.DppConfig.DisplayCfg = TRUE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); } } //------------------------------------------------------------------- // 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); s.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); s.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); s.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); s.isPlotLine = TRUE; } // SaveSpectrum(SPECTRUM, STATUS, CommonDialog1) void CvcDP5Dlg::OnBnClickedButtonSaveFile() { CFileBrowse BR; CString strDfltExt; string strSpectrum; // holds final spectrum file SpectrumFileType sfInfo; CString strFilename; s.DppConfig.CfgReadBack = TRUE; s.DppConfig.DisplayCfg = FALSE; SendCommandConfig(XMTPT_FULL_READ_CONFIG_PACKET); sfInfo.strSpectrumConfig = CreateSpectrumConfig(s.HwCfgDP5.GetString()); // 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 = s.DP5Stat.ShowStatusValueStrings(s.DP5Stat.m_DP5_Status); sfInfo.m_iNumChan = s.DP5Proto.SPECTRUM.CHANNELS; // number channels in spectrum sfInfo.SerialNumber = s.DP5Stat.m_DP5_Status.SerialNumber; // dpp serial number // create spectrum file, save file to string strSpectrum = CreateMCAData(s.DP5Proto.SPECTRUM.DATA,sfInfo,s.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 CString strCursorPos; strCursorPos.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; CString strCursorPos; if (pMsg->message == WM_KEYDOWN) { GetCursorPos(&pt); // Get the cursor position for a screen ScreenToClient(&pt); // Convert to window co-ordinates strCursorPos.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() { //BOOL isROI = FALSE; 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 (s.DP5Proto.SPECTRUM.CHANNELS < 256) { s.DP5Proto.SPECTRUM.CHANNELS = 1024; } double pixperchan = (double)s.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; } s.plot->m_xCursorData = (double)(CursorPosition.x - 14) * pixperchan; CString strChan; //strChan.Format("Channel %.2f",s.plot->m_xCursorData); int CurChan = (int)(s.plot->m_xCursorData + 0.5); if (CurChan > s.DP5Proto.SPECTRUM.CHANNELS - 1) { CurChan = s.DP5Proto.SPECTRUM.CHANNELS - 1; } CurrentChannel = CurChan; //if (s.m_Spectrum.m_roi.m_count > 0) { // isROI = TRUE //} strChan.Format("Channel %d",CurChan); GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strChan); } double CvcDP5Dlg::GetPixPerChannel() { CRect rect; m_PicturePlot.GetClientRect(&rect); int x_min = 0; int x_max = rect.Width(); if (s.DP5Proto.SPECTRUM.CHANNELS < 256) { s.DP5Proto.SPECTRUM.CHANNELS = 1024; } double pixperchan = (double)s.DP5Proto.SPECTRUM.CHANNELS / (double)x_max; return pixperchan; } void CvcDP5Dlg::OnBnClickedOk() { OnOK(); } void CvcDP5Dlg::OnBnClickedCancel() { OnCancel(); } void CvcDP5Dlg::OnBnClickedButtonClearRoi() { // TODO: Add your control notification handler code here } void CvcDP5Dlg::OnBnClickedButtonRoiEnd() { //CSelectDP5 dlgSelectDP5; //dlgSelectDP5.DoModal(); //CAboutDlg dlgAbout; //dlgAbout.DoModal(); } void CvcDP5Dlg::OnBnClickedButtonRoiStart() { // TODO: Add your control notification handler code here } //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 (! s.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; 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 s.DP5Stat.m_DP5_Status.AFAST_LOCKED = FALSE; // reset flag before call s.DppConfig.SetFastThreshDone = s.DP5Stat.m_DP5_Status.AFAST_LOCKED; //BOOL SendCommand(XMTPT_AUTOSET_FAST_THRESHOLD); // call tune fast thresh tmr.msTimer(50); MaxTime += GetCurrentTime(); // monitor flag until done or timeout while ((GetCurrentTime() < MaxTime) && (!s.DppConfig.SetFastThreshDone)) { tmr.msTimer(100); LoopCounter++; if (LoopCounter > 5) { LoopCounter = 0; SendCommand(XMTPT_SEND_STATUS); } } if (!s.DppConfig.SetFastThreshDone) { 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(s.hWnd_Main,WM_USER_READ_DPP_CONFIG,0L,0L); tmr.msTimer(200); tmr.msTimer(200); if (! s.DppConfig.isDeltaMode) { // check delta mode, if not in delta, set to delta WasInMCAMode = true; s.DppConfig.isDeltaMode = (! s.DppConfig.isDeltaMode); TuneSlowThresh.DelayTask(1000); // 1 second to convert to delta mode } mcaCh = (int)s.DP5Proto.SPECTRUM.CHANNELS; TuneSlowThresh.SetSlowThreshToChPos(0, mcaCh); // set slow thresh to 0 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, s.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(); CString strChan; strChan.Format("Channel %d",CurPos); //GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(strChan); GetDlgItem(IDC_EDIT_MISC_DATA)->SetWindowText(strChan); TuneSlowThresh.SetSlowThreshToChPos(SlowThreshCh, mcaCh); // set the calculated setting GlobalUnlock( hGlobal ); GlobalFree( hGlobal ); if (WasInMCAMode) { // set old delta mode, if in mca, set to delta to false s.DppConfig.isDeltaMode = false; } dlg.Close(); tmr.msTimer(200); OnBnClickedButtonClearDataAndGraph(); } void CvcDP5Dlg::OnBnClickedButtonAutotune() { 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; } ////////////////////////////////////////////////////////////////////// // 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; } ////////// SaveSpectrum(SPECTRUM, STATUS, CommonDialog1) ////////void CvcDP5Dlg::OnBnClickedButtonSaveFile() ////////{ //////// CFileBrowse BR; //////// CString strDfltExt; //////// CString strFilename; //////// CString strMCA; //////// //////// strMCA = CreateMCAData(s.DP5Proto.SPECTRUM.DATA, s.DP5Proto.SPECTRUM.CHANNELS, s.DP5Stat.m_DP5_Status); //get data //////// if (strMCA.GetLength() > 256) { //////// strDfltExt = _T("mca"); //////// if (BR.DoModal(BR.SAVE, //////// "Save Spectrum", //////// BR.McaFileFilter, //////// strDfltExt, //////// _T(""), //////// &strFilename)) { //////// SaveMCAFile(strFilename, strMCA); //////// } //////// } ////////} //////// ////////void CvcDP5Dlg::SaveMCAFile(CString strFilename, CString strMCA) ////////{ //////// CFile cf(strFilename, CFile::modeCreate | CFile::modeWrite); //////// cf.Write(strMCA, strMCA.GetLength()); //////// cf.Close(); ////////} //////// ////////CString CvcDP5Dlg::CreateMCAData(long m_larDataBuffer[], SHORT m_iNumChan, DP4_FORMAT_STATUS cfgStatusLst) ////////{ //////// CString strMCA; //////// CString strText; //////// CString strADC; //////// long idxChan; //////// CString strData; //////// unsigned long SerialNumber; //////// //////// if (cfgStatusLst.SerialNumber <= 0) //////// { //////// return (""); //////// } //////// strMCA = ""; //////// //SaveDPPStatus(cfgStatusLst); //display string for <> section' //////// //SaveDPPConfig(????); //////// switch(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"; //////// GetDlgItemText(IDC_EDIT_TAG, strText); //////// strMCA += "TAG - " + strText + "\r\n"; //////// GetDlgItemText(IDC_EDIT_DESCRIPTION, strText); //////// strMCA += "DESCRIPTION - " + strText + "\r\n"; //////// strMCA += "GAIN - " + strADC + "\r\n"; //////// strMCA += "THRESHOLD - 0\r\n"; //////// strMCA += "LIVE_MODE - 0\r\n"; //////// //strText.Format("%.1f", (m_cfgDPPSettings.PresetTime) / 10.0); //////// strText.Format("%s:%s", s.DppConfig.strPresetCmd,s.DppConfig.strPresetVal); //////// strMCA += "PRESET_TIME - " + strText + "\r\n"; //////// strText = ""; //////// strMCA += "LIVE_TIME - " + strText + "\r\n"; //////// strText.Format("%lf", cfgStatusLst.AccumulationTime); //////// strMCA += "REAL_TIME - " + strText + "\r\n"; //////// //GetDlgItemText(IDC_EDIT_START_TIME, strText); //////// strMCA += "START_TIME - " + strText + "\r\n"; //////// SerialNumber = (unsigned long)cfgStatusLst.SerialNumber; //////// strText.Format("%i", SerialNumber); //////// strMCA += "SERIAL_NUMBER - " + strText + "\r\n"; //////// strMCA += "<>\r\n"; //////// for (idxChan=0;idxChan