⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addmabm.c

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 C
📖 第 1 页 / 共 5 页
字号:
			SetWindowText(GetDlgItem(hDlg,IDC_TO),(LPCTSTR)szBuffer);

			for(i = lStartDisplay; i <= lEndDisplay; ++i)
			{

				if (gwDataType == 0)
					sprintf(szBuffer, "Buf[%ld] = %4x",i, ((USHORT far *)temp)[i]);
				else
					sprintf(szBuffer, "Buf[%ld] = %10.6f", i, ((FLOAT far *)temp)[i]);

				if(SendDlgItemMessage(hDlg, IDC_DATALIST, LB_ADDSTRING, 0,
					(LPARAM)(LPSTR)szBuffer) == LB_ERRSPACE)
				{   MessageBox(hWnd,(LPCSTR)"Not Enough Memory",
						"Display Data",MB_OK);
                return TRUE;
				}
			}
			EnableWindow(GetDlgItem(hDlg,IDC_BACKWARD), TRUE);
			EnableWindow(GetDlgItem(hDlg,IDC_BACKBUTTON), TRUE);
			EnableWindow(GetDlgItem(hDlg,IDC_FORWARD), FALSE);
			EnableWindow(GetDlgItem(hDlg,IDC_FORWARDBUTTON), FALSE);

			hCursor = LoadCursor(NULL, IDC_ARROW);
			SetCursor(hCursor);
			break;
			}

        case IDC_UPDATE :
			 break;

        case IDOK :
        case IDCANCEL :
            EndDialog(hDlg, 0);
            return TRUE;

        }
        break;
    }
    return FALSE ;
}

/******************************************************************************
    FUNCTION: DisplayDlgProc(HWND, unsigned, WPARAM, LPARAM)

    PURPOSE:  Processes dialog box messages for display range
******************************************************************************/

