예제 #1
0
        private const int LatencyTimer = 255; // Hz

        static void Main(string[] args)
        {

            var adcSpiConfig = new FtChannelConfig
                             {
                                 ClockRate = ConnectionSpeed,
                                 LatencyTimer = LatencyTimer,
                                 configOptions = FtConfigOptions.Mode0 | FtConfigOptions.CsDbus3 | FtConfigOptions.CsActivelow
                             };

          

            var adcConfig = new Maxim186Configuration
                                {
                                    Channel = Maxim186.Channel.Channel0,
                                    ConversionType = Maxim186.ConversionType.SingleEnded,
                                    Polarity = Maxim186.Polarity.Unipolar,
                                    PowerMode = Maxim186.PowerMode.InternalClockMode
                                };

           

            var adc = new Maxim186(adcConfig, adcSpiConfig);

            do
            {
                Console.WriteLine(adc.GetConvertedSample());

               

            } while (true);
            //*/
        }
예제 #2
0
        public int Begin(int address)
        {
            if (_i2cDevice == null)
            {
                var adci2cConfig = new FtChannelConfig
                {
                    ClockRate = ConnectionSpeed,
                    LatencyTimer = LatencyTimer
                };

                if (_i2cDevice == null)
                {
                    _i2cDevice = new I2CDevice(adci2cConfig, address);

                    var b = _i2cDevice.Read(1);

                    if (b == null)
                    {
                        Debugger.Break();
                    }

                    _shadow = Convert.ToInt32(b[0]);
                    _initialised = true;
                }
            }

            return 1;
        }
예제 #3
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;

        }
예제 #4
0
 public extern static FtResult SPI_InitChannel(IntPtr handle, ref FtChannelConfig config);
예제 #5
0
 public static extern FtResult I2C_InitChannel(System.IntPtr handle, ref FtChannelConfig config);
예제 #6
0
 public Maxim186(Maxim186Configuration adcConfig, FtChannelConfig config, SpiConfiguration spiConfig)
     : base(config, spiConfig)
 {
     _adcConfig = adcConfig;
 }
예제 #7
0
 public Maxim186(Maxim186Configuration adcConfig, FtChannelConfig config)
     : this(adcConfig, config, null)
 {
 }
예제 #8
0
 protected SpiDevice(FtChannelConfig config, SpiConfiguration spiConfig)
 {
     _spiConfig = spiConfig ?? SpiConfiguration.ChannelZeroConfiguration;
     _cfg = config;
     InitLibAndHandle();
 }
예제 #9
0
        protected SpiDevice(FtChannelConfig config)
            : this(config, null)
        {

        }
예제 #10
0
 private void EnforceRightConfiguration()
 {
     if (_currentGlobalConfig.configOptions != _cfg.configOptions)
     {
         LibMpsseSpi.SPI_ChangeCS(_handle, _cfg.configOptions);
         _currentGlobalConfig = _cfg;
     }
 }