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

📄 thermo.c

📁 测试传感器温度的控件...实在没什么可多介绍的了.VC
💻 C
📖 第 1 页 / 共 3 页
字号:
                            0, (LPARAM)((LPSTR)0));
                        for (i = 0; i < (int)DevFeatures.usNumGain; i ++)
                            SendDlgItemMessage(hDlg, IDC_INPRANGE, CB_ADDSTRING, 0,
                            (LPARAM)((LPSTR)(DevFeatures.glGainList[i].szGainStr)));

                        SendDlgItemMessage(hDlg, IDC_INPRANGE,
                            CB_SELECTSTRING, (WPARAM)(-1),
                            (LPARAM)((LPSTR)(DevFeatures.glGainList[gwGain].szGainStr)));
                    }
                    else
                    {
                        EnableWindow(GetDlgItem(hDlg, IDC_INPRANGE), FALSE);
                        SendDlgItemMessage(hDlg, IDC_INPRANGE, CB_RESETCONTENT,
                            0, (LPARAM)((LPSTR)0));
                    }

                    // fourth: close device

                    DRV_DeviceClose((LONG far *)&DriverHandle);
                }

                return TRUE;
         }
         break;
    }
    return FALSE ;
}


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

    PURPOSE:  Processes dialog box messages for scan time settings
****************************************************************************/

