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

📄 adexp.c

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 C
📖 第 1 页 / 共 4 页
字号:
            // initialize the Module List Combobox with the retrieved
            // information

            EnableWindow(GetDlgItem(hDlg, IDC_MODULE), TRUE);
            SendDlgItemMessage(hDlg, IDC_MODULE, CB_RESETCONTENT, 0,
                    (LPARAM)((LPSTR)0));

            for (i = 0; i < gnNumOfSubdevices; i++)
                SendDlgItemMessage(hDlg, IDC_MODULE, CB_ADDSTRING, 0,
                        (LPARAM)((LPSTR)SubDeviceList[i].szDeviceName));

            SendDlgItemMessage(hDlg, IDC_MODULE, CB_SETCURSEL,
					(WPARAM)gwSubDevice, (LPARAM)0);
        }
        else
        {
            EnableWindow(GetDlgItem(hDlg, IDC_MODULE), FALSE);
            SendDlgItemMessage(hDlg, IDC_MODULE, CB_RESETCONTENT, 0,
                    (LPARAM)((LPSTR)0));
        }

        // ------------------------------------------------------------
        // Initialize Input Range List Combobox, it needs to get device
        // features for gain list
        // ------------------------------------------------------------

        // first : 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(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
            return 0;
        }

        // second: 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(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
            DRV_DeviceClose((LONG far *)&DriverHandle);
            return 0;
        }

        // Have AI function support ?
        if ((DevFeatures.usMaxAIDiffChl   == 0) &&
            (DevFeatures.usMaxAISiglChl == 0))
        {
            EnableWindow(GetDlgItem(hDlg, IDC_ECHANNEL), FALSE);
            SendDlgItemMessage(hDlg, IDC_ECHANNEL, CB_RESETCONTENT,
                0, (LPARAM)((LPSTR)0));
            EnableWindow(GetDlgItem(hDlg, IDC_EXPCHAN), FALSE);
            SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_RESETCONTENT,
                0, (LPARAM)((LPSTR)0));
            EnableWindow(GetDlgItem(hDlg, IDC_BOARDID), FALSE);
            SendDlgItemMessage(hDlg, IDC_BOARDID, CB_RESETCONTENT,
                0, (LPARAM)((LPSTR)0));
        }
        else
        {
            ptAIGetConfig.buffer = (LPDEVCONFIG_AI)&DevCfg;
            ptAIGetConfig.size = sizeof(DEVCONFIG_AI);

            // call AIGetConfig
            if ((ErrCde = DRV_AIGetConfig(DriverHandle,
                (LPT_AIGetConfig)&ptAIGetConfig)) != SUCCESS)
            {
                DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                MessageBox(hMainWnd,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                DRV_DeviceClose((LONG far *)&DriverHandle);
                return 0;
            }

            usMaxChannel = DevFeatures.usMaxAISiglChl;

            EnableWindow(GetDlgItem(hDlg, IDC_ECHANNEL), TRUE);
            EnableWindow(GetDlgItem(hDlg, IDC_EXPCHAN), TRUE);
            SendDlgItemMessage(hDlg, IDC_ECHANNEL, CB_RESETCONTENT, 0, 0L);
            SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_RESETCONTENT, 0, 0L);

            // setting dialog box for channel setting
            // fill in the channel listbox with the available channel
            // in the AI subsection (start with channel 0)
            for (i=0; i< (int)usMaxChannel; ++i)
            {
                wsprintf(szBuf, "%d", i);
                if (i == (int)DevCfg.usCjcChannel) // CJC channel
                {
                    lstrcat(szBuf, " (CJC Channel)");
                }
                else if (DevCfg.Daughter[i&0xf].dwBoardID!=0L)// exp. board exist
                {
                    lstrcat(szBuf, " (");
                    DRV_BoardTypeMapBoardName(DevCfg.Daughter[i&0xf].dwBoardID,
                                              (LPSTR)szExpName);
                    lstrcat(szBuf, szExpName);
                    lstrcat(szBuf, ")");
                }
                SendDlgItemMessage(hDlg, IDC_ECHANNEL, CB_ADDSTRING,(WPARAM) -1,
                    (LPARAM)(LPSTR)szBuf);
            }
            // initialize input channel
            SendDlgItemMessage(hDlg, IDC_ECHANNEL, CB_SETCURSEL, gwChannel,0L);

            // if the selected channel is associated with an expansion board,
            // fill in the Exp. channel listbox with the available expansion board
            // channel.
            if (DevCfg.usNumExpChan > 0 && DevCfg.Daughter[gwChannel&0xf].dwBoardID
                && (int)gwChannel != (int)DevCfg.usCjcChannel &&
                DevCfg.Daughter[gwChannel&0xf].dwBoardID != (DWORD)BD_PCLD8115
				&&DevCfg.Daughter[gwChannel&0xf].dwBoardID != (DWORD)BD_PCLD8710)//mining add
			{
                EnableWindow(GetDlgItem(hDlg, IDC_EXPCHAN), TRUE);

                for (i=0; i<(int)DevCfg.Daughter[gwChannel&0xf].usNum; ++i)
				{
					wsprintf(szBuf, "%d", i);
                    SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_ADDSTRING,(WPARAM)-1,
						(LPARAM)(LPSTR)szBuf);
				}

                SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_SETCURSEL,
                    usExpChan,0L);
			}
			else
			{
                usExpChan = 0;
                EnableWindow(GetDlgItem(hDlg, IDC_EXPCHAN), FALSE);
                SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_RESETCONTENT, 0, 0L);
			}

            if (DevCfg.Daughter[gwChannel&0xf].dwBoardID == (DWORD)BD_PCLD788)
            {
                EnableWindow(GetDlgItem(hDlg, IDC_BOARDID), TRUE);

                for (i=0; i<(int)DevCfg.Daughter[gwChannel&0xf].usCards; ++i)
                {
                    wsprintf(szBuf, "%d", i);
                    SendDlgItemMessage(hDlg, IDC_BOARDID, CB_ADDSTRING, (WPARAM)-1,
                        (LPARAM)(LPSTR)szBuf);
                }
                SendDlgItemMessage(hDlg, IDC_BOARDID, CB_SETCURSEL,
                    usBoardID,0L);
            }
            else
            {
                usBoardID = 0;
                EnableWindow(GetDlgItem(hDlg,IDC_BOARDID),FALSE);
                SendDlgItemMessage(hDlg, IDC_BOARDID, CB_RESETCONTENT, 0, 0L);
            }

            // third: initialize Input Range List Combobox with device features
            if ((DevFeatures.usNumGain != 0) &&
                (DevCfg.Daughter[gwChannel&0xf].dwBoardID == 0) &&
                (DevCfg.usCjcChannel != gwChannel))
            {
                EnableWindow(GetDlgItem(hDlg, IDC_INPRANGE), TRUE);
                SendDlgItemMessage(hDlg, IDC_INPRANGE, CB_RESETCONTENT,
                    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
            {
                gwGain = 0;
                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;

    case WM_COMMAND :
         switch (LOWORD(wParam))
         {
            case IDOK :

              //
              // get device selection
              //

              if ((dwIndex = SendDlgItemMessage(hDlg, IDC_DEVICE,
                           CB_GETCURSEL, 0, 0)) != CB_ERR)
                   gwDevice = (WORD)dwIndex;


              //
              // get sub-device selection
              //

              if ((dwIndex = SendDlgItemMessage(hDlg, IDC_MODULE,
                           CB_GETCURSEL, 0, 0)) != CB_ERR)
                   gwSubDevice = (WORD)dwIndex;


              //
              // get channel number
              //
              if ((dwIndex = SendDlgItemMessage(hDlg, IDC_ECHANNEL,
                           CB_GETCURSEL, 0, 0)) != CB_ERR)
                   gwChannel = (WORD)dwIndex;
              //
              // get input range selection
              //

              if ((dwIndex = SendDlgItemMessage(hDlg, IDC_INPRANGE,
                           CB_GETCURSEL, 0, 0)) != CB_ERR)
                   gwGain = (WORD)dwIndex;

              //
              // get expansion channel number
              //
              if ((dwIndex = SendDlgItemMessage(hDlg, IDC_EXPCHAN,
                           CB_GETCURSEL, 0, 0)) != CB_ERR)
                   usExpChan = (WORD)dwIndex;

              //
              // get board id for PCLD-788
              //
              if ((dwIndex = SendDlgItemMessage(hDlg, IDC_BOARDID,
                           CB_GETCURSEL, 0, 0)) != CB_ERR)
                   usBoardID = (WORD)dwIndex;

              EndDialog(hDlg, 0);
              return TRUE;


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

            case IDC_ECHANNEL :

                //
                // When device selection is changed, it needs to
                // re-initialize sub-device combobox and input range
                // combobox.
                //

                if (HIWORD(wParam) == CBN_SELCHANGE)
                {
                  gwChannel = 0;
                  gwGain = 0;
                  usExpChan = 0;
                  usBoardID = 0;

                  if ((dwIndex = SendDlgItemMessage(hDlg, IDC_ECHANNEL,
                               CB_GETCURSEL, 0, 0)) != CB_ERR)
                       gwChannel = (WORD)dwIndex;

                  // if the selected channel is associated with an expansion board,
                  // fill in the Exp. channel listbox with the available expansion board
                  // channel.
                  if (DevCfg.usNumExpChan > 0 && DevCfg.Daughter[gwChannel&0xf].dwBoardID
                      && (int)gwChannel != (int)DevCfg.usCjcChannel &&
                      DevCfg.Daughter[gwChannel&0xf].dwBoardID != (DWORD)BD_PCLD8115
					  &&DevCfg.Daughter[gwChannel&0xf].dwBoardID != (DWORD)BD_PCLD8710)//mining add
                  {
                      EnableWindow(GetDlgItem(hDlg, IDC_EXPCHAN), TRUE);
                      for (i=0; i<(int)DevCfg.Daughter[gwChannel&0xf].usNum; ++i)
                      {
                          wsprintf(szBuf, "%d", i);
                          SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_ADDSTRING,(WPARAM)-1,
                              (LPARAM)(LPSTR)szBuf);
                      }

                      SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_SETCURSEL,
                          usExpChan,0L);
                  }
                  else
                  {
                      EnableWindow(GetDlgItem(hDlg, IDC_EXPCHAN), FALSE);
                      SendDlgItemMessage(hDlg, IDC_EXPCHAN, CB_RESETCONTENT, 0, 0L);
                  }

                  if (DevCfg.Daughter[gwChannel&0xf].dwBoardID == (DWORD)BD_PCLD788)
                  {
                      EnableWindow(GetDlgItem(hDlg, IDC_BOARDID), TRUE);
                      for (i=0; i<(int)DevCfg.Daughter[gwChannel&0xf].usCards; ++i)
                      {
                          wsprintf(szBuf, "%d", i);
                          SendDlgItemMessage(hDlg, IDC_BOARDID, CB_ADDSTRING, (WPARAM)-1,
                              (LPARAM)(LPSTR)szBuf);
                      }
                      SendDlgItemMessage(hDlg, IDC_BOARDID, CB_SETCURSEL,
                          usBoardID,0L);
                  }
                  else
                  {
                      EnableWindow(GetDlgItem(hDlg,IDC_BOARDID),FALSE);
                      SendDlgItemMessage(hDlg, IDC_BOARDID, CB_RESETCONTENT, 0, 0L);

⌨️ 快捷键说明

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