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

📄 portio.c

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 C
📖 第 1 页 / 共 3 页
字号:
                if (IsDlgButtonChecked(hDlg, IDC_D11) > 0)
                    glDoState += 0x800;
                if (IsDlgButtonChecked(hDlg, IDC_D12) > 0)
                    glDoState += 0x1000;
                if (IsDlgButtonChecked(hDlg, IDC_D13) > 0)
                    glDoState += 0x2000;
                if (IsDlgButtonChecked(hDlg, IDC_D14) > 0)
                    glDoState += 0x4000;
                if (IsDlgButtonChecked(hDlg, IDC_D15) > 0)
                    glDoState += 0x8000;

                // output word
				ptWritePortWord.port = gwPortAddress;
				ptWritePortWord.WordData = (USHORT)( glDoState & 0xffff);

                if((ErrCde = DRV_WritePortWord(DriverHandle, 
					(LPT_WritePortWord)&ptWritePortWord)) != 0)
                {
                    DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                    MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                    return 0;
                }

                return TRUE;

            case IDC_WRITEDWORD:
				
                // 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;
                if (IsDlgButtonChecked(hDlg, IDC_D11) > 0)
                    glDoState += 0x800;
                if (IsDlgButtonChecked(hDlg, IDC_D12) > 0)
                    glDoState += 0x1000;
                if (IsDlgButtonChecked(hDlg, IDC_D13) > 0)
                    glDoState += 0x2000;
                if (IsDlgButtonChecked(hDlg, IDC_D14) > 0)
                    glDoState += 0x4000;
                if (IsDlgButtonChecked(hDlg, IDC_D15) > 0)
                    glDoState += 0x8000;
				
				if (IsDlgButtonChecked(hDlg, IDC_D16) > 0)
					HighData = 1;
				else
					HighData = 0;
				if (IsDlgButtonChecked(hDlg, IDC_D17) > 0)
					HighData += 0x2;
				if (IsDlgButtonChecked(hDlg, IDC_D18) > 0)
					HighData += 0x4;
				if (IsDlgButtonChecked(hDlg, IDC_D19) > 0)
					HighData += 0x8;
				if (IsDlgButtonChecked(hDlg, IDC_D20) > 0)
					HighData += 0x10;
				if (IsDlgButtonChecked(hDlg, IDC_D21) > 0)
					HighData += 0x20;
				if (IsDlgButtonChecked(hDlg, IDC_D22) > 0)
					HighData += 0x40;
				if (IsDlgButtonChecked(hDlg, IDC_D23) > 0)
					HighData += 0x80;
				if (IsDlgButtonChecked(hDlg, IDC_D24) > 0)
					HighData += 0x100;
				if (IsDlgButtonChecked(hDlg, IDC_D25) > 0)
					HighData += 0x200;
				if (IsDlgButtonChecked(hDlg, IDC_D26) > 0)
					HighData += 0x400;
				if (IsDlgButtonChecked(hDlg, IDC_D27) > 0)
					HighData += 0x800;
				if (IsDlgButtonChecked(hDlg, IDC_D28) > 0)
					HighData += 0x1000;
				if (IsDlgButtonChecked(hDlg, IDC_D29) > 0)
					HighData += 0x2000;
				if (IsDlgButtonChecked(hDlg, IDC_D30) > 0)
					HighData += 0x4000;
				if (IsDlgButtonChecked(hDlg, IDC_D31) > 0)
					HighData += 0x8000;
				
				glDoState = glDoState + (HighData << 16); 
								
                // output dword
				ptWritePortDword.port = gwPortAddress;
				ptWritePortDword.DwordData = glDoState;
				
                if((ErrCde=DRV_WritePortDword(DriverHandle,
					(LPT_WritePortDword)&ptWritePortDword))!= 0)
                {
                    DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                    MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                    return 0;
                }
				
                return TRUE;
				
			case IDC_READBYTE:

                // read port byte
				ptReadPortByte.port = gwPortAddress;
				ptReadPortByte.ByteData = (USHORT far *)&glDiState;

                if((ErrCde = DRV_ReadPortByte(DriverHandle,
					(LPT_ReadPortByte)&ptReadPortByte)) != 0)
                {
                    DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                    MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                    return 0;
                }

                // display the value

                _itoa((int)(glDiState & 0xff), szBuffer, 16);
                SendDlgItemMessage(hDlg, IDC_BYTEDATA, WM_SETTEXT, 0,
                        (LPARAM)((LPSTR)szBuffer));

                return TRUE;

            case IDC_READWORD:

                // read port word
				ptReadPortWord.port = gwPortAddress;
				ptReadPortWord.WordData = (USHORT far *)&glDiState;
                if((ErrCde = DRV_ReadPortWord(DriverHandle, 
					(LPT_ReadPortWord)&ptReadPortWord)) != 0)
                {
                    DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                    MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                    return 0;
                }

                // display the value

                _ltoa((USHORT)(glDiState & 0xffff), szBuffer, 16);
                SendDlgItemMessage(hDlg, IDC_WORDDATA, WM_SETTEXT, 0,
                        (LPARAM)((LPSTR)szBuffer));

                return TRUE;

            case IDC_READDWORD:
				
                // read port dword
				ptReadPortDword.port = gwPortAddress;
				ptReadPortDword.DwordData = (ULONG far *)&glDiState;
                if((ErrCde = DRV_ReadPortDword(DriverHandle, 
					(LPT_ReadPortDword)&ptReadPortDword)) != 0)
                {
                    DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
                    MessageBox(hDlg,(LPCSTR)szErrMsg,"Driver Message",MB_OK);
                    return 0;
                }
				
                // display the value
				
                _ltoa(glDiState , szBuffer, 16);
                SendDlgItemMessage(hDlg, IDC_DWORDDATA, WM_SETTEXT, 0,
					(LPARAM)((LPSTR)szBuffer));
				
                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 ;

    switch (message)
    {
        case WM_CREATE:

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

            lpfnConfigDlgProc = MakeProcInstance (ConfigDlgProc, hInstance) ;

            lpfnRunDlgProc = MakeProcInstance (RunDlgProc, hInstance) ;

            return 0 ;

        case WM_COMMAND:     // message: from application menu

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

            case IDM_RUN :
                DialogBox (hInstance, MAKEINTRESOURCE(IDD_RUN),
                         hWnd, lpfnRunDlgProc) ;
                return 0;

            }

            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

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

   return ((LONG)NULL);
}