BOOL FTYPE ScanDlgProc
(
    HWND        hDlg,                          // window handle
    unsigned    message,                       // type of message
    WPARAM      wParam,                        // additional information
    LPARAM      lParam                         // additional information
)
{
    char        szBuffer[40];

    switch (message)
    {
    case WM_INITDIALOG :

        // ---------------------------------------------------
        // Initialize Scan Time Edit, Maximum accuracy: 40 ms
        // ---------------------------------------------------

        itoa(gwScanTime, szBuffer, 10);
        SendDlgItemMessage(hDlg, IDC_SCAN, EM_REPLACESEL, 0,
                        (LPARAM)((LPSTR)szBuffer));

        return TRUE;

    case WM_COMMAND :

         switch (LOWORD(wParam))
         {
            case IDOK :

                //
                // get scan time
                //

                if (SendDlgItemMessage(hDlg, IDC_SCAN,
                           EM_GETMODIFY, 0, 0))
                {
                    SendDlgItemMessage(hDlg, IDC_SCAN,
                            WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
                    gwScanTime = atoi(szBuffer);
                    SendDlgItemMessage(hDlg, IDC_SCAN,
                              EM_SETMODIFY, FALSE, 0) ;
                }

            case IDCANCEL :
                EndDialog(hDlg, 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        hWnd,                          // window handle
    unsigned    message,                       // type of message
    WPARAM      wParam,                        // additional information
    LPARAM      lParam                         // additional information
)
{
    static  HANDLE  hInstance ;
    HMENU           hMenu;
    HDC             hdc;
    char            szBuffer[120];
    RECT            rect;
    DWORD           dwCurrentTime;
    DWORD           dwErrorTime;
    BOOL            bTimerOverrun;
    float           fTemp;

    switch (message)
    {
        case WM_CREATE:

            //
            // initialize Stop Menu
            //

            hMenu = GetMenu(hWnd);
            EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED);

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

            lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;

            lpfnScanDlgProc = MakeProcInstance (ScanDlgProc, hInstance) ;

            return 0 ;

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

            hMenu = GetMenu(hWnd);

            switch (LOWORD(wParam))
            {
                case IDM_SETTING :
                    DialogBox (hInstance, MAKEINTRESOURCE(IDD_SETTING),
                         hWnd, lpfnConfigDlgProc) ;
                    return 0;

                case IDM_SCAN :
                    DialogBox (hInstance, MAKEINTRESOURCE(IDD_SCAN),
                         hWnd, lpfnScanDlgProc) ;
                    return 0;

                case IDM_STOP :

                    //
                    // kill timer and close driver
                    //

                    KillTimer(hWnd, 1);
                    DRV_DeviceClose((LONG far *)&DriverHandle);

                    bRun = FALSE;

                    //
                    // reset menu item status
                    //

                    EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED);
                    EnableMenuItem(hMenu, IDM_START, MF_BYCOMMAND | MF_ENABLED);

                    return 0;

                case IDM_START :

                    //
                    // Open Device
                    //

                    if (gnNumOfSubdevices == 0)
                        ErrCde = DRV_DeviceOpen(
                            DeviceList[gwDevice].dwDeviceNum,
                                (LONG far *)&DriverHandle);
                    else
                        ErrCde = DRV_DeviceOpen(
                            SubDeviceList[gwSubDevice].dwDeviceNum,
                                (LONG far *)&DriverHandle);

                    if (ErrCde != SUCCESS)
                    {
                        strcpy(szErrMsg,"Device open error !");
                        MessageBox(hWnd,(LPCSTR)szErrMsg,"Device Open",MB_OK);
                        return 0;
                    }

                    //
                    // get gain code
                    //

                    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;
                    }

                    //
                    // configures the gain for the specifed analog input channel
                    //

                    gwDasGain = DevFeatures.glGainList[gwGain].usGainCde;
                    gwTempScale = uScaleValue[gwScale];
                    gwTcType = uTypeValue[gwType];

                    //
                    // enable Stop Menu item and disable the others
                    //

                    EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_ENABLED);
                    EnableMenuItem(hMenu, IDM_START, MF_BYCOMMAND | MF_GRAYED);

                    //
                    // Set the new timer type and start it up.
                    //

                    if (SetTimer(hWnd, 1, gwScanTime, NULL) == (UINT)NULL)
                    {
                        MessageBox(hWnd, "Couldn't create timer.", "Notice!",
                            MB_OK);
                        DRV_DeviceClose((LONG far *)&DriverHandle);
                        return 0;
                    }

                    bRun = TRUE;

                    gdwStartTime = GetTickCount();
                    gwOverrunCount = 0;

                    return 0;

            }
            return 0;

        case WM_TIMER:

            //
            // Timer set to dispatch a WM_TIMER message has gone off.
            //

            //
            // check if timer is overrun
            //
            dwCurrentTime = GetTickCount();

            gdwElapseTime = gdwElapseTime + (DWORD)gwScanTime;
            dwErrorTime = dwCurrentTime - gdwElapseTime - gdwStartTime;
            if (dwErrorTime > (DWORD)40)        // maximum 40 ms scan time
            {
                gdwElapseTime = dwCurrentTime - gdwStartTime;
                gwOverrunCount ++;
                if (gwOverrunCount >= 10)
                {
                    bTimerOverrun = TRUE;
                    gwOverrunCount = 0;
                }
                else
                    bTimerOverrun = FALSE;
            }
            else
            {
                bTimerOverrun = FALSE;
                gwOverrunCount = 0;
            }


            //
            // measure the temperature
            //

            ptTCMuxRead.DasChan = gwDasChl;
            ptTCMuxRead.DasGain = gwDasGain;
            ptTCMuxRead.ExpChan = gwExpChl;
            ptTCMuxRead.TCType = gwTcType;
            ptTCMuxRead.TempScale = gwTempScale;
            ptTCMuxRead.temp = (FLOAT far *)&fTemp;

            if ((ErrCde = DRV_TCMuxRead(DriverHandle,
                   (LPT_TCMuxRead)&ptTCMuxRead)) != 0)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                KillTimer(hWnd, 1);
                MessageBox(hWnd,(LPCSTR)szErrMsg, "Driver Message", MB_OK);
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return TRUE;
            }


            //
            // Display Data
            //

            hdc = GetDC(hWnd);
            GetClientRect(hWnd, &rect);
            InvalidateRect(hWnd, NULL, TRUE);
            UpdateWindow(hWnd);
            if (bTimerOverrun == FALSE)
                sprintf(szBuffer, "Temperature = %6.2f", fTemp);
            else
                sprintf(szBuffer, "Timer Overrun!");
            DrawText(hdc, szBuffer, -1, &rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER);
            ReleaseDC(hWnd, hdc);

          	return 0;

        case WM_DESTROY:
            if (bRun == TRUE)
            {
                KillTimer(hWnd, 1);
                DRV_DeviceClose((LONG far *)&DriverHandle);
            }
            PostQuitMessage(0);
            break;

      default:
           return (DefWindowProc(hWnd, message, wParam, lParam));
   }

   return ((LONG)NULL);
}

⌨️ 快捷键说明

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