CdioCs.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. //============================================================-
  2. // CDIOCS.CS
  3. // Class file for CONTEC Digital I/O device
  4. // CONTEC.Co.,Ltd.
  5. //============================================================-
  6. using System;
  7. using System.Runtime.InteropServices;
  8. public enum CdioConst
  9. {
  10. //-------------------------------------------------
  11. // Type definition
  12. //-------------------------------------------------
  13. DEVICE_TYPE_ISA = 0, // ISA or C bus
  14. DEVICE_TYPE_PC = 1, // PCI bus
  15. DEVICE_TYPE_PCMCIA = 2, // PCMCIA
  16. DEVICE_TYPE_USB = 3, // USB
  17. DEVICE_TYPE_FIT = 4, // FIT
  18. DEVICE_TYPE_CARDBUS = 5, // CardBus
  19. //-------------------------------------------------
  20. // Parameters
  21. //-------------------------------------------------
  22. // I/O(for Sample)
  23. DIO_MAX_ACCS_PORTS = 256,
  24. // DioNotifyInt:Logic
  25. DIO_INT_NONE = 0,
  26. DIO_INT_RISE = 1,
  27. DIO_INT_FALL = 2,
  28. // DioNotifyTrg:TrgKind
  29. DIO_TRG_RISE = 1,
  30. DIO_TRG_FALL = 2,
  31. // Message
  32. DIOM_INTERRUPT = 0x1300,
  33. DIOM_TRIGGER = 0x1340,
  34. DIO_DMM_STOP = 0x1350,
  35. DIO_DMM_COUNT = 0x1360,
  36. // Device Information
  37. IDIO_DEVICE_TYPE = 0, // device type. Param1:short
  38. IDIO_NUMBER_OF_8255 = 1, // Number of 8255 chip. Param1:int
  39. IDIO_IS_8255_BOARD = 2, // Is 8255 board? Param1:BOOL(True/False)
  40. IDIO_NUMBER_OF_DI_BIT = 3, // Number of digital input bit. Param1:int
  41. IDIO_NUMBER_OF_DO_BIT = 4, // Number of digital outout bit. Param1:int
  42. IDIO_NUMBER_OF_DI_PORT = 5, // Number of digital input port. Param1:int
  43. IDIO_NUMBER_OF_DO_PORT = 6, // Number of digital output port. Param1:int
  44. IDIO_IS_POSITIVE_LOGIC = 7, // Is positive logic? Param1:BOOL(True/False)
  45. IDIO_IS_ECHO_BACK = 8, // Can echo back output port? Param1:BOOL(True/False)
  46. IDIO_IS_DIRECTION = 9, // Can DioSetIoDirection function be used? Param1:int(1:true, 0:false)
  47. IDIO_IS_FILTER = 10, // Can digital filter be used? Param1:int(1:true, 0:false)
  48. IDIO_NUMBER_OF_INT_BIT = 11, // Number of interrupt bit. Param1:short
  49. // DM
  50. // Direction
  51. PI_32 = 1,
  52. PO_32 = 2,
  53. PIO_1616 = 3,
  54. DIODM_DIR_IN = 0x1,
  55. DIODM_DIR_OUT = 0x2,
  56. // Start
  57. DIODM_START_SOFT = 1,
  58. DIODM_START_EXT_RISE = 2,
  59. DIODM_START_EXT_FALL = 3,
  60. DIODM_START_PATTERN = 4,
  61. DIODM_START_EXTSIG_1 = 5,
  62. DIODM_START_EXTSIG_2 = 6,
  63. DIODM_START_EXTSIG_3 = 7,
  64. // Clock
  65. DIODM_CLK_CLOCK = 1,
  66. DIODM_CLK_EXT_TRG = 2,
  67. DIODM_CLK_HANDSHAKE = 3,
  68. DIODM_CLK_EXTSIG_1 = 4,
  69. DIODM_CLK_EXTSIG_2 = 5,
  70. DIODM_CLK_EXTSIG_3 = 6,
  71. // Internal Clock
  72. DIODM_TIM_UNIT_S = 1,
  73. DIODM_TIM_UNIT_MS = 2,
  74. DIODM_TIM_UNIT_US = 3,
  75. DIODM_TIM_UNIT_NS = 4,
  76. // Stop
  77. DIODM_STOP_SOFT = 1,
  78. DIODM_STOP_EXT_RISE = 2,
  79. DIODM_STOP_EXT_FALL = 3,
  80. DIODM_STOP_NUM = 4,
  81. DIODM_STOP_EXTSIG_1 = 5,
  82. DIODM_STOP_EXTSIG_2 = 6,
  83. DIODM_STOP_EXTSIG_3 = 7,
  84. // ExtSig
  85. DIODM_EXT_START_SOFT_IN = 1,
  86. DIODM_EXT_STOP_SOFT_IN = 2,
  87. DIODM_EXT_CLOCK_IN = 3,
  88. DIODM_EXT_EXT_TRG_IN = 4,
  89. DIODM_EXT_START_EXT_RISE_IN = 5,
  90. DIODM_EXT_START_EXT_FALL_IN = 6,
  91. DIODM_EXT_START_PATTERN_IN = 7,
  92. DIODM_EXT_STOP_EXT_RISE_IN = 8,
  93. DIODM_EXT_STOP_EXT_FALL_IN = 9,
  94. DIODM_EXT_CLOCK_ERROR_IN = 10,
  95. DIODM_EXT_HANDSHAKE_IN = 11,
  96. DIODM_EXT_TRNSNUM_IN = 12,
  97. DIODM_EXT_START_SOFT_OUT = 101,
  98. DIODM_EXT_STOP_SOFT_OUT = 102,
  99. DIODM_EXT_CLOCK_OUT = 103,
  100. DIODM_EXT_EXT_TRG_OUT = 104,
  101. DIODM_EXT_START_EXT_RISE_OUT= 105,
  102. DIODM_EXT_START_EXT_FALL_OUT= 106,
  103. DIODM_EXT_STOP_EXT_RISE_OUT = 107,
  104. DIODM_EXT_STOP_EXT_FALL_OUT = 108,
  105. DIODM_EXT_CLOCK_ERROR_OUT = 109,
  106. DIODM_EXT_HANDSHAKE_OUT = 110,
  107. DIODM_EXT_TRNSNUM_OUT = 111,
  108. // Status
  109. DIODM_STATUS_BMSTOP = 0x1,
  110. DIODM_STATUS_PIOSTART = 0x2,
  111. DIODM_STATUS_PIOSTOP = 0x4,
  112. DIODM_STATUS_TRGIN = 0x8,
  113. DIODM_STATUS_OVERRUN = 0x10,
  114. // Error
  115. DIODM_STATUS_FIFOEMPTY = 0x1,
  116. DIODM_STATUS_FIFOFULL = 0x2,
  117. DIODM_STATUS_SGOVERIN = 0x4,
  118. DIODM_STATUS_TRGERR = 0x8,
  119. DIODM_STATUS_CLKERR = 0x10,
  120. DIODM_STATUS_SLAVEHALT = 0x20,
  121. DIODM_STATUS_MASTERHALT = 0x40,
  122. // Reset
  123. DIODM_RESET_FIFO_IN = 0x02,
  124. DIODM_RESET_FIFO_OUT = 0x04,
  125. // Buffer Ring
  126. DIODM_WRITE_ONCE = 0,
  127. DIODM_WRITE_RING = 1,
  128. //-------------------------------------------------
  129. // Error codes
  130. //-------------------------------------------------
  131. // Initialize Error
  132. // Common
  133. DIO_ERR_SUCCESS = 0, // normal completed
  134. DIO_ERR_INI_RESOURCE = 1, // invalid resource reference specified
  135. DIO_ERR_INI_INTERRUPT = 2, // invalid interrupt routine registered
  136. DIO_ERR_INI_MEMORY = 3, // invalid memory allocationed
  137. DIO_ERR_INI_REGISTRY = 4, // invalid registry accesse
  138. DIO_ERR_SYS_RECOVERED_FROM_STANDBY = 7, // Execute DioResetDevice function because the device has recovered from standby mode.
  139. DIO_ERR_INI_NOT_FOUND_SYS_FILE = 8, // Because the Cdio.sys file is not found, it is not possible to initialize it.
  140. DIO_ERR_INI_DLL_FILE_VERSION = 9, // Because version information on the Cdio.dll file cannot be acquired, it is not possible to initialize it.
  141. DIO_ERR_INI_SYS_FILE_VERSION = 10, // Because version information on the Cdio.sys file cannot be acquired, it is not possible to initialize it.
  142. DIO_ERR_INI_NO_MATCH_DRV_VERSION = 11, // Because version information on Cdio.dll and Cdio.sys is different, it is not possible to initialize it.
  143. // DLL Error
  144. // Common
  145. DIO_ERR_DLL_DEVICE_NAME = 10000, // invalid device name specified.
  146. DIO_ERR_DLL_INVALID_ID = 10001, // invalid ID specified.
  147. DIO_ERR_DLL_CALL_DRIVER = 10002, // not call the driver.(Invalid device I/O controller)
  148. DIO_ERR_DLL_CREATE_FILE = 10003, // not create the file.(Invalid CreateFile)
  149. DIO_ERR_DLL_CLOSE_FILE = 10004, // not close the file.(Invalid CloseFile)
  150. DIO_ERR_DLL_CREATE_THREAD = 10005, // not create the thread.(Invalid CreateThread)
  151. DIO_ERR_INFO_INVALID_DEVICE = 10050, // invalid device information specified .Please check the spell.
  152. DIO_ERR_INFO_NOT_FIND_DEVICE = 10051, // not find the available device
  153. DIO_ERR_INFO_INVALID_INFOTYPE = 10052, // specified device information type beyond the limit
  154. // DIO
  155. DIO_ERR_DLL_BUFF_ADDRESS = 10100, // invalid data buffer address
  156. DIO_ERR_DLL_HWND = 10200, // window handle beyond the limit
  157. DIO_ERR_DLL_TRG_KIND = 10300, // trigger kind beyond the limit
  158. // SYS Error
  159. // Common
  160. DIO_ERR_SYS_MEMORY = 20000, // not secure memory
  161. DIO_ERR_SYS_NOT_SUPPORTED = 20001, // this board couldn't use this function
  162. DIO_ERR_SYS_BOARD_EXECUTING = 20002, // board is behaving, not execute
  163. DIO_ERR_SYS_USING_OTHER_PROCESS = 20003, // other process is using the device, not execute
  164. STATUS_SYS_USB_CRC = 20020, // the last data packet received from end point exist CRC error
  165. STATUS_SYS_USB_BTSTUFF = 20021, // the last data packet received from end point exist bit stuffing offense error
  166. STATUS_SYS_USB_DATA_TOGGLE_MISMATCH = 20022, // the last data packet received from end point exist toggle packet mismatch error
  167. STATUS_SYS_USB_STALL_PID = 20023, // end point return STALL packet identifier
  168. STATUS_SYS_USB_DEV_NOT_RESPONDING = 20024, // device don't respond to token(IN), don't support handshake
  169. STATUS_SYS_USB_PID_CHECK_FAILURE = 20025,
  170. STATUS_SYS_USB_UNEXPECTED_PID = 20026, // invalid packet identifier received
  171. STATUS_SYS_USB_DATA_OVERRUN = 20027, // end point return data quantity overrun
  172. STATUS_SYS_USB_DATA_UNDERRUN = 20028, // end point return data quantity underrun
  173. STATUS_SYS_USB_BUFFER_OVERRUN = 20029, // IN transmit specified buffer overrun
  174. STATUS_SYS_USB_BUFFER_UNDERRUN = 20030, // OUT transmit specified buffer underrun
  175. STATUS_SYS_USB_ENDPOINT_HALTED = 20031, // end point status is STALL, not transmit
  176. STATUS_SYS_USB_NOT_FOUND_DEVINFO = 20032, // not found device information
  177. STATUS_SYS_USB_ACCESS_DENIED = 20033, // Access denied
  178. STATUS_SYS_USB_INVALID_HANDLE = 20034, // Invalid handle
  179. // DIO
  180. DIO_ERR_SYS_PORT_NO = 20100, // board No. beyond the limit
  181. DIO_ERR_SYS_PORT_NUM = 20101, // board number beyond the limit
  182. DIO_ERR_SYS_BIT_NO = 20102, // bit No. beyond the limit
  183. DIO_ERR_SYS_BIT_NUM = 20103, // bit number beyond the limit
  184. DIO_ERR_SYS_BIT_DATA = 20104, // bit data beyond the limit of 0 to 1
  185. DIO_ERR_SYS_INT_BIT = 20200, // interrupt bit beyond the limit
  186. DIO_ERR_SYS_INT_LOGIC = 20201, // interrupt logic beyond the limit
  187. DIO_ERR_SYS_TIM = 20300, // timer value beyond the limit
  188. DIO_ERR_SYS_FILTER = 20400, // filter number beyond the limit
  189. DIO_ERR_SYS_IODIRECTION = 20500, // Direction value is out of range
  190. // DM
  191. DIO_ERR_SYS_SIGNAL = 21000, // Usable signal is outside the setting range.
  192. DIO_ERR_SYS_START = 21001, // Usable start conditions are outside the setting range.
  193. DIO_ERR_SYS_CLOCK = 21002, // Clock conditions are outside the setting range.
  194. DIO_ERR_SYS_CLOCK_VAL = 21003, // Clock value is outside the setting range.
  195. DIO_ERR_SYS_CLOCK_UNIT = 21004, // Clock value unit is outside the setting range.
  196. DIO_ERR_SYS_STOP = 21005, // Stop conditions are outside the setting range.
  197. DIO_ERR_SYS_STOP_NUM = 21006, // Stop number is outside the setting range.
  198. DIO_ERR_SYS_RESET = 21007, // Contents of reset are outside the setting range.
  199. DIO_ERR_SYS_LEN = 21008, // Data number is outside the setting range.
  200. DIO_ERR_SYS_RING = 21009, // Buffer repetition use setup is outside the setting range.
  201. DIO_ERR_SYS_COUNT = 21010, // Data transmission number is outside the setting range.
  202. DIO_ERR_DM_BUFFER = 21100, // Buffer was too large and has not secured.
  203. DIO_ERR_DM_LOCK_MEMORY = 21101, // Memory has not been locked.
  204. DIO_ERR_DM_PARAM = 21102, // Parameter error
  205. DIO_ERR_DM_SEQUENCE = 21103 // Procedure error of execution
  206. }
  207. namespace CdioCs
  208. {
  209. unsafe public delegate void PINTCALLBACK(short Id, int wParam, int lParam, void *Param);
  210. unsafe public delegate void PTRGCALLBACK(short Id, int wParam, int lParam, void *Param);
  211. unsafe public delegate void PDMCOUNTCALLBACK(short Id, int wParam, int lParam, void *Param);
  212. unsafe public delegate void PDMSTOPCALLBACK(short Id, int wParam, int lParam, void *Param);
  213. public class Cdio
  214. {
  215. // Definition of common functions
  216. [DllImport("cdio.dll")] static extern int DioInit(string DeviceName, ref short Id);
  217. [DllImport("cdio.dll")] static extern int DioExit(short Id);
  218. [DllImport("cdio.dll")] static extern int DioResetDevice(short Id);
  219. [DllImport("cdio.dll")] static extern int DioGetErrorString(int ErrorCode, System.Text.StringBuilder ErrorString);
  220. // Digital filter functions
  221. [DllImport("cdio.dll")] static extern int DioSetDigitalFilter(short Id, short FilterValue);
  222. [DllImport("cdio.dll")] static extern int DioGetDigitalFilter(short Id, ref short FilterValue);
  223. // I/O Direction functions
  224. [DllImport("cdio.dll")] static extern int DioSetIoDirection(short Id, uint dwDir);
  225. [DllImport("cdio.dll")] static extern int DioGetIoDirection(short Id, ref uint dwDir);
  226. [DllImport("cdio.dll")] static extern int DioSetIoDirectionEx(short Id, uint dwDir);
  227. [DllImport("cdio.dll")] static extern int DioGetIoDirectionEx(short Id, ref uint dwDir);
  228. [DllImport("cdio.dll")] static extern int DioSet8255Mode(short Id, short ChipNo, short CtrlWord);
  229. [DllImport("cdio.dll")] static extern int DioGet8255Mode(short Id, short ChipNo, ref short CtrlWord);
  230. // Simple I/O functions
  231. [DllImport("cdio.dll")] static extern int DioInpByte(short Id, short PortNo, ref byte Data);
  232. [DllImport("cdio.dll")] static extern int DioInpBit(short Id, short BitNo, ref byte Data);
  233. [DllImport("cdio.dll")] static extern int DioOutByte(short Id, short PortNo, byte Data);
  234. [DllImport("cdio.dll")] static extern int DioOutBit(short Id, short BitNo, byte Data);
  235. [DllImport("cdio.dll")] static extern int DioEchoBackByte(short Id, short PortNo, ref byte Data);
  236. [DllImport("cdio.dll")] static extern int DioEchoBackBit(short Id, short BitNo, ref byte Data);
  237. // Multiple I/O functions
  238. [DllImport("cdio.dll")] static extern int DioInpMultiByte(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] PortNo, short PortNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
  239. [DllImport("cdio.dll")] static extern int DioInpMultiBit(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] BitNo, short BitNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
  240. [DllImport("cdio.dll")] static extern int DioOutMultiByte(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] PortNo, short PortNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
  241. [DllImport("cdio.dll")] static extern int DioOutMultiBit(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] BitNo, short BitNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
  242. [DllImport("cdio.dll")] static extern int DioEchoBackMultiByte(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] PortNo, short PortNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
  243. [DllImport("cdio.dll")] static extern int DioEchoBackMultiBit(short Id, [MarshalAs(UnmanagedType.LPArray)] short[] BitNo, short BitNum, [MarshalAs(UnmanagedType.LPArray)] byte[] Data);
  244. // Interrupt functions
  245. [DllImport("cdio.dll")] static extern int DioNotifyInterrupt(short Id, short IntBit, short Logic, int hWnd);
  246. [DllImport("cdio.dll")] unsafe static extern int DioSetInterruptCallBackProc(short Id, PINTCALLBACK pIntCallBack, void *Param);
  247. // Trigger functions
  248. [DllImport("cdio.dll")] static extern int DioNotifyTrg(short Id, short TrgBit, short TrgKind, int Tim, int hWnd);
  249. [DllImport("cdio.dll")] static extern int DioStopNotifyTrg(short Id, short TrgBit);
  250. [DllImport("cdio.dll")] static extern int DioSetTrgCallBackProc(short Id, PTRGCALLBACK CallBackProc, ref int Param);
  251. // Information functions
  252. [DllImport("cdio.dll")] static extern int DioGetDeviceInfo(string Device, short InfoType, ref int Param1, ref int Param2, ref int Param3);
  253. [DllImport("cdio.dll")] static extern int DioQueryDeviceName(short Index, System.Text.StringBuilder DeviceName, System.Text.StringBuilder Device);
  254. [DllImport("cdio.dll")] static extern int DioGetDeviceType(string Device, ref short DeviceType);
  255. [DllImport("cdio.dll")] static extern int DioGetMaxPorts(short Id, ref short InPortNum, ref short OutPortNum);
  256. //dm functions
  257. [DllImport("cdio.DLL")] static extern int DioDmSetDirection(short Id, short Direction);
  258. [DllImport("cdio.DLL")] static extern int DioDmGetDirection(short Id, ref short Direction);
  259. [DllImport("cdio.DLL")] static extern int DioDmSetStandAlone(short Id);
  260. [DllImport("cdio.DLL")] static extern int DioDmSetMaster(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt);
  261. [DllImport("cdio.DLL")] static extern int DioDmSetSlave(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt);
  262. [DllImport("cdio.DLL")] static extern int DioDmSetStartTrigger(short Id, short Direction, short Start);
  263. [DllImport("cdio.DLL")] static extern int DioDmSetStartPattern(short Id, uint Pattern, uint Mask);
  264. [DllImport("cdio.DLL")] static extern int DioDmSetClockTrigger(short Id, short Direction, short Clock);
  265. [DllImport("cdio.DLL")] static extern int DioDmSetInternalClock(short Id, short Direction, uint Clock, short Unit);
  266. [DllImport("cdio.DLL")] static extern int DioDmSetStopTrigger(short Id, short Direction, short Stop);
  267. [DllImport("cdio.DLL")] static extern int DioDmSetStopNumber(short Id, short Direction, uint StopNumber);
  268. [DllImport("cdio.DLL")] static extern int DioDmFifoReset(short Id, short Reset);
  269. [DllImport("cdio.DLL")] static extern int DioDmSetBuffer(short Id, short Direction, IntPtr Buffer, uint Length, short IsRing);
  270. [DllImport("cdio.DLL")] static extern int DioDmSetTransferStartWait(short Id, short Time);
  271. [DllImport("cdio.DLL")] static extern int DioDmTransferStart(short Id, short Direction);
  272. [DllImport("cdio.DLL")] static extern int DioDmTransferStop(short Id, short Direction);
  273. [DllImport("cdio.DLL")] static extern int DioDmGetStatus(short Id, short Direction, ref uint Status, ref uint Err);
  274. [DllImport("cdio.DLL")] static extern int DioDmGetCount(short Id, short Direction, ref uint Count, ref uint Carry);
  275. [DllImport("cdio.DLL")] static extern int DioDmGetWritePointer(short Id, short Direction, ref uint WritePointer, ref uint Count, ref uint Carry);
  276. [DllImport("cdio.DLL")] static extern int DioDmSetStopEvent(short Id, short Direction, int hWnd);
  277. [DllImport("cdio.DLL")] unsafe static extern int DioDmSetStopCallBackProc(short Id, PDMSTOPCALLBACK CallBackProc, void *Param);
  278. [DllImport("cdio.DLL")] static extern int DioDmSetCountEvent(short Id, short Direction, uint Count, int hWnd);
  279. [DllImport("cdio.DLL")] unsafe static extern int DioDmSetCountCallBackProc(short Id, PDMCOUNTCALLBACK CallBackProc, void *Param);
  280. // Demo Device I/O functions
  281. [DllImport("cdio.dll")] static extern int DioSetDemoByte(short Id, short PortNo, byte Data);
  282. [DllImport("cdio.dll")] static extern int DioSetDemoBit(short Id, short BitNo, byte Data);
  283. // Constructor
  284. public Cdio()
  285. {
  286. }
  287. // Description of common functions
  288. public int Init(string DeviceName, out short Id)
  289. {
  290. Id = 0;
  291. int ret = DioInit(DeviceName, ref Id);
  292. return ret;
  293. }
  294. public int Exit(short Id)
  295. {
  296. int ret = DioExit(Id);
  297. return ret;
  298. }
  299. public int ResetDevice(short Id)
  300. {
  301. int ret = DioResetDevice(Id);
  302. return ret;
  303. }
  304. public int GetErrorString(int ErrorCode, out string ErrorString)
  305. {
  306. ErrorString = new String('0', 1);
  307. System.Text.StringBuilder errorstring = new System.Text.StringBuilder(256);
  308. int ret = DioGetErrorString(ErrorCode, errorstring);
  309. if(ret == 0)
  310. {
  311. ErrorString = errorstring.ToString();
  312. }
  313. return ret;
  314. }
  315. // Digital filter functions
  316. public int SetDigitalFilter(short Id, short FilterValue)
  317. {
  318. int ret = DioSetDigitalFilter(Id, FilterValue);
  319. return ret;
  320. }
  321. public int GetDigitalFilter(short Id, out short FilterValue)
  322. {
  323. FilterValue = 0;
  324. int ret = DioGetDigitalFilter(Id, ref FilterValue);
  325. return ret;
  326. }
  327. // I/O Direction functions
  328. public int SetIoDirection(short Id, uint dwDir)
  329. {
  330. int ret = DioSetIoDirection(Id, dwDir);
  331. return ret;
  332. }
  333. public int GetIoDirection(short Id, out uint dwDir)
  334. {
  335. dwDir = 0;
  336. int ret = DioGetIoDirection(Id, ref dwDir);
  337. return ret;
  338. }
  339. public int Set8255Mode(short Id, short ChipNo, short CtrlWord)
  340. {
  341. int ret = DioSet8255Mode(Id, ChipNo, CtrlWord);
  342. return ret;
  343. }
  344. public int Get8255Mode(short Id, short ChipNo, out short CtrlWord)
  345. {
  346. CtrlWord = 0;
  347. int ret = DioGet8255Mode(Id, ChipNo, ref CtrlWord);
  348. return ret;
  349. }
  350. public int SetIoDirectionEx(short Id, uint dwDir)
  351. {
  352. int ret = DioSetIoDirectionEx(Id, dwDir);
  353. return ret;
  354. }
  355. public int GetIoDirectionEx(short Id, out uint dwDir)
  356. {
  357. dwDir = 0;
  358. int ret = DioGetIoDirectionEx(Id, ref dwDir);
  359. return ret;
  360. }
  361. // Simple I/O functions
  362. public int InpByte(short Id, short PortNo, out byte Data)
  363. {
  364. Data = 0;
  365. int ret = DioInpByte(Id, PortNo, ref Data);
  366. return ret;
  367. }
  368. public int InpBit(short Id, short BitNo, out byte Data)
  369. {
  370. Data = 0;
  371. int ret = DioInpBit(Id, BitNo, ref Data);
  372. return ret;
  373. }
  374. public int OutByte(short Id, short PortNo, byte Data)
  375. {
  376. int ret = DioOutByte(Id, PortNo, Data);
  377. return ret;
  378. }
  379. public int OutBit(short Id, short BitNo, byte Data)
  380. {
  381. int ret = DioOutBit(Id, BitNo, Data);
  382. return ret;
  383. }
  384. public int EchoBackByte(short Id, short PortNo, out byte Data)
  385. {
  386. Data = 0;
  387. int ret = DioEchoBackByte(Id, PortNo, ref Data);
  388. return ret;
  389. }
  390. public int EchoBackBit(short Id, short BitNo, out byte Data)
  391. {
  392. Data = 0;
  393. int ret = DioEchoBackBit(Id, BitNo, ref Data);
  394. return ret;
  395. }
  396. // Multiple I/O functions
  397. public int InpMultiByte(short Id, short[] PortNo, short PortNum, byte[] Data)
  398. {
  399. int ret = DioInpMultiByte(Id, PortNo, PortNum, Data);
  400. return ret;
  401. }
  402. public int InpMultiBit(short Id, short[] BitNo, short BitNum, byte[] Data)
  403. {
  404. int ret = DioInpMultiBit(Id, BitNo, BitNum, Data);
  405. return ret;
  406. }
  407. public int OutMultiByte(short Id, short[] PortNo, short PortNum, byte[] Data)
  408. {
  409. int ret = DioOutMultiByte(Id, PortNo, PortNum, Data);
  410. return ret;
  411. }
  412. public int OutMultiBit(short Id, short[] BitNo, short BitNum, byte[] Data)
  413. {
  414. int ret = DioOutMultiBit(Id, BitNo, BitNum, Data);
  415. return ret;
  416. }
  417. public int EchoBackMultiByte(short Id, short[] PortNo, short PortNum, byte[] Data)
  418. {
  419. int ret = DioEchoBackMultiByte(Id, PortNo, PortNum, Data);
  420. return ret;
  421. }
  422. public int EchoBackMultiBit(short Id, short[] BitNo, short BitNum, byte[] Data)
  423. {
  424. int ret = DioEchoBackMultiBit(Id, BitNo, BitNum, Data);
  425. return ret;
  426. }
  427. // Interrupt functions
  428. public int NotifyInterrupt(short Id, short IntBit, short Logic, int hWnd)
  429. {
  430. int ret = DioNotifyInterrupt(Id, IntBit, Logic, hWnd);
  431. return ret;
  432. }
  433. unsafe public int SetInterruptCallBackProc(short Id, PINTCALLBACK pIntCallBack, void *Param)
  434. {
  435. int ret = DioSetInterruptCallBackProc(Id, pIntCallBack, Param);
  436. return ret;
  437. }
  438. // Trigger functions
  439. public int NotifyTrg(short Id, short TrgBit, short TrgKind, int Tim, int hWnd)
  440. {
  441. int ret = DioNotifyTrg(Id, TrgBit, TrgKind, Tim, hWnd);
  442. return ret;
  443. }
  444. public int StopNotifyTrg(short Id, short TrgBit)
  445. {
  446. int ret = DioStopNotifyTrg(Id, TrgBit);
  447. return ret;
  448. }
  449. public int SetTrgCallBackProc(short Id, PTRGCALLBACK CallBackProc, out int Param)
  450. {
  451. Param = 0;
  452. int ret = DioSetTrgCallBackProc(Id, CallBackProc, ref Param);
  453. return ret;
  454. }
  455. // Information functions
  456. public int GetDeviceInfo(string Device, short InfoType, out int Param1, out int Param2, out int Param3)
  457. {
  458. Param1 = 0;
  459. Param2 = 0;
  460. Param3 = 0;
  461. int ret = DioGetDeviceInfo(Device, InfoType, ref Param1, ref Param2, ref Param3);
  462. return ret;
  463. }
  464. public int QueryDeviceName(short Index, out string DeviceName, out string Device)
  465. {
  466. DeviceName = new String('0', 1);
  467. Device = new String('0', 1);
  468. System.Text.StringBuilder devicename = new System.Text.StringBuilder(256);
  469. System.Text.StringBuilder device = new System.Text.StringBuilder(256);
  470. int ret = DioQueryDeviceName(Index, devicename, device);
  471. if(ret == 0)
  472. {
  473. DeviceName = devicename.ToString();
  474. Device = device.ToString();
  475. }
  476. return ret;
  477. }
  478. public int GetDeviceType(string Device, out short DeviceType)
  479. {
  480. DeviceType = 0;
  481. int ret = DioGetDeviceType(Device, ref DeviceType);
  482. return ret;
  483. }
  484. public int GetMaxPorts(short Id, out short InPortNum, out short OutPortNum)
  485. {
  486. InPortNum = 0;
  487. OutPortNum = 0;
  488. int ret = DioGetMaxPorts(Id, ref InPortNum, ref OutPortNum);
  489. return ret;
  490. }
  491. public int DmSetDirection(short Id, short Direction)
  492. {
  493. int ret = DioDmSetDirection(Id, Direction);
  494. return ret;
  495. }
  496. public int DmGetDirection(short Id, out short Direction)
  497. {
  498. Direction = 0;
  499. int ret = DioDmGetDirection(Id, ref Direction);
  500. return ret;
  501. }
  502. public int DmSetStandAlone(short Id)
  503. {
  504. int ret = DioDmSetStandAlone(Id);
  505. return ret;
  506. }
  507. public int DmSetMaster(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt)
  508. {
  509. int ret = DioDmSetMaster(Id, ExtSig1, ExtSig2, ExtSig3, MasterHalt, SlaveHalt);
  510. return ret;
  511. }
  512. public int DmSetSlave(short Id, short ExtSig1, short ExtSig2, short ExtSig3, short MasterHalt, short SlaveHalt)
  513. {
  514. int ret = DioDmSetSlave(Id, ExtSig1, ExtSig2, ExtSig3, MasterHalt, SlaveHalt);
  515. return ret;
  516. }
  517. public int DmSetStartTrigger(short Id, short Direction, short Start)
  518. {
  519. int ret = DioDmSetStartTrigger(Id, Direction, Start);
  520. return ret;
  521. }
  522. public int DmSetStartPattern(short Id, uint Pattern, uint Mask)
  523. {
  524. int ret = DioDmSetStartPattern(Id, Pattern, Mask);
  525. return ret;
  526. }
  527. public int DmSetClockTrigger(short Id, short Direction, short Clock)
  528. {
  529. int ret = DioDmSetClockTrigger(Id, Direction, Clock);
  530. return ret;
  531. }
  532. public int DmSetInternalClock(short Id, short Direction, uint Clock, short Unit)
  533. {
  534. int ret = DioDmSetInternalClock(Id, Direction, Clock, Unit);
  535. return ret;
  536. }
  537. public int DmSetStopTrigger(short Id, short Direction, short Stop)
  538. {
  539. int ret = DioDmSetStopTrigger(Id, Direction, Stop);
  540. return ret;
  541. }
  542. public int DmSetStopNumber(short Id, short Direction, uint StopNumber)
  543. {
  544. int ret = DioDmSetStopNumber(Id, Direction, StopNumber);
  545. return ret;
  546. }
  547. public int DmFifoReset(short Id, short Reset)
  548. {
  549. int ret = DioDmFifoReset(Id, Reset);
  550. return ret;
  551. }
  552. public int DmSetBuffer(short Id, short Direction, IntPtr Buffer, uint Length, short IsRing)
  553. {
  554. int ret = DioDmSetBuffer(Id, Direction, Buffer, Length, IsRing);
  555. return ret;
  556. }
  557. public int DmSetTransferStartWait(short Id, short Time)
  558. {
  559. int ret = DioDmSetTransferStartWait(Id, Time);
  560. return ret;
  561. }
  562. public int DmTransferStart(short Id, short Direction)
  563. {
  564. int ret = DioDmTransferStart(Id, Direction);
  565. return ret;
  566. }
  567. public int DmTransferStop(short Id, short Direction)
  568. {
  569. int ret = DioDmTransferStop(Id, Direction);
  570. return ret;
  571. }
  572. public int DmGetStatus(short Id, short Direction, out uint Status, out uint Err)
  573. {
  574. Status = 0;
  575. Err = 0;
  576. int ret = DioDmGetStatus(Id, Direction, ref Status, ref Err);
  577. return ret;
  578. }
  579. public int DmGetCount(short Id, short Direction, out uint Count, out uint Carry)
  580. {
  581. Count = 0;
  582. Carry = 0;
  583. int ret = DioDmGetCount(Id, Direction, ref Count, ref Carry);
  584. return ret;
  585. }
  586. public int DmGetWritePointer(short Id, short Direction, out uint WritePointer, out uint Count, out uint Carry)
  587. {
  588. WritePointer = 0;
  589. Count = 0;
  590. Carry = 0;
  591. int ret = DioDmGetWritePointer(Id, Direction, ref WritePointer, ref Count, ref Carry);
  592. return ret;
  593. }
  594. public int DmSetStopEvent(short Id, short Direction, int hWnd)
  595. {
  596. int ret = DioDmSetStopEvent(Id, Direction, hWnd);
  597. return ret;
  598. }
  599. unsafe public int DmSetStopCallBackProc(short Id, PDMSTOPCALLBACK CallBackProc, void *Param)
  600. {
  601. int ret = DioDmSetStopCallBackProc(Id, CallBackProc, Param);
  602. return ret;
  603. }
  604. public int DmSetCountEvent(short Id, short Direction, uint Count, int hWnd)
  605. {
  606. int ret = DioDmSetCountEvent(Id, Direction, Count, hWnd);
  607. return ret;
  608. }
  609. unsafe public int DmSetCountCallBackProc(short Id, PDMCOUNTCALLBACK CallBackProc, void *Param)
  610. {
  611. int ret = DioDmSetCountCallBackProc(Id, CallBackProc, Param);
  612. return ret;
  613. }
  614. public int SetDemoByte(short Id, short PortNo, byte Data)
  615. {
  616. int ret = DioSetDemoByte(Id, PortNo, Data);
  617. return ret;
  618. }
  619. public int SetDemoBit(short Id, short BitNo, byte Data)
  620. {
  621. int ret = DioSetDemoBit(Id, BitNo, Data);
  622. return ret;
  623. }
  624. }
  625. }