public int ThermTransact(Ads1118TemperatureSensorMode mode, Ads1118InputMultiplexer channel)
        {
            int ret;

            using (var transferBuffer = this.spi1.CreateTransferBuffer(4, SpiTransferMode.ReadWrite))
            {
                if (mode == Ads1118TemperatureSensorMode.ExternalSignal && channel == Ads1118InputMultiplexer.Ain0Ain1)
                {
                    transferBuffer.Tx[0] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[1] = Convert.ToByte(0x8a);
                    transferBuffer.Tx[2] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[3] = Convert.ToByte(0x8a);
                }
                else if (mode == Ads1118TemperatureSensorMode.InternalSensor && channel == Ads1118InputMultiplexer.Ain0Ain1)
                {
                    transferBuffer.Tx[0] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[1] = Convert.ToByte(0x9a);
                    transferBuffer.Tx[2] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[3] = Convert.ToByte(0x9a);
                }

                Console.Write("sending [{0} {1} {2} {3}]. ", transferBuffer.Tx[0].ToString("x2"), transferBuffer.Tx[1].ToString("x2"), transferBuffer.Tx[2].ToString("x2"), transferBuffer.Tx[3].ToString("x2"));

                transferBuffer.Delay            = 0;
                transferBuffer.Speed            = SpiSpeed;
                transferBuffer.BitsPerWord      = BitsPerWord;
                transferBuffer.ChipSelectChange = false;

                ret = this.spi1.Transfer(transferBuffer);

                if (ret < 0)
                {
                    Console.WriteLine("Error performing SPI exchange: {0}", Console.Error.ToString());
                    Environment.Exit(1);
                }

                ret = 0;

                Console.WriteLine("received [{0} {1} {2} {3}]", transferBuffer.Rx[0].ToString("x2"), transferBuffer.Rx[1].ToString("x2"), transferBuffer.Rx[2].ToString("x2"), transferBuffer.Rx[3].ToString("x2"));

                ret = transferBuffer.Rx[0];
                ret = ret << 8;
                ret = ret | transferBuffer.Rx[1];
            }

            return(ret);
        }
        public byte[] GetConfiguration(Ads1118TemperatureSensorMode mode, Ads1118InputMultiplexer channel)
        {
            var config = new byte[2];

            switch (this.singleShot)
            {
            case Ads1118SingleShot.NoEffect:
                config[0] = 0;
                break;

            case Ads1118SingleShot.SingleShot:
            default:
                config[0] = 1;
                break;
            }

            switch (channel)
            {
            case Ads1118InputMultiplexer.Ain0Ain1:
            default:
                config[1] = 0;
                config[2] = 0;
                config[3] = 0;
                break;

            case Ads1118InputMultiplexer.Ain0Ain3:
                config[1] = 0;
                config[2] = 0;
                config[3] = 1;
                break;

            case Ads1118InputMultiplexer.Ain1Ain3:
                config[1] = 0;
                config[2] = 1;
                config[3] = 0;
                break;

            case Ads1118InputMultiplexer.Ain2Ain3:
                config[1] = 0;
                config[2] = 1;
                config[3] = 1;
                break;

            case Ads1118InputMultiplexer.Ain0Gnd:
                config[1] = 1;
                config[2] = 0;
                config[3] = 0;
                break;

            case Ads1118InputMultiplexer.Ain1Gnd:
                config[1] = 1;
                config[2] = 0;
                config[3] = 1;
                break;

            case Ads1118InputMultiplexer.Ain2Gnd:
                config[1] = 1;
                config[2] = 1;
                config[3] = 0;
                break;

            case Ads1118InputMultiplexer.Ain3Gnd:
                config[1] = 1;
                config[2] = 1;
                config[3] = 1;
                break;
            }

            return(config);
        }
        public int ThermTransact(Ads1118TemperatureSensorMode mode, Ads1118InputMultiplexer channel)
        {
            int ret;

            using (var transferBuffer = this.spi1.CreateTransferBuffer(4, SpiTransferMode.ReadWrite))
            {
                if (mode == Ads1118TemperatureSensorMode.ExternalSignal && channel == Ads1118InputMultiplexer.Ain0Ain1)
                {
                    transferBuffer.Tx[0] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[1] = Convert.ToByte(0x8a);
                    transferBuffer.Tx[2] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[3] = Convert.ToByte(0x8a);
                }
                else if (mode == Ads1118TemperatureSensorMode.InternalSensor && channel == Ads1118InputMultiplexer.Ain0Ain1)
                {
                    transferBuffer.Tx[0] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[1] = Convert.ToByte(0x9a);
                    transferBuffer.Tx[2] = Convert.ToByte(0x8b);
                    transferBuffer.Tx[3] = Convert.ToByte(0x9a);
                }

                Console.Write("sending [{0} {1} {2} {3}]. ", transferBuffer.Tx[0].ToString("x2"), transferBuffer.Tx[1].ToString("x2"), transferBuffer.Tx[2].ToString("x2"), transferBuffer.Tx[3].ToString("x2"));

                transferBuffer.Delay = 0;
                transferBuffer.Speed = SpiSpeed;
                transferBuffer.BitsPerWord = BitsPerWord;
                transferBuffer.ChipSelectChange = false;

                ret = this.spi1.Transfer(transferBuffer);

                if (ret < 0)
                {
                    Console.WriteLine("Error performing SPI exchange: {0}", Console.Error.ToString());
                    Environment.Exit(1);
                }

                ret = 0;

                Console.WriteLine("received [{0} {1} {2} {3}]", transferBuffer.Rx[0].ToString("x2"), transferBuffer.Rx[1].ToString("x2"), transferBuffer.Rx[2].ToString("x2"), transferBuffer.Rx[3].ToString("x2"));

                ret = transferBuffer.Rx[0];
                ret = ret << 8;
                ret = ret | transferBuffer.Rx[1];
            }

            return ret;
        }
        public byte[] GetConfiguration(Ads1118TemperatureSensorMode mode, Ads1118InputMultiplexer channel)
        {
            var config = new byte[2];

            switch (this.singleShot)
            {
                case Ads1118SingleShot.NoEffect:
                    config[0] = 0;
                    break;

                case Ads1118SingleShot.SingleShot:
                default:
                    config[0] = 1;
                    break;
            }

            switch (channel)
            {
                case Ads1118InputMultiplexer.Ain0Ain1:
                default:
                    config[1] = 0;
                    config[2] = 0;
                    config[3] = 0;
                    break;

                case Ads1118InputMultiplexer.Ain0Ain3:
                    config[1] = 0;
                    config[2] = 0;
                    config[3] = 1;
                    break;

                case Ads1118InputMultiplexer.Ain1Ain3:
                    config[1] = 0;
                    config[2] = 1;
                    config[3] = 0;
                    break;

                case Ads1118InputMultiplexer.Ain2Ain3:
                    config[1] = 0;
                    config[2] = 1;
                    config[3] = 1;
                    break;

                case Ads1118InputMultiplexer.Ain0Gnd:
                    config[1] = 1;
                    config[2] = 0;
                    config[3] = 0;
                    break;

                case Ads1118InputMultiplexer.Ain1Gnd:
                    config[1] = 1;
                    config[2] = 0;
                    config[3] = 1;
                    break;

                case Ads1118InputMultiplexer.Ain2Gnd:
                    config[1] = 1;
                    config[2] = 1;
                    config[3] = 0;
                    break;

                case Ads1118InputMultiplexer.Ain3Gnd:
                    config[1] = 1;
                    config[2] = 1;
                    config[3] = 1;
                    break;
            }

            return config;
        }