📄 pulsepwm.c
字号:
// 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));
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 Channel Edit
//
itoa(gwChannel, szBuffer, 10);
SendDlgItemMessage(hDlg, IDC_ECHANNEL, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
// Initialize Pulse Out count
// J.L mod
//if(gwChannel & 0x01)
//if(!(gwChannel )) //commented by yingsong.huang at 08/29/02
if(gwChannel & 0x01)
{
CheckDlgButton(hDlg, IDC_PWMEnableCh0, 1);
EnableWindow(GetDlgItem(hDlg, IDC_GATEPERIOD0),TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_UPCYCLE0),TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable0),TRUE);
sprintf(szBuffer,"%5.1f",gfGatePeriod[0]);
SendDlgItemMessage(hDlg, IDC_GATEPERIOD0, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
sprintf(szBuffer,"%5.1f",gfUpCycle[0]);
SendDlgItemMessage(hDlg, IDC_UPCYCLE0, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
if(gusOutCount[0])
{
CheckDlgButton(hDlg, IDC_OutCountEnable0, 1);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount0),TRUE);
sprintf(szBuffer,"%d",gusOutCount[0]);
SendDlgItemMessage(hDlg, IDC_ED_OutCount0, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
}
else
{
CheckDlgButton(hDlg, IDC_OutCountEnable0, 0);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount0),FALSE);
}
}
else
{
CheckDlgButton(hDlg, IDC_PWMEnableCh0, 0);
EnableWindow(GetDlgItem(hDlg, IDC_GATEPERIOD0),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_UPCYCLE0),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable0),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount0),FALSE);
}
// J.L mod
//if(gwChannel & 0x02)
//if(gwChannel & 0x01) //commented by yingsong.huang
if(gwChannel & 0x02)
{
CheckDlgButton(hDlg, IDC_PWMEnableCh1, 1);
EnableWindow(GetDlgItem(hDlg, IDC_GATEPERIOD1),TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_UPCYCLE1),TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable1),TRUE);
sprintf(szBuffer,"%5.1f",gfGatePeriod[1]);
SendDlgItemMessage(hDlg, IDC_GATEPERIOD1, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
sprintf(szBuffer,"%5.1f",gfUpCycle[1]);
SendDlgItemMessage(hDlg, IDC_UPCYCLE1, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
if(gusOutCount[1])
{
CheckDlgButton(hDlg, IDC_OutCountEnable1, 1);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount1),TRUE);
sprintf(szBuffer,"%d",gusOutCount[1]);
SendDlgItemMessage(hDlg, IDC_ED_OutCount1, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
}
else
{
CheckDlgButton(hDlg, IDC_OutCountEnable1, 0);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount1),FALSE);
}
}
else
{
CheckDlgButton(hDlg, IDC_PWMEnableCh1, 0);
EnableWindow(GetDlgItem(hDlg, IDC_GATEPERIOD1),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_UPCYCLE1),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable1),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount1),FALSE);
}
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 gate period
//
if(IsDlgButtonChecked(hDlg, IDC_PWMEnableCh0))
{
// J.L mod
//gwChannel = 0x01;
//gwChannel = 0x0; //commented by yingsong.huang at 08/29/02
gwChannel |= 0x01; //add by yingsong.huang at 08/29/02
SendDlgItemMessage(hDlg, IDC_GATEPERIOD0, WM_GETTEXT, 13,
(LPARAM)(LPSTR)szBuffer) ;
gfGatePeriod[0] = (float)atof(szBuffer);
SendDlgItemMessage(hDlg, IDC_UPCYCLE0, WM_GETTEXT, 13,
(LPARAM)(LPSTR)szBuffer) ;
gfUpCycle[0] = (float)atof(szBuffer);
//Get Pulse Out Count
if(IsDlgButtonChecked(hDlg, IDC_OutCountEnable0))
{
SendDlgItemMessage( hDlg, IDC_ED_OutCount0, EM_GETLINE, 0, (LPARAM)szTmp);
gusOutCount[0] = LOWORD( atol(szTmp));
}
else
gusOutCount[0] = 0; //0 means PWM pulse out not stop
}
else
{
//J.L mod
//gwChannel &= 0x02;
//gwChannel &= 0x01; //commented by yingsong.huang at 08/29/02
gwChannel &= 0xfe; //added by yingsong.huang
gfGatePeriod[0] = 0.0;
gfUpCycle[0] = 0.0;
}
if(IsDlgButtonChecked(hDlg, IDC_PWMEnableCh1))
{
// J.L mod
//gwChannel |= 0x02;
//gwChannel |= 0x01; //commented by yingsong.huang at 08/29/02
gwChannel |=0x02; //added by yingsong.huang
SendDlgItemMessage(hDlg, IDC_GATEPERIOD1, WM_GETTEXT, 13,
(LPARAM)(LPSTR)szBuffer) ;
gfGatePeriod[1] = (float)atof(szBuffer);
SendDlgItemMessage(hDlg, IDC_UPCYCLE1, WM_GETTEXT, 13,
(LPARAM)(LPSTR)szBuffer) ;
gfUpCycle[1] = (float)atof(szBuffer);
//Get Pulse Out Count
if(IsDlgButtonChecked(hDlg, IDC_OutCountEnable1))
{
SendDlgItemMessage( hDlg, IDC_ED_OutCount1, EM_GETLINE, 0, (LPARAM)szTmp);
gusOutCount[1] = LOWORD( atol(szTmp));
}
else
gusOutCount[1] = 0; //0 means PWM pulse out not stop
}
else
{
//gwChannel &= 0x01;
//gwChannel &= 0x0; // J.L mod //commented by yingsong.huang
gwChannel &= 0xfd;
gfGatePeriod[1] = 0.0;
gfUpCycle[1] = 0.0;
}
EndDialog(hDlg, 0);
return TRUE;
case IDCANCEL :
EndDialog(hDlg, 0);
return TRUE;
case IDC_OutCountEnable0 :
if(IsDlgButtonChecked(hDlg,IDC_OutCountEnable0))
{ EnableWindow(GetDlgItem(hDlg,IDC_ED_OutCount0),TRUE);
SetFocus(GetDlgItem(hDlg,IDC_ED_OutCount0));
}
else
EnableWindow(GetDlgItem(hDlg,IDC_ED_OutCount0),FALSE);
case IDC_OutCountEnable1 :
if(IsDlgButtonChecked(hDlg,IDC_OutCountEnable1))
{ EnableWindow(GetDlgItem(hDlg,IDC_ED_OutCount1),TRUE);
SetFocus(GetDlgItem(hDlg,IDC_ED_OutCount1));}
else
EnableWindow(GetDlgItem(hDlg,IDC_ED_OutCount1),FALSE);
case IDC_PWMEnableCh0 :
if(IsDlgButtonChecked(hDlg,IDC_PWMEnableCh0))
{ EnableWindow(GetDlgItem(hDlg,IDC_GATEPERIOD0),TRUE);
EnableWindow(GetDlgItem(hDlg,IDC_UPCYCLE0),TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable0),TRUE);
SetFocus(GetDlgItem(hDlg,IDC_GATEPERIOD0));}
else
{
EnableWindow(GetDlgItem(hDlg,IDC_GATEPERIOD0),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_UPCYCLE0),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable0),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount0),FALSE);
}
case IDC_PWMEnableCh1 :
if(IsDlgButtonChecked(hDlg,IDC_PWMEnableCh1))
{ EnableWindow(GetDlgItem(hDlg,IDC_GATEPERIOD1),TRUE);
EnableWindow(GetDlgItem(hDlg,IDC_UPCYCLE1),TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable1),TRUE);
SetFocus(GetDlgItem(hDlg,IDC_GATEPERIOD1));}
else
{
EnableWindow(GetDlgItem(hDlg,IDC_GATEPERIOD1),FALSE);
EnableWindow(GetDlgItem(hDlg,IDC_UPCYCLE1),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_OutCountEnable1),FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_ED_OutCount1),FALSE);
}
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -