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.

346 lines
10 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: LgAdvantechPCI1762.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgAdvantechPCI1762.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgAdvantechPCI1762.h"
  16. CLgAdvantechPCI1762::CLgAdvantechPCI1762()
  17. {
  18. m_hDevice = NULL;
  19. m_bEvent = FALSE;
  20. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgAdvantechPCI1762::CLgAdvantechPCI1762") );
  21. }
  22. CLgAdvantechPCI1762::~CLgAdvantechPCI1762()
  23. {
  24. Destroy();
  25. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgAdvantechPCI1762::~CLgAdvantechPCI1762") );
  26. }
  27. BOOL CLgAdvantechPCI1762::Create( INT nDevice )
  28. {
  29. Destroy();
  30. __try
  31. {
  32. // open device
  33. DWORD dwResult = DRV_DeviceOpen( nDevice, &m_hDevice );
  34. if( dwResult != SUCCESS )
  35. {
  36. TCHAR pErrorMessage[MAX_PATH];
  37. DRV_GetErrorMessage( dwResult, pErrorMessage );
  38. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::Create"), _T("DRV_DeviceOpen failed with <%s>"), pErrorMessage );
  39. return FALSE;
  40. }
  41. // enable event handling
  42. PT_EnableEvent EventSetting;
  43. EventSetting.EventType = ADS_EVT_INTERRUPT;
  44. EventSetting.Enabled = TRUE;
  45. EventSetting.Count = 1;
  46. dwResult = DRV_EnableEvent( m_hDevice, &EventSetting );
  47. if( dwResult != SUCCESS )
  48. {
  49. TCHAR pErrorMessage[MAX_PATH];
  50. DRV_GetErrorMessage( dwResult, pErrorMessage );
  51. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::Create"), _T("DRV_EnableEvent failed with <%s>"), pErrorMessage );
  52. return FALSE;
  53. }
  54. m_bEvent = TRUE;
  55. }
  56. __except( EXCEPTION_EXECUTE_HANDLER )
  57. {
  58. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::Create"), _T("Exception 0x%08X"), _exception_code() );
  59. return FALSE;
  60. }
  61. return TRUE;
  62. }
  63. void CLgAdvantechPCI1762::Destroy()
  64. {
  65. if( m_hDevice != NULL )
  66. {
  67. if( m_bEvent )
  68. {
  69. PT_EnableEvent EventSetting;
  70. EventSetting.EventType = ADS_EVT_INTERRUPT;
  71. EventSetting.Enabled = FALSE;
  72. EventSetting.Count = 1;
  73. DWORD dwResult = DRV_EnableEvent( m_hDevice, &EventSetting );
  74. if( dwResult != SUCCESS )
  75. {
  76. TCHAR pErrorMessage[MAX_PATH];
  77. DRV_GetErrorMessage( dwResult, pErrorMessage );
  78. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::Destroy"), _T("DRV_EnableEvent failed with <%s>"), pErrorMessage );
  79. }
  80. m_bEvent = FALSE;
  81. }
  82. DRV_DeviceClose( &m_hDevice );
  83. m_hDevice = NULL;
  84. }
  85. }
  86. BOOL CLgAdvantechPCI1762::WaitForEvent( DWORD dwTimeout )
  87. {
  88. if( !m_hDevice )
  89. {
  90. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::WaitForEvent"), _T("Device handle is not valid") );
  91. return FALSE;
  92. }
  93. USHORT usEventType = 0;
  94. PT_CheckEvent ptCheckEvent;
  95. ptCheckEvent.EventType = &usEventType;
  96. ptCheckEvent.Milliseconds = dwTimeout;
  97. if( DRV_CheckEvent( m_hDevice, &ptCheckEvent ) != SUCCESS )
  98. return FALSE;
  99. return TRUE;
  100. }
  101. BOOL CLgAdvantechPCI1762::SetDirectOutput( INT nBit, BOOL bOn )
  102. {
  103. if( !m_hDevice )
  104. {
  105. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::SetDirectOutput"), _T("Device handle is not valid") );
  106. return FALSE;
  107. }
  108. PT_DioWriteBit dioWriteBit;
  109. dioWriteBit.port = nBit / 8;
  110. dioWriteBit.bit = nBit % 8;
  111. dioWriteBit.state = bOn;
  112. DWORD dwResult = DRV_DioWriteBit( m_hDevice, &dioWriteBit );
  113. if( dwResult != SUCCESS )
  114. {
  115. TCHAR pErrorMessage[MAX_PATH];
  116. DRV_GetErrorMessage( dwResult, pErrorMessage );
  117. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::SetDirectOutput"), _T("DRV_DioWriteBit failed with <%s>"), pErrorMessage );
  118. return FALSE;
  119. }
  120. return TRUE;
  121. }
  122. BOOL CLgAdvantechPCI1762::SetDirectOutputAll( DWORD dwMask, DWORD dwState )
  123. {
  124. if( !m_hDevice )
  125. {
  126. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::SetDirectOutputAll"), _T("Device handle is not valid") );
  127. return FALSE;
  128. }
  129. // write first part
  130. PT_DioWritePortByte dioWritePortByte;
  131. dioWritePortByte.port = 0;
  132. dioWritePortByte.mask = (SHORT)(dwMask & 0x00FF);
  133. dioWritePortByte.state = (SHORT)(dwState & 0x00FF);
  134. DWORD dwResult = DRV_DioWritePortByte( m_hDevice, &dioWritePortByte );
  135. if( dwResult != SUCCESS )
  136. {
  137. TCHAR pErrorMessage[MAX_PATH];
  138. DRV_GetErrorMessage( dwResult, pErrorMessage );
  139. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::SetDirectOutputAll"), _T("DRV_DioWritePortByte for first part failed with <%s>"), pErrorMessage );
  140. return FALSE;
  141. }
  142. // write second part
  143. dioWritePortByte.port = 1;
  144. dioWritePortByte.mask = (SHORT)( ( dwMask >> 8 ) & 0x00FF);
  145. dioWritePortByte.state = (SHORT)( ( dwState >> 8 ) & 0x00FF);
  146. dwResult = DRV_DioWritePortByte( m_hDevice, &dioWritePortByte );
  147. if( dwResult != SUCCESS )
  148. {
  149. TCHAR pErrorMessage[MAX_PATH];
  150. DRV_GetErrorMessage( dwResult, pErrorMessage );
  151. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::SetDirectOutputAll"), _T("DRV_DioWritePortByte for second part failed with <%s>"), pErrorMessage );
  152. return FALSE;
  153. }
  154. return TRUE;
  155. }
  156. BOOL CLgAdvantechPCI1762::GetDirectOutput( INT nBit, PBOOL pOn )
  157. {
  158. if( !m_hDevice )
  159. {
  160. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectOutput"), _T("Device handle is not valid") );
  161. return FALSE;
  162. }
  163. if( !pOn )
  164. {
  165. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectOutput"), _T("Passed NULL pointer for output") );
  166. return FALSE;
  167. }
  168. USHORT state;
  169. PT_DioGetCurrentDOBit dioGetCurrentDOBit;
  170. dioGetCurrentDOBit.port = nBit / 8;
  171. dioGetCurrentDOBit.bit = nBit % 8;
  172. dioGetCurrentDOBit.state = &state;
  173. DWORD dwResult = DRV_DioGetCurrentDOBit( m_hDevice, &dioGetCurrentDOBit );
  174. if( dwResult != SUCCESS )
  175. {
  176. TCHAR pErrorMessage[MAX_PATH];
  177. DRV_GetErrorMessage( dwResult, pErrorMessage );
  178. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::GetDirectOutput"), _T("DRV_DioGetCurrentDOBit failed with <%s>"), pErrorMessage );
  179. return FALSE;
  180. }
  181. *pOn = state;
  182. return TRUE;
  183. }
  184. BOOL CLgAdvantechPCI1762::GetDirectOutputAll( DWORD dwMask, PDWORD pState )
  185. {
  186. if( !m_hDevice )
  187. {
  188. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectOutputAll"), _T("Device handle is not valid") );
  189. return FALSE;
  190. }
  191. if( !pState )
  192. {
  193. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectOutputAll"), _T("Passed NULL pointer for output") );
  194. return FALSE;
  195. }
  196. USHORT state;
  197. PT_DioGetCurrentDOByte dioGetCurrentDOByte;
  198. dioGetCurrentDOByte.port = 0;
  199. dioGetCurrentDOByte.value = &state;
  200. DWORD dwResult = DRV_DioGetCurrentDOByte( m_hDevice, &dioGetCurrentDOByte );
  201. if( dwResult != SUCCESS )
  202. {
  203. TCHAR pErrorMessage[MAX_PATH];
  204. DRV_GetErrorMessage( dwResult, pErrorMessage );
  205. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::GetDirectOutputAll"), _T("DRV_DioGetCurrentDOByte for first part failed with <%s>"), pErrorMessage );
  206. return FALSE;
  207. }
  208. *pState = (DWORD)state;
  209. dioGetCurrentDOByte.port = 1;
  210. dioGetCurrentDOByte.value = &state;
  211. dwResult = DRV_DioGetCurrentDOByte( m_hDevice, &dioGetCurrentDOByte );
  212. if( dwResult != SUCCESS )
  213. {
  214. TCHAR pErrorMessage[MAX_PATH];
  215. DRV_GetErrorMessage( dwResult, pErrorMessage );
  216. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::GetDirectOutput2All"), _T("DRV_DioGetCurrentDOByte for second part failed with <%s>"), pErrorMessage );
  217. return FALSE;
  218. }
  219. *pState |= (DWORD)(state << 8);
  220. return TRUE;
  221. }
  222. BOOL CLgAdvantechPCI1762::GetDirectInput( INT nBit, PBOOL pOn )
  223. {
  224. if( !m_hDevice )
  225. {
  226. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectInput"), _T("Device handle is not valid") );
  227. return FALSE;
  228. }
  229. if( !pOn )
  230. {
  231. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectInput"), _T("Passed NULL pointer for output") );
  232. return FALSE;
  233. }
  234. USHORT state;
  235. PT_DioReadBit dioReadBit;
  236. dioReadBit.port = nBit / 8;
  237. dioReadBit.bit = nBit % 8;
  238. dioReadBit.state = &state;
  239. DWORD dwResult = DRV_DioReadBit( m_hDevice, &dioReadBit );
  240. if( dwResult != SUCCESS )
  241. {
  242. TCHAR pErrorMessage[MAX_PATH];
  243. DRV_GetErrorMessage( dwResult, pErrorMessage );
  244. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::GetDirectInput"), _T("DRV_DioReadBit failed with <%s>"), pErrorMessage );
  245. return FALSE;
  246. }
  247. *pOn = state;
  248. return TRUE;
  249. }
  250. BOOL CLgAdvantechPCI1762::GetDirectInputAll( DWORD dwMask, PDWORD pState )
  251. {
  252. if( !m_hDevice )
  253. {
  254. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectInputAll"), _T("Device handle is not valid") );
  255. return FALSE;
  256. }
  257. if( !pState )
  258. {
  259. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, _T("CLgAdvantechPCI1762::GetDirectInputAll"), _T("Passed NULL pointer for output") );
  260. return FALSE;
  261. }
  262. USHORT state;
  263. PT_DioReadPortByte dioReadPortByte;
  264. dioReadPortByte.port = 0;
  265. dioReadPortByte.value = &state;
  266. DWORD dwResult = DRV_DioReadPortByte( m_hDevice, &dioReadPortByte );
  267. if( dwResult != SUCCESS )
  268. {
  269. TCHAR pErrorMessage[MAX_PATH];
  270. DRV_GetErrorMessage( dwResult, pErrorMessage );
  271. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::SetDirectOutputAll"), _T("DRV_DioReadPortByte for first part failed with <%s>"), pErrorMessage );
  272. return FALSE;
  273. }
  274. *pState = (DWORD)state;
  275. dioReadPortByte.port = 1;
  276. dioReadPortByte.value = &state;
  277. dwResult = DRV_DioReadPortByte( m_hDevice, &dioReadPortByte );
  278. if( dwResult != SUCCESS )
  279. {
  280. TCHAR pErrorMessage[MAX_PATH];
  281. DRV_GetErrorMessage( dwResult, pErrorMessage );
  282. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgAdvantechPCI1762::SetDirectOutputAll"), _T("DRV_DioReadPortByte for second part failed with <%s>"), pErrorMessage );
  283. return FALSE;
  284. }
  285. *pState |= (DWORD)(state << 8);
  286. return TRUE;
  287. }