// 7300bWavDlg.cpp : implementation file // #include "stdafx.h" #include "7300bWav.h" #include "7300bWavDlg.h" #include "math.h" #ifndef M_PI #define M_PI 3.14159265359 #endif #define MAX_SIZE 1024000 //in words #ifdef _DEBUG #define new DEBUG_NEW #endif CRect plotRect; U16 out_buf[MAX_SIZE]; U16 in_buf[MAX_SIZE], in_buf2[MAX_SIZE], in_buf3[MAX_SIZE], in_buf4[MAX_SIZE]; I16 ghCard; U16 gViewIdx; BOOLEAN gHalfReady; U16 db_times = 0; void DI_DBCallBack() { BOOLEAN HalfReady=0; DI_AsyncMultiBufferNextReady(ghCard, &HalfReady, &gViewIdx); db_times = (db_times+1)%4; } void DI_CallBack() { U32 access_cnt; C7300bWavApp* pMyApp; C7300bWavDlg* pMyDlg; pMyApp = (C7300bWavApp*)AfxGetApp(); pMyDlg = (C7300bWavDlg*)(pMyApp->m_pMainWnd); pMyDlg->display_buffer_data(); DO_AsyncClear(ghCard, &access_cnt); pMyDlg->GetDlgItem(IDC_BT_START)->EnableWindow( TRUE ); pMyDlg->GetDlgItem( IDC_BT_STOP )->EnableWindow( FALSE); } // 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() // C7300bWavDlg dialog C7300bWavDlg::C7300bWavDlg(I16 hCard, CWnd* pParent /*=NULL*/) : CDialog(C7300bWavDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); ghCard = hCard; OnBrush = OffBrush = NULL; n_PlotWidth = -1; n_PlotHeight = -1; min_val = 0x00; max_val = 0x0000FFFF; m_fSampleRate = 10000.0; // 10KHz m_dwDISamples = 100000; } void C7300bWavDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(C7300bWavDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_DESTROY() ON_BN_CLICKED(IDC_BT_START, &C7300bWavDlg::OnStart) ON_BN_CLICKED(IDC_BT_STOP, &C7300bWavDlg::OnStop) // ON_WM_TIMER() ON_WM_VSCROLL() END_MESSAGE_MAP() // C7300bWavDlg message handlers BOOL C7300bWavDlg::OnInitDialog() { I16 err; int i; CString strTemp; CDialog::OnInitDialog(); // 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) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here x_divider = 5; y_divider = 2; OnBrush = CreateSolidBrush( RGB(255,0,0) ); OffBrush = CreateSolidBrush( RGB(125,0,0) ); RedPen.CreatePen( PS_SOLID, 1, RGB(255,0,0)); GreenPen.CreatePen( PS_SOLID, 1, RGB(0,255,0)); if( n_PlotWidth == -1 && n_PlotHeight == -1 ) { ((CWnd*)GetDlgItem(IDC_STATIC_DRAW))->GetWindowRect(&plotRect); ScreenToClient(&plotRect); n_PlotWidth = min( plotRect.Width(), 512); n_PlotHeight = plotRect.Height() - 10; } // set the default SampleRate SetDlgItemInt( IDC_EDIT_SAMPLE_RATE, (UINT)(m_fSampleRate/1000) ); // Set the default DI Sample SetDlgItemInt( IDC_EDIT_SAMPLE, (UINT)(m_dwDISamples) ); err = DI_7300B_Config(ghCard, 16, TRIG_CLK_10MHZ, P7300_WAIT_NO, P7300_TERM_ON, 0, 0, 0); if (err != 0) { strTemp.Format( TEXT("DI_7300B_Config Error = %d, card=%d"), err, ghCard); AfxMessageBox( strTemp ); return TRUE; } err = DO_7300B_Config (ghCard, 16, TRIG_INT_PACER, P7300_WAIT_NO, P7300_TERM_ON, 0, 0x00040004); if (err != 0) { strTemp.Format( TEXT("DO_7300B_Config Error = %d, card=%d"), err, ghCard); AfxMessageBox( strTemp ); return TRUE; } for (i=0; i(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 { redraw_display_area(); CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR C7300bWavDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void C7300bWavDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here if( OnBrush != NULL ) ::DeleteObject( OnBrush ); if( OffBrush != NULL ) ::DeleteObject( OffBrush ); RedPen.DeleteObject(); GreenPen.DeleteObject(); DI_ContMultiBufferReset( ghCard ); } void C7300bWavDlg::OnStart() { // TODO: Add your control notification handler code here U32 dwDISamples; U16 BufferId; I16 err; CString strMsg; dwDISamples = GetDlgItemInt( IDC_EDIT_SAMPLE ); if( (dwDISamples*2) > MAX_SIZE) { m_dwDISamples = (MAX_SIZE/2); AfxMessageBox(TEXT("This sample supports at most 512K words DMA transfer\nOnly perform 100K words DMA transfer.")); } else m_dwDISamples = dwDISamples; //setting the DMA buffers err = DI_ContMultiBufferSetup (ghCard, in_buf, m_dwDISamples, &BufferId); if (err < 0) { strMsg.Format(TEXT("DI_ContMultiBufferSetup Error = %d"), err); AfxMessageBox( strMsg ); return; } err = DI_ContMultiBufferSetup (ghCard, in_buf2, m_dwDISamples, &BufferId); if (err < 0) { strMsg.Format(TEXT("DI_ContMultiBufferSetup Error = %d"), err); AfxMessageBox( strMsg ); return; } err = DI_ContMultiBufferSetup (ghCard, in_buf3, m_dwDISamples, &BufferId); if (err < 0) { strMsg.Format(TEXT("DI_ContMultiBufferSetup Error = %d"), err); AfxMessageBox( strMsg ); return; } err = DI_ContMultiBufferSetup (ghCard, in_buf4, m_dwDISamples, &BufferId); if (err < 0) { strMsg.Format(TEXT("DI_ContMultiBufferSetup Error = %d"), err); AfxMessageBox( strMsg ); return; } DI_EventCallBack_x64 (ghCard, 1, DIEnd, (ULONG_PTR) DI_CallBack ); DI_EventCallBack_x64 (ghCard, 1, DBEvent, (ULONG_PTR) DI_DBCallBack ); db_times = 0; err = DO_ContWritePort (ghCard, 0, out_buf, 2*m_dwDISamples, 0, 5000000, ASYNCH_OP); if (err < 0) { strMsg.Format(TEXT("DO_ContWritePort Error = %d"), err); AfxMessageBox( strMsg ); return; } // start multi-buffered DI err = DI_ContMultiBufferStart (ghCard, 0, 1); if (err < 0) { strMsg.Format(TEXT("DI_ContMultiBufferStart Error = %d"), err); AfxMessageBox( strMsg ); return; } // clear display area redraw_display_area(); GetDlgItem( IDC_BT_START )->EnableWindow( FALSE ); GetDlgItem( IDC_BT_STOP )->EnableWindow( TRUE ); } void C7300bWavDlg::OnStop() { // TODO: Add your control notification handler code here U32 count; DI_AsyncClear(ghCard, &count); GetDlgItem( IDC_BT_START )->EnableWindow( TRUE ); GetDlgItem( IDC_BT_STOP )->EnableWindow( FALSE); } void C7300bWavDlg::display_buffer_data(void) { CClientDC dc_plot(this); int nDraw_Bottom, j; int newY, oldY = -1; int newX, oldX = -1; U32 index, di_data; nDraw_Bottom = ( plotRect.bottom - 5 ); dc_plot.SelectObject( &GreenPen ); for(j=0; j<4; j++) { for (index=0; index 200000.0 ) m_fSampleRate = 200000.0; break; case SB_LINEDOWN: m_fSampleRate -= 10000; if (m_fSampleRate < 10000.0 ) m_fSampleRate = 10000.0; break; } SetDlgItemInt( IDC_EDIT_SAMPLE_RATE, (UINT)(m_fSampleRate/1000) ); CDialog::OnVScroll(nSBCode, nPos, pScrollBar); }