BOOL FTYPE DisplayDlgProc(hDlg, message, wParam, lParam)
HWND hDlg;                               /* window handle                   */
unsigned message;                        /* type of message                 */
WPARAM wParam;                           /* additional information          */
LPARAM lParam;                           /* additional information          */
{

    switch (message)
    {
    case WM_INITDIALOG :

        // Initialize Start Point
        ultoa(gdwStartPt, szBuffer, 10);

        SendDlgItemMessage(hDlg, IDC_ESTAPT, EM_REPLACESEL, 0,
            (LPARAM)((LPSTR)szBuffer));

        // Initialize Stop Point
        ultoa(gdwStopPt, szBuffer, 10);

        SendDlgItemMessage(hDlg, IDC_ESTOPT, EM_REPLACESEL, 0,
            (LPARAM)((LPSTR)szBuffer));

        return TRUE;

    case WM_COMMAND :
        switch (LOWORD(wParam))
        {
        case IDOK :
        case IDCANCEL :
            EndDialog(hDlg, 0);
            return TRUE;

        case IDC_ESTAPT :

            if (HIWORD(wParam) == EN_KILLFOCUS)
            {
                if(SendDlgItemMessage(hDlg, IDC_ESTAPT,
                    EM_GETMODIFY, 0, 0))
                {
                    SendDlgItemMessage(hDlg, IDC_ESTAPT,
                        WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
                    gdwStartPt = (USHORT)atoi(szBuffer);
                    SendDlgItemMessage(hDlg, IDC_ESTAPT,
                        EM_SETMODIFY, FALSE, 0) ;
                }
            }
            return TRUE;

        case IDC_ESTOPT :
            if (HIWORD(wParam) == EN_KILLFOCUS)
            {
                if(SendDlgItemMessage(hDlg, IDC_ESTOPT,
                    EM_GETMODIFY, 0, 0))
                {
                    SendDlgItemMessage(hDlg, IDC_ESTOPT,
                        WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
                    gdwStopPt = atol(szBuffer);
                    SendDlgItemMessage(hDlg, IDC_ESTOPT,
                        EM_SETMODIFY, FALSE, 0) ;
                }
            }
            return TRUE;
        }
        break;
    }
    return FALSE ;
}

/******************************************************************************
    FUNCTION: MainWndProc(HWND, unsigned, WPARAM, LPARAM)

    PURPOSE:  Processes messages

    MESSAGES:

        WM_CREATE     - create window
        WM_COMMAND    - application menu (About dialog box)
        WM_DESTROY    - destroy window
******************************************************************************/

long FTYPE MainWndProc(hWnd, message, wParam, lParam)
HWND     hWnd;                            /* window handle                   */
unsigned message;                         /* type of message                 */
WPARAM   wParam;                          /* additional information          */
LPARAM   lParam;                          /* additional information          */
{
    int     dec, sign, i;
    TEXTMETRIC tm;
    HDC     hdc;
    static  int cxChar, cyChar;
    char    *szStr, szDest[100], szTemp[50];
    double  ratio;
    USHORT  temp;
	DWORD   dwExitCode;
	int LogChan;

    switch (message)
    {
    case WM_CREATE:

        hMenu = GetMenu(hWnd);

        hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;

        lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;

        lpfnShowDataDlgProc = MakeProcInstance (ShowDataDlgProc, hInstance) ;

        lpfnDisplayDlgProc = MakeProcInstance (DisplayDlgProc, hInstance) ;

        lpfnGainListDlgProc = MakeProcInstance (GainListDlgProc, hInstance) ;

        hdc = GetDC(hWnd);
        SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
        GetTextMetrics(hdc, &tm);
        cxChar = tm.tmAveCharWidth;
        cyChar = tm.tmHeight + tm.tmExternalLeading;
        ReleaseDC(hWnd, hdc);

        //Create stop button and status button
        hwndStopButton = CreateWindow("button", "Stop",
            (DWORD)(WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON),
            0, 0, 8*cxChar, 3*cyChar/2, hWnd,
            (HMENU)IDC_STOPBUTTON,
            (HANDLE)hInstance, (LPVOID)NULL);

        hwndStatusButton = CreateWindow("button", "Status",
            (DWORD)(WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON),
            8*cxChar, 0, 8*cxChar, 3*cyChar/2, hWnd,
            (HMENU)IDC_STATUSBUTTON,
            (HANDLE)hInstance, (LPVOID)NULL);

        EnableWindow(hwndStopButton, FALSE);
        EnableWindow(hwndStatusButton, FALSE);

        return 0 ;

    case WM_COMMAND:     /* message: from application menu */

        hMenu = GetMenu(hWnd);

        switch(LOWORD(wParam))
        {
            // Show the dialog box of the input parameter
        case IDM_SETTING :

            DialogBox (hInstance, MAKEINTRESOURCE(IDD_SETTING),
                hWnd, lpfnConfigDlgProc) ;
            return 0;

            // Show the dialog box for the range of data to display
        case IDM_DISPLAY:

            DialogBox (hInstance, MAKEINTRESOURCE(IDD_DISPLAY),
                hWnd, lpfnDisplayDlgProc) ;

            return 0;

        case IDM_RUN :

            // Step 1: Device open
            ErrCde = DRV_DeviceOpen(dwDeviceNum, (LONG far *)&DriverHandle);
            if (ErrCde != SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hWnd,(LPCSTR)szErrMsg,"Device Open",MB_OK);
                return 0;
            }

            // Step 2: Get device features
            ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
            ptDevFeatures.size = sizeof(DEVFEATURES);
            if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
                (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return 0;
            }

            // Step 3: Allocate memory for Voltage data or Raw data
            //********Version 2.0B*******************
            //  As with DMA transfers, it's better to start the buffer at
            //  page boundary(4096 Bytes). If the buffers used for the 
            //  DMA operation is aligned on addresses of page boundary, user 
            //  can get exact page change event(just set the Count of 
            //  PT_EnableEvent to 2048, it means 1 page). Once Interrupt
            //  event occurs, it means 2048 samples(4096 byes) are available.
            //  
            //  It is why we changed the memory allocation policy from
            //  Solution A to solution B at Version 2.0B.
            //
            //  At the same time, the buffer that receives the samples must
            //  be a multiple of 4096 bypes(2048 samples). In cycle mode, if
            //  you are interested in buffer change event, the minimal buffer
            //  is 8192 bytes(4096 samples).
            //****************************************
           
            // Solution A:
            if((hUserBuf=(FLOAT far *)GlobalAlloc(GHND,
                sizeof(FLOAT) * gulConvNum)) == 0)
            {
                MessageBox(hWnd,"Not enough memory for buffer ",
                    "High Speed",MB_OK);
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return 0;
            }
            /*
            // Solution B:
            // Win9x seems don't support the routine well.
            // so it's recommended only to use it at WinNT/2K.
            hUserBuf = VirtualAlloc( NULL,                    // region to reserve or commit
                                     2 * gulConvNum,          // size of region
                                     MEM_COMMIT|MEM_RESERVE,  // type of allocation
                                     PAGE_READWRITE );        // type of access protection
            */
            if ( NULL==hUserBuf )                       
            {
                MessageBox( hWnd, "Not enough memory for buffer", "High Speed",MB_OK );
                DRV_DeviceClose((LONG *)&DriverHandle);
                return 0;
            }
            // End of solution B.

            if((hDisplayBuf=(FLOAT far *)GlobalAlloc(GHND,
                sizeof(FLOAT) * gulConvNum)) == 0)
            {
                MessageBox(hWnd,"Not enough memory for buffer ", "High Speed",MB_OK);
                VirtualFree(
                            hUserBuf,                   // base address of block
                            2 * gulConvNum,             // bytes of committed pages
                            MEM_DECOMMIT| MEM_RELEASE); // decommit the pages
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return 0;
            }
            ptFAITransfer.DataBuffer = (FLOAT far  *)GlobalLock(hDisplayBuf);           
          
            // Step 4: Enable event feature
            ptEnableEvent.EventType = 0;
            if( bBufferChange )
            {
                ptEnableEvent.EventType |= ADS_EVT_BUFCHANGE;
            }
            if( bTerminate )
            {
                ptEnableEvent.EventType |= ADS_EVT_TERMINATED;
            }
            if( bOverrun )
            {
                ptEnableEvent.EventType |= ADS_EVT_OVERRUN;
            }
            if( bInterrupt )
            {
                ptEnableEvent.EventType |= ADS_EVT_INTERRUPT;
            }
           
            ptEnableEvent.Enabled = gwEvtFlag;
            ptEnableEvent.Count   = (USHORT)(gulEventCount * 2048);

            if ((ErrCde = DRV_EnableEvent(DriverHandle,
                (LPT_EnableEvent)&ptEnableEvent)) != 0)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                VirtualFree(
                            hUserBuf,                  
                            2 * gulConvNum,             
                            MEM_DECOMMIT| MEM_RELEASE); 
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return 0;
            }

            for (i=0 ; i < MAX_CHANNELS ; i++)        
            {
                if (!gwGainList)
                {
                    gwGainCde[i] = DevFeatures.glGainList[gwGainCode].usGainCde;
                }
                else
                {
                    temp = gwGain[i];
                    gwGainCde[i] = DevFeatures.glGainList[temp].usGainCde;
                }
            }

			gwMaxLogChanNum = GetMaxLogChanNum(&Devconfig_AI,&DevFeatures);
			LogChan = PhyChanToLogChan(&Devconfig_AI,gwStartChl);
            for(i=0; i<min(gwNumChl,gwMaxLogChanNum);i++,LogChan++)
            {
				ReorderGainCode[i] =  gwGainCde[LogChan % gwMaxLogChanNum];
            }

            // Step 5: Start DMA transfer
            ptFAIDmaExStart.TrigSrc			= gwExtTrig;
            ptFAIDmaExStart.TrigMode		= gwTrigMode;
            ptFAIDmaExStart.ClockSrc		= gwClockSrc;
            ptFAIDmaExStart.TrigEdge		= gwTrigEdge;
            ptFAIDmaExStart.SRCType			= gwSRCType;
            ptFAIDmaExStart.CyclicMode		= gwCyclicMode;
            ptFAIDmaExStart.TrigVol			= gwTrigVol;
            ptFAIDmaExStart.StartChan		= gwStartChl;
            ptFAIDmaExStart.NumChans		= min(gwNumChl,gwMaxLogChanNum);
            ptFAIDmaExStart.ulDelayCnt		= gwDelayCnt;
            ptFAIDmaExStart.SampleRate		= gdwPacerRate;
            ptFAIDmaExStart.GainList		= &ReorderGainCode[0];           
            ptFAIDmaExStart.count			= gulConvNum;
            ptFAIDmaExStart.buffer0			= (USHORT *)hUserBuf;

            if ((ErrCde = DRV_FAIDmaExStart(DriverHandle,
                (LPT_FAIDmaExStart)&ptFAIDmaExStart)) != 0)
         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -