Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.5 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgDeviceGPIOPCI1762.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgDeviceGPIOPCI1762.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgDeviceGPIOPCI1762.h"
  16. CLgDeviceGPIOPCI1762::CLgDeviceGPIOPCI1762()
  17. {
  18. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDeviceGPIOPCI1762::CLgDeviceGPIOPCI1762") );
  19. }
  20. CLgDeviceGPIOPCI1762::~CLgDeviceGPIOPCI1762()
  21. {
  22. Destroy();
  23. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgDeviceGPIOPCI1762::~CLgDeviceGPIOPCI1762") );
  24. }
  25. BOOL CLgDeviceGPIOPCI1762::Create( INT nDevice )
  26. {
  27. if( !CLgDeviceGPIO::Create( 16, 16 ) )
  28. {
  29. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::Create failed") );
  30. return FALSE;
  31. }
  32. if( !CLgAdvantechPCI1762::Create( nDevice ) )
  33. {
  34. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::Create failed") );
  35. return FALSE;
  36. }
  37. DWORD dwState;
  38. if( !CLgAdvantechPCI1762::GetDirectInputAll( CLgAdvantechPCI1762::DIM_ALL, &dwState ) )
  39. {
  40. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::GetDirectInputAll failed") );
  41. return FALSE;
  42. }
  43. if( !CLgDeviceGPIO::InitInputState( 0, dwState ) )
  44. {
  45. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::InitInputState failed") );
  46. return FALSE;
  47. }
  48. if( !CLgAdvantechPCI1762::SetDirectOutputAll( CLgAdvantechPCI1762::DOM_ALL, 0 ) )
  49. {
  50. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::SetDirectOutputAll failed") );
  51. return FALSE;
  52. }
  53. if( !CLgAdvantechPCI1762::GetDirectOutputAll( CLgAdvantechPCI1762::DOM_ALL, &dwState ) )
  54. {
  55. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgAdvantechPCI1762::GetDirectOutputAll failed") );
  56. return FALSE;
  57. }
  58. if( !CLgDeviceGPIO::SetOutputState( 0, CLgAdvantechPCI1762::DOM_ALL, dwState ) )
  59. {
  60. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::SetOutputState failed") );
  61. return FALSE;
  62. }
  63. return TRUE;
  64. }
  65. void CLgDeviceGPIOPCI1762::Destroy()
  66. {
  67. CLgAdvantechPCI1762::Destroy();
  68. }
  69. BOOL CLgDeviceGPIOPCI1762::ReadWriteProc( DWORD dwTimeout )
  70. {
  71. INT nCmd = GetCmd();
  72. switch( nCmd )
  73. {
  74. case CMD_GET_INPUT:
  75. {
  76. // avalible for new commands
  77. ReleaseCmd();
  78. // get input
  79. DWORD dwState;
  80. CLgDeviceGPIO::GetInputState( 0, &dwState );
  81. // call handler
  82. OnEvtGetInput( m_Input, ( dwState & (1 << m_Input) ) ? TRUE : FALSE );
  83. }
  84. break;
  85. case CMD_GET_INPUT_ALL:
  86. {
  87. // avalible for new commands
  88. ReleaseCmd();
  89. // call handler
  90. OnEvtGetInputAll( GetInputPins() );
  91. }
  92. break;
  93. case CMD_SET_OUTPUT:
  94. {
  95. // avalible for new commands
  96. ReleaseCmd();
  97. // set output
  98. CLgAdvantechPCI1762::SetDirectOutput( m_Output.nIndex, m_Output.bOn );
  99. // store output state
  100. CLgDeviceGPIO::SetOutputState( 0, 1 << m_Output.nIndex, m_Output.bOn ? 1 << m_Output.nIndex : 0 );
  101. // call handler
  102. OnEvtSetOutput( m_Output.nIndex, m_Output.bOn );
  103. }
  104. break;
  105. case CMD_GET_OUTPUT_ALL:
  106. {
  107. // avalible for new commands
  108. ReleaseCmd();
  109. // call handler
  110. OnEvtGetOutputAll( GetOutputPins() );
  111. }
  112. break;
  113. case CMD_NONE:
  114. break;
  115. default:
  116. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgDeviceGPIOPCI1762::ReadWriteProc"), _T("received unsupported command %d"), nCmd );
  117. ReleaseCmd();
  118. OnEvtCommandError( nCmd, _T("UNSUPPORTED") );
  119. break;
  120. }
  121. if( CLgAdvantechPCI1762::WaitForEvent( dwTimeout ) )
  122. {
  123. DWORD dwState;
  124. if( !CLgAdvantechPCI1762::GetDirectInputAll( CLgAdvantechPCI1762::DIM_ALL, &dwState ) )
  125. {
  126. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::ReadWriteProc"), _T("CLgAdvantechPCI1762::GetDirectInputAll failed") );
  127. }
  128. else
  129. if( !CLgDeviceGPIO::UpdateInputState( 0, dwState ) )
  130. {
  131. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgDeviceGPIOPCI1762::Create"), _T("CLgDeviceGPIO::InitInputState failed") );
  132. }
  133. }
  134. return TRUE;
  135. }
  136. void CLgDeviceGPIOPCI1762::OnInputChange( INT nBit, BOOL bOn )
  137. {
  138. OnEvtInputChange( nBit, bOn );
  139. }