/// <summary> /// 打开IIC /// </summary> /// <returns></returns> public static bool IICOpen(bool bOpen) { // 如果已经打开IIC, 则返回false if (bOpen) { return(false); } // 尝试打开IIC设备 uint val_Handle; try { val_Handle = USBIOComm.USBIO_OpenDevice(0); } catch { // Please check if the file \"USBIOX.DLL\" and \"usbio.dll\" are in the root directory return(false); } if (val_Handle == USBIOComm.INVALID_HANDLE_VALUE || val_Handle == 0) { // IIC detected failed! return(false); } SetIICSpeed(true); // 打开高速模式, true为高速, false为低速 return(true); }
public static bool IICWriteRead(UInt32 iIndex, UInt32 iWriteLength, UInt32 iWriteBuffer, UInt32 iReadLength, UInt32 iReadBuffer) { bool bResult = USBIOComm.USBIO_StreamI2C(iIndex, iWriteLength, iWriteBuffer, iReadLength, iReadBuffer); return(bResult); }
private static bool IOConfig(int iPin, USBIOComm.IO_Cfg ioconfig) { bool bReturn = true; //if (!g_bIOOpened) // return false; if ((iPin < 1) || (iPin > 10)) { return(false); } switch (ioconfig) { case USBIOComm.IO_Cfg.IO_In: USBIOComm.USB2IO_SetIoCfg(_hIOHandle, iPin, 0); break; case USBIOComm.IO_Cfg.IO_OD: USBIOComm.USB2IO_SetIoCfg(_hIOHandle, iPin, 2); break; case USBIOComm.IO_Cfg.IO_Push: USBIOComm.USB2IO_SetIoCfg(_hIOHandle, iPin, 3); break; default: bReturn = false; break; } return(bReturn); }
/// <summary> /// /// </summary> /// <param name="bOpen"></param> /// <returns></returns> public static bool IICClose(bool bOpen) { // 如果打开则关闭 if (bOpen) { USBIOComm.USBIO_CloseDevice(0); return(false); } return(true); }
public static bool InitIO() { _hIOHandle = USBIOComm.USB2IO_Open(1); if (_hIOHandle == USBIOComm.INVALID_HANDLE_VALUE) { return(false); } return(true); }
public static void SetIICSpeed(bool bFast) { if (bFast) { USBIOComm.USBIO_SetStream(0, 0x81); // 0x81, 高速100KHz, 0X80, 低速20KHz } else { USBIOComm.USBIO_SetStream(0, 0x80); // 0x81, 高速100KHz, 0X80, 低速20KHz } }
private static bool IOSet(int iPin, int IOValue) { bool bReturn = true; int iReturn = 0; //if (!g_bIOOpened) // return false; iReturn = USBIOComm.USB2IO_SetIoOut(_hIOHandle, iPin, IOValue != 0 ? 1 : 0); if (iReturn != 0) { bReturn = false; } return(bReturn); }
public static bool DeInitIO() { USBIOComm.USB2IO_Close(_hIOHandle); return(true); }