//------------------------------------------------------------------
// Function    : StringToDec
// PURPOSE     : This function is used to do string conversion to base
//				 by 16 or base by 10.. etc.
// Parameters  : szStr(IN), nBase(IN)
// Return      : szStr (success)
// Call/Called procedure cross reference :
// Call        Called		     Explanation
// Power
//------------------------------------------------------------------
static int StringToDec(char *szStr, int nBase)
{
    int i,j,nValue, nResult;
    char cNum;
    nResult = 0;
    for(i = strlen(szStr)-1, j = 0; i >=0 ; --i,++j)
    {
	cNum = *(szStr+i);
	if(cNum >= '0' && cNum <= '9')
	    nValue = (int)(cNum - '0');
	else
	{
	    cNum = tolower(cNum);
	    nValue = (int)(cNum - 'a') + 10;
	}
	nResult = nResult + Power(nBase, j)* nValue;
    }
    return (nResult);

}

//------------------------------------------------------------------
// Function    : Power
// PURPOSE     : This function is used to do support StringToDec
//				 function.
// Parameters  : nBase(IN), nPow(IN)
// Return      : Value (success)
// Call/Called procedure cross reference :
// Call        Called		     Explanation
//			   StringToDec
//------------------------------------------------------------------
static int Power(int nBase, int nPow)
{
    int nValue,i;
    if(nPow == 0)
	return(1);

    nValue = 1;
    for(i = nPow; i > 0; i--)
	nValue = nValue * nBase;

    return(nValue);
}

⌨️ 快捷键说明

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