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

📄 pulsepwm.c

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 C
📖 第 1 页 / 共 3 页
字号:
        // 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(hDlg,(LPCSTR)szErrMsg,"Device Open",MB_OK);
           return 0;
        }
        
        
        //
        // get number of counter channels
        //
        
        ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
        ptDevFeatures.size = sizeof(DEVFEATURES);
        if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
           (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
        {
           DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
           MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
           DRV_DeviceClose((LONG far *)&DriverHandle);
           return 0;
        }

        dwBordID = DevFeatures.dwBoardID;
        usMaxCntChan = DevFeatures.usMaxTimerChl;
        DRV_DeviceClose(&DriverHandle);
        //
        // Initialize Input Channel Edit
        //
      
		 for ( i = 0; i< usMaxCntChan; i++ )
		 {
         _itoa( i, tmp, 10 );
         SendDlgItemMessage( 
		   hDlg, 
		   IDC_CFGCNT,
		   CB_ADDSTRING, 
		   0, 
		  ( LPARAM )( ( LPSTR )tmp ) );
		 }
		 
		 SendDlgItemMessage(hDlg, IDC_CFGCNT, CB_SETCURSEL, gwChannel,0 );

		  sprintf(szBuffer,"%5.6f",gfGatePeriod);
        SendDlgItemMessage(hDlg, IDC_GATEPERIOD0, EM_REPLACESEL, 0,
                              (LPARAM)((LPSTR)szBuffer));
		  sprintf(szBuffer,"%5.6f",gfUpCycle);
        SendDlgItemMessage(hDlg, IDC_UPCYCLE0, EM_REPLACESEL, 0,
                              (LPARAM)((LPSTR)szBuffer));
		sprintf(szBuffer,"%d",	 gusOutCount);
		SendDlgItemMessage(hDlg,IDC_OUTCOUNT,EM_REPLACESEL,0,(LPARAM)((LPSTR)szBuffer));
      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
             //
			    gwChannel =(USHORT) SendDlgItemMessage(
				                     hDlg, 
									 IDC_CFGCNT, 
									 CB_GETCURSEL, 
									 0, 
									 (LPARAM)0);            

               //
               // get gate period
               //
           
				 SendDlgItemMessage(hDlg, IDC_GATEPERIOD, WM_GETTEXT, 13,
                  (LPARAM)(LPSTR)szBuffer) ;         
				if(!InvalidStrToNum((const char *)szBuffer))
				{
					MessageBox(hDlg,"Period is not invalid number","Error",MB_OK);
					return TRUE;
				}
			    gfGatePeriod = (float)atof(szBuffer);
			
             SendDlgItemMessage(hDlg, IDC_UPCYCLE, WM_GETTEXT, 13,
                                    (LPARAM)(LPSTR)szBuffer) ;
			if(!InvalidStrToNum((const char *)szBuffer))
			{
				MessageBox(hDlg,"Hi Period is not invalid number","Error",MB_OK);
				return TRUE;
			}

             gfUpCycle = (float)atof(szBuffer);

			    gusOutCount = 0;   //0 means PWM pulse out not stop, no use here
			SendDlgItemMessage(hDlg,IDC_OUTCOUNT,WM_GETTEXT,13,(LPARAM)(LPSTR)szBuffer);

			if(!InvalidStrToNum((const char *)szBuffer))
			{
				MessageBox(hDlg,"OutCount is not invalid number","Error",MB_OK);
				return TRUE;
			}   

			gusOutCount=(USHORT)atol(szBuffer);
             EndDialog(hDlg, 0);
             return TRUE;


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

            case IDC_DEVICE :

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

                if (HIWORD(wParam) == CBN_SELCHANGE)
                {
                    if ((dwIndex = SendDlgItemMessage(hDlg, IDC_DEVICE,
                        CB_GETCURSEL, 0, 0)) != CB_ERR)
                         gwDevice = (WORD)dwIndex;
                    else
                        return TRUE;


                    // ------------------------------------------------------
                    // Initialize Module Combobox for COM port or CAN devices
                    // ------------------------------------------------------

                    // check any device attached on this COM port or CAN

                    gnNumOfSubdevices = DeviceList[gwDevice].nNumOfSubdevices;
                    if (gnNumOfSubdevices > MAX_DEVICES)
                        gnNumOfSubdevices = MAX_DEVICES;


                    // retrieve the information of all installed devices

                    if (gnNumOfSubdevices != 0)
                    {
                        if ((ErrCde = DRV_DeviceGetSubList(
                            (DWORD)DeviceList[gwDevice].dwDeviceNum,
                            (DEVLIST far *)&SubDeviceList[0],
                            (SHORT)gnNumOfSubdevices,
                            (SHORT far *)&nOutEntries)) != (LONG)SUCCESS)
                        {
                            DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                            MessageBox(hMainWnd, (LPCSTR)szErrMsg,
                                "Driver Message", MB_OK);
                            return TRUE;
                        }


                        // 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));

                        gwSubDevice = 0;

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

                    //
                    // 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(hDlg,(LPCSTR)szErrMsg,"Device Open",MB_OK);
                       return 0;
                    }
                    
                    
                    //
                    // get number of counter channels
                    //
                    
                    ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
                    ptDevFeatures.size = sizeof(DEVFEATURES);
                    if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
                       (LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
                    {
                       DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                       MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                       DRV_DeviceClose((LONG far *)&DriverHandle);
                       return 0;
                    }
                    
                    dwBordID = DevFeatures.dwBoardID;
                    usMaxCntChan = DevFeatures.usMaxTimerChl;
                    DRV_DeviceClose(&DriverHandle);
                    //
                    // Initialize Input Channel Edit
                    //
                    SendDlgItemMessage(hDlg, IDC_CFGCNT, CB_RESETCONTENT, (WPARAM)0,(LPARAM)0);
                    
                    for ( i = 0; i< usMaxCntChan; i++ )
                    {
                       _itoa( i, tmp, 10 );
                       SendDlgItemMessage( 
                          hDlg, 
                          IDC_CFGCNT,
                          CB_ADDSTRING, 
                          0, 
                          ( LPARAM )( ( LPSTR )tmp ) );
                    }
                    
                    SendDlgItemMessage(hDlg, IDC_CFGCNT, CB_SETCURSEL, gwChannel,0 );
                }

                return TRUE;
         }

         break;
    }

    return FALSE ;
}


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

    PURPOSE:  Processes dialog box messages for setting paramters, while running PWM
****************************************************************************/
BOOL FTYPE ChgSetDlgProc
(
 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 :
      
      sprintf(szBuffer,"%5.6f",gfGatePeriod);
      SendDlgItemMessage(hDlg, IDC_CHGPERIOD, EM_REPLACESEL, 0,
         (LPARAM)((LPSTR)szBuffer));
      sprintf(szBuffer,"%5.6f",gfUpCycle);
      SendDlgItemMessage(hDlg, IDC_CHGHIPERIOD, EM_REPLACESEL, 0,
         (LPARAM)((LPSTR)szBuffer));
      return TRUE;
      
   case WM_COMMAND :
      switch (LOWORD(wParam))
      {

⌨️ 快捷键说明

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