// 7200CwavDlg.cpp : implementation file // #include "stdafx.h" #include "math.h" #include "7200Cwav.h" #include "7200CwavDlg.h" #ifndef M_PI #define M_PI 3.14159265359 #endif #ifdef _DEBUG #define new DEBUG_NEW #endif CRect plotRect; I16 g_hCard; U32* g_pDIAddr; #ifdef _SELF_OUTPUT_ ULONG DoBuf[10240]; BOOLEAN bOutStopped; ULONG out_count; #endif void DI_DBCallBack() { I16 err; C7200CwavApp* pMyApp; C7200CwavDlg* pMyDlg; err =DI_AsyncDblBufferTransfer( g_hCard, g_pDIAddr ); pMyApp = (C7200CwavApp*)AfxGetApp(); pMyDlg = (C7200CwavDlg*)(pMyApp->m_pMainWnd); pMyDlg->redraw_display_area(); pMyDlg->display_buffer_data( g_pDIAddr ); } void DI_EndCallBack() { I16 err; U32 count; err = DI_AsyncClear(g_hCard, &count); #ifdef _SELF_OUTPUT_ err = DO_AsyncClear(g_hCard, &out_count); #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() // C7200CwavDlg dialog C7200CwavDlg::C7200CwavDlg(I16 hCard, CWnd* pParent /*=NULL*/) : CDialog(C7200CwavDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); g_hCard = hCard; OnBrush = OffBrush = NULL; n_PlotWidth = -1; n_PlotHeight = -1; min_val = 0x00; max_val = 0xFFFFFFFF; m_fSampleRate = 100000.0; // 100KHz m_dwDISamples = 40960; g_pDIAddr = NULL; #ifdef _SELF_OUTPUT_ for (int i=0; i<10240; i++) { DoBuf[i] = (U32)(sin((double)i/1024*M_PI)*0x7FFFFFFF)+0x80000000; } #endif } void C7200CwavDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(C7200CwavDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_DESTROY() // ON_WM_TIMER() ON_BN_CLICKED(IDC_BT_START, &C7200CwavDlg:: OnStart) ON_BN_CLICKED(IDC_BT_STOP, &C7200CwavDlg::OnStop) ON_WM_VSCROLL() END_MESSAGE_MAP() // C7200CwavDlg message handlers BOOL C7200CwavDlg::OnInitDialog() { 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) ); return TRUE; // return TRUE unless you set the focus to a control } void C7200CwavDlg::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 C7200CwavDlg::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 { redraw_display_area(); CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR C7200CwavDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void C7200CwavDlg::OnDestroy() { U32 count; CDialog::OnDestroy(); // TODO: Add your message handler code here if( OnBrush != NULL ) ::DeleteObject( OnBrush ); if( OffBrush != NULL ) ::DeleteObject( OffBrush ); RedPen.DeleteObject(); GreenPen.DeleteObject(); if( g_pDIAddr != NULL ) { free( g_pDIAddr ); g_pDIAddr = NULL; } DI_AsyncClear( g_hCard, &count ); DI_EventCallBack_x64( g_hCard, 0, DIEnd, (ULONG_PTR)DI_EndCallBack ); DI_EventCallBack_x64( g_hCard, 0, DBEvent, (ULONG_PTR)DI_DBCallBack ); #ifdef _SELF_OUTPUT_ DO_AsyncClear( g_hCard, &out_count ); #endif } void C7200CwavDlg:: OnStart() { // TODO: Add your control notification handler code here U32 dwMemSize, dwDISamples; void* pMem; I16 err; CString strMsg; dwDISamples = GetDlgItemInt( IDC_EDIT_SAMPLE ); if( dwDISamples != m_dwDISamples ) { if( g_pDIAddr != NULL ) { free( g_pDIAddr ); g_pDIAddr = NULL; } m_dwDISamples = dwDISamples; } dwMemSize = (m_dwDISamples * 2); // (m_dwDISamples * sizeof(U32)/2 ) pMem = malloc( dwMemSize ); if( pMem == NULL ) { AfxMessageBox( TEXT("Memory allocated failed") ); return; } else { g_pDIAddr = (U32*) pMem; memset( g_pDIAddr, '\0', dwMemSize ); } #ifdef _SELF_OUTPUT_ DO_7200_Config(g_hCard, TRIG_INT_PACER, OREQ_DISABLE, OTRIG_LOW); //DO_AsyncDblBufferMode(g_hCard, 0); #endif if ((err=DI_7200_Config(g_hCard, TRIG_INT_PACER, DI_NOWAITING, DI_TRIG_FALLING, IREQ_FALLING)) != NoError) { strMsg.Format( TEXT("DI_Config Error = %d"), err); AfxMessageBox( strMsg ); return; } if ((err=DI_AsyncDblBufferMode (g_hCard, 1)) != NoError) { strMsg.Format( TEXT("DI_AsyncDblBufferMode Error = %d"), err); AfxMessageBox( strMsg ); return; } #ifdef _SELF_OUTPUT_ DO_ContWritePort(g_hCard, 0, DoBuf, 10240, 0, m_fSampleRate, ASYNCH_OP); #endif DI_EventCallBack_x64 (g_hCard, 1, DIEnd, (ULONG_PTR) DI_EndCallBack ); DI_EventCallBack_x64 (g_hCard, 1, DBEvent, (ULONG_PTR) DI_DBCallBack ); if ((err=DI_ContReadPort(g_hCard, 0, pMem, m_dwDISamples, m_fSampleRate, ASYNCH_OP)) != NoError) { strMsg.Format( TEXT("DI_ContReadPort Error = %d"), err); AfxMessageBox( strMsg ); return; } GetDlgItem( IDC_BT_START )->EnableWindow( FALSE ); GetDlgItem( IDC_BT_STOP )->EnableWindow( TRUE ); } void C7200CwavDlg::OnStop() { // TODO: Add your control notification handler code here U32 count; DI_AsyncClear(g_hCard, &count); #ifdef _SELF_OUTPUT_ DO_AsyncClear(g_hCard, &out_count); #endif GetDlgItem( IDC_BT_START )->EnableWindow( TRUE ); GetDlgItem( IDC_BT_STOP )->EnableWindow( TRUE ); } void C7200CwavDlg::display_buffer_data(U32* pBuf) { CClientDC dc_plot(this); int nDraw_Bottom; int newY, oldY = -1; int newX, oldX = -1; U32 index, di_data; U32 dwDISamples = (m_dwDISamples/2); nDraw_Bottom = ( plotRect.bottom - 5 ); dc_plot.SelectObject( &GreenPen ); for( index=0; index 1000000.0 ) m_fSampleRate = 1000000.0; break; case SB_LINEDOWN: m_fSampleRate -= 50000; if (m_fSampleRate < 50000 ) m_fSampleRate = 50000; break; } SetDlgItemInt( IDC_EDIT_SAMPLE_RATE, (UINT)(m_fSampleRate/1000) ); CDialog::OnVScroll(nSBCode, nPos, pScrollBar); }