Ejemplo n.º 1
0
        private void InitLibAndHandle()
        {
            FtResult result;

            if (_handle != IntPtr.Zero)
            {
                return;
            }


            LibMpsse.Init();
            result = LibMpsseSpi.SPI_OpenChannel(_spiConfig.ChannelIndex, out _handle);

            CheckResult(result);

            if (_handle == IntPtr.Zero)
            {
                throw new SpiChannelNotConnectedException(FtResult.InvalidHandle);
            }

            result = LibMpsseSpi.SPI_InitChannel(_handle, ref _cfg);

            CheckResult(result);

            _currentGlobalConfig = _cfg;
        }
Ejemplo n.º 2
0
        void InitLibAndHandle()
        {
            FtResult result;

            if (_handle != IntPtr.Zero)
            {
                return;
            }

            LibMpsse.Init();

            var num_channels = 0;

            var channels = LibMpsseI2C.I2C_GetNumChannels(out num_channels);

            CheckResult(channels);

            //if (num_channels > 0)
            //{
            //    for (var i = 0; i < num_channels; i++)
            //    {
            //        FtDeviceInfo cInfo;
            //        var channelInfoStatus = LibMpsseI2C.I2C_GetChannelInfo(i, out cInfo);
            //        CheckResult(channelInfoStatus);
            //        Debug.WriteLine($"Flags: {cInfo.Flags}");
            //        Debug.WriteLine($"Type: {cInfo.Type}");
            //        Debug.WriteLine($"ID: {cInfo.ID}");
            //        Debug.WriteLine($"LocId: {cInfo.LocId}");
            //        Debug.WriteLine($"SerialNumber: {cInfo.SerialNumber}");
            //        Debug.WriteLine($"Description: {cInfo.Description}");
            //        Debug.WriteLine($"ftHandle: {cInfo.ftHandle}");
            //    }
            //}

            result = LibMpsseI2C.I2C_OpenChannel(_i2cConfig.ChannelIndex, out _handle);

            CheckResult(result);

            if (_handle == IntPtr.Zero)
            {
                throw new I2CChannelNotConnectedException(FtResult.InvalidHandle);
            }

            result = LibMpsseI2C.I2C_InitChannel(_handle, ref _cfg);

            CheckResult(result);
            _currentGlobalConfig = _cfg;
        }
        protected void InitLibAndHandle(int channelIndex)
        {
            if (_i2cHandle != IntPtr.Zero)
            {
                return;
            }

            LibMpsse.Init();

            var config = Config;

            var result = CheckResult(LibMpsse.I2C_OpenChannel(channelIndex, out _i2cHandle));

            if (_i2cHandle == IntPtr.Zero)
            {
                throw new I2CNotConnectedException(FtdiMpsseI2CResult.InvalidAddress);
            }


            result = CheckResult(LibMpsse.I2C_InitChannel(_i2cHandle, ref config));

            Config = config;
        }