public void Dispose() { if (_id != 0) { CheckErrorCode(CdioSdk.DioExit(_id)); } }
/// <summary> /// Initialize Cdio device /// </summary> /// <returns></returns> public void Init() { var pnt = Marshal.AllocHGlobal(Marshal.SizeOf(sizeof(short))); CheckErrorCode(CdioSdk.DioInit("DIO000", pnt)); _id = Marshal.ReadInt16(pnt); }
public void GetMaxPorts(out short inputPorts, out short outputPorts) { var inPnt = Marshal.AllocHGlobal(Marshal.SizeOf(sizeof(short))); var outPnt = Marshal.AllocHGlobal(Marshal.SizeOf(sizeof(short))); CheckErrorCode(CdioSdk.DioGetMaxPorts(_id, inPnt, outPnt)); inputPorts = Marshal.ReadInt16(inPnt); outputPorts = Marshal.ReadInt16(outPnt); }
private void CheckErrorCode(long errorCode) { if (errorCode != 0) { var errorString = new StringBuilder(256); CdioSdk.DioGetErrorString(errorCode, errorString); throw new CdioDeviceException(errorCode, errorString.ToString()); } }
public void SetTrigger(short bitNo, CdioTriggerTypeEnum triggerType, int pollingInterval) { CheckErrorCode(CdioSdk.DioSetTrgEvent(_id, bitNo, (short)triggerType, pollingInterval)); }
public void SetTriggerCallback(TriggerCallback callback) { CheckErrorCode(CdioSdk.DioSetTrgCallBackProc(_id, new CdioSdk.TrgCallBack((short id, short message, long wParam, long lParam, IntPtr userData1) => { callback((short)wParam, (CdioTriggerTypeEnum)lParam); }), IntPtr.Zero)); }