Example #1
0
        /// <summary>
        /// Disconnects from device.
        /// </summary>
        public Task Disconnect()
        {
            if (this.ChannelHandle == IntPtr.Zero)
            {
                return(Task.CompletedTask);
            }

            // Close the channel
            return(Task.Run(() =>
            {
                var status = NativeMethods_I2C.I2C_CloseChannel(this.ChannelHandle);
                this.DeviceNode = null;
                this.ChannelHandle = IntPtr.Zero;
                if (status != FTDI.FT_STATUS.FT_OK)
                {
                    throw new CommunicationException("Unable to close I2C channel. (Status: " + status + ")");
                }
            }));
        }