📄 portio.c
字号:
// 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 Output Channel
// -----------------------------
sprintf( szBuffer, "%X", gwPortAddress);
SendDlgItemMessage(hDlg, IDC_PORT, 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
//
if (SendDlgItemMessage(hDlg, IDC_PORT,
EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(hDlg, IDC_PORT,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
gwPortAddress = StringToDec(szBuffer, 16);
}
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));
}
}
return TRUE;
}
break;
}
return FALSE ;
}
/***************************************************************************
FUNCTION: RunDlgProc(HWND, unsigned, WPARAM, LPARAM)
PURPOSE: Processes dialog box messages for IDD_RUN
****************************************************************************/
BOOL FTYPE RunDlgProc
(
HWND hDlg, // window handle
unsigned message, // type of message
WPARAM wParam, // additional information
LPARAM lParam // additional information
)
{
char szBuffer[40];
USHORT HighData;
switch (message)
{
case WM_INITDIALOG :
// Initialize Output Byte Value Check Button
CheckDlgButton(hDlg, IDC_D0, (glDoState & 0x1));
CheckDlgButton(hDlg, IDC_D1, (glDoState & 0x2));
CheckDlgButton(hDlg, IDC_D2, (glDoState & 0x4));
CheckDlgButton(hDlg, IDC_D3, (glDoState & 0x8));
CheckDlgButton(hDlg, IDC_D4, (glDoState & 0x10));
CheckDlgButton(hDlg, IDC_D5, (glDoState & 0x20));
CheckDlgButton(hDlg, IDC_D6, (glDoState & 0x40));
CheckDlgButton(hDlg, IDC_D7, (glDoState & 0x80));
CheckDlgButton(hDlg, IDC_D8, (glDoState & 0x100));
CheckDlgButton(hDlg, IDC_D9, (glDoState & 0x200));
CheckDlgButton(hDlg, IDC_D10, (glDoState & 0x400));
CheckDlgButton(hDlg, IDC_D11, (glDoState & 0x800));
CheckDlgButton(hDlg, IDC_D12, (glDoState & 0x1000));
CheckDlgButton(hDlg, IDC_D13, (glDoState & 0x2000));
CheckDlgButton(hDlg, IDC_D14, (glDoState & 0x4000));
CheckDlgButton(hDlg, IDC_D15, (glDoState & 0x8000));
HighData = ( glDoState & 0xffff0000 ) >> 16;
CheckDlgButton(hDlg, IDC_D16, (HighData & 0x1));
CheckDlgButton(hDlg, IDC_D17, (HighData & 0x2));
CheckDlgButton(hDlg, IDC_D18, (HighData & 0x4));
CheckDlgButton(hDlg, IDC_D19, (HighData & 0x8));
CheckDlgButton(hDlg, IDC_D20, (HighData & 0x10));
CheckDlgButton(hDlg, IDC_D21, (HighData & 0x20));
CheckDlgButton(hDlg, IDC_D22, (HighData & 0x40));
CheckDlgButton(hDlg, IDC_D23, (HighData & 0x80));
CheckDlgButton(hDlg, IDC_D24, (HighData & 0x100));
CheckDlgButton(hDlg, IDC_D25, (HighData & 0x200));
CheckDlgButton(hDlg, IDC_D26, (HighData & 0x400));
CheckDlgButton(hDlg, IDC_D27, (HighData & 0x800));
CheckDlgButton(hDlg, IDC_D28, (HighData & 0x1000));
CheckDlgButton(hDlg, IDC_D29, (HighData & 0x2000));
CheckDlgButton(hDlg, IDC_D30, (HighData & 0x4000));
CheckDlgButton(hDlg, IDC_D31, (HighData & 0x8000));
//
// 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,"Notice",MB_OK);
return 0;
}
return TRUE;
case WM_COMMAND :
switch (LOWORD(wParam))
{
case IDCANCEL :
EndDialog(hDlg, 0);
return TRUE;
case IDC_WRITEBYTE :
// get output byte value
if (IsDlgButtonChecked(hDlg, IDC_D0) > 0)
glDoState = 1;
else
glDoState = 0;
if (IsDlgButtonChecked(hDlg, IDC_D1) > 0)
glDoState += 0x2;
if (IsDlgButtonChecked(hDlg, IDC_D2) > 0)
glDoState += 0x4;
if (IsDlgButtonChecked(hDlg, IDC_D3) > 0)
glDoState += 0x8;
if (IsDlgButtonChecked(hDlg, IDC_D4) > 0)
glDoState += 0x10;
if (IsDlgButtonChecked(hDlg, IDC_D5) > 0)
glDoState += 0x20;
if (IsDlgButtonChecked(hDlg, IDC_D6) > 0)
glDoState += 0x40;
if (IsDlgButtonChecked(hDlg, IDC_D7) > 0)
glDoState += 0x80;
// output byte
ptWritePortByte.port = gwPortAddress;
ptWritePortByte.ByteData = (USHORT)( glDoState & 0xffff );
if((ErrCde = DRV_WritePortByte( DriverHandle,
(LPT_WritePortByte)&ptWritePortByte)) != 0 )
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
return TRUE;
case IDC_WRITEWORD:
// get output byte value
if (IsDlgButtonChecked(hDlg, IDC_D0) > 0)
glDoState = 1;
else
glDoState = 0;
if (IsDlgButtonChecked(hDlg, IDC_D1) > 0)
glDoState += 0x2;
if (IsDlgButtonChecked(hDlg, IDC_D2) > 0)
glDoState += 0x4;
if (IsDlgButtonChecked(hDlg, IDC_D3) > 0)
glDoState += 0x8;
if (IsDlgButtonChecked(hDlg, IDC_D4) > 0)
glDoState += 0x10;
if (IsDlgButtonChecked(hDlg, IDC_D5) > 0)
glDoState += 0x20;
if (IsDlgButtonChecked(hDlg, IDC_D6) > 0)
glDoState += 0x40;
if (IsDlgButtonChecked(hDlg, IDC_D7) > 0)
glDoState += 0x80;
if (IsDlgButtonChecked(hDlg, IDC_D8) > 0)
glDoState += 0x100;
if (IsDlgButtonChecked(hDlg, IDC_D9) > 0)
glDoState += 0x200;
if (IsDlgButtonChecked(hDlg, IDC_D10) > 0)
glDoState += 0x400;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -