예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bOpen"></param>
 /// <returns></returns>
 public static bool IICClose(bool bOpen)
 {
     // 如果打开则关闭
     if (bOpen)
     {
         USBIOComm.USBIO_CloseDevice(0);
         return(false);
     }
     return(true);
 }
예제 #5
0
        public static bool InitIO()
        {
            _hIOHandle = USBIOComm.USB2IO_Open(1);

            if (_hIOHandle == USBIOComm.INVALID_HANDLE_VALUE)
            {
                return(false);
            }
            return(true);
        }
예제 #6
0
 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
     }
 }
예제 #7
0
        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);
        }
예제 #8
0
 public static bool DeInitIO()
 {
     USBIOComm.USB2IO_Close(_hIOHandle);
     return(true);
 }