示例#1
0
        /// <summary>
        /// Initialize the brick including SPI communication
        /// </summary>
        /// <param name="spiAddress">The Spi Address of the brick</param>
        /// <param name="busId">The bus id that the device is connected to</param>
        /// <param name="ChipSelectLine">The chip select line that the device is connected to</param>
        public Brick(byte spiAddress = 1, int busId = 0, int ChipSelectLine = 1)
        {
            try
            {
                SpiAddress = spiAddress;
                // SPI 0 is used on Raspberry with ChipSelectLine 1
                var settings = new SpiConnectionSettings(busId, ChipSelectLine);
                // 500K is the SPI communication with the brick
                settings.ClockFrequency = 500000;
                // see http://tightdev.net/SpiDev_Doc.pdf
                settings.Mode          = SpiMode.Mode0;
                settings.DataBitLength = 8;
                // as the SPI is a static, checking if it has already be initialised
                if (_brickPiSPI == null)
                {
                    _brickPiSPI = SpiDevice.Create(settings);
                }

                BrickPi3Info = new BrickPiInfo();
                BrickPi3Info.Manufacturer    = GetManufacturer();
                BrickPi3Info.Board           = GetBoard();
                BrickPi3Info.HardwareVersion = GetHardwareVersion();
                BrickPi3Info.SoftwareVersion = GetFirmwareVersion();
                BrickPi3Info.Id = GetId();
            }
            catch (Exception ex) when(ex is IOException)
            {
                Debug.Write($"Exception: {ex.Message}");
            }
        }
示例#2
0
文件: BrickPi3.cs 项目: mmalyska/iot
        /// <summary>
        /// Initialize the brick including SPI communication
        /// </summary>
        /// <param name="spiAddress">The Spi Address of the brick</param>
        /// <param name="busId">The bus id that the device is connected to</param>
        /// <param name="ChipSelectLine">The chip select line that the device is connected to</param>
        public Brick(byte spiAddress = 1, int busId = 0, int ChipSelectLine = 1)
        {
            SpiAddress = spiAddress;
            // SPI 0 is used on Raspberry with ChipSelectLine 1
            var settings = new SpiConnectionSettings(busId, ChipSelectLine);

            // 500K is the SPI communication with the brick
            settings.ClockFrequency = 500000;
            // see http://tightdev.net/SpiDev_Doc.pdf
            settings.Mode          = SpiMode.Mode0;
            settings.DataBitLength = 8;
            _brickPiSPI            = SpiDevice.Create(settings);
            BrickPi3Info           = new BrickPiInfo(
                GetManufacturer(),
                GetBoard(),
                GetHardwareVersion(),
                GetFirmwareVersion(),
                GetId());
        }
示例#3
0
        private async Task InitSPI_async(byte spi_address = 1)
        {
            try
            {
                SPI_Address = spi_address;
                var settings = new SpiConnectionSettings(CHIP_SELECT_lINE);
                settings.ClockFrequency = 500000;        /* 500K                     */
                settings.Mode           = SpiMode.Mode0; //http://tightdev.net/SpiDev_Doc.pdf
                settings.DataBitLength  = 8;
                settings.SharingMode    = SpiSharingMode.Exclusive;
                // as the SPI is a static, checking if it has already be initialised
                if (BrickPiSPI == null)
                {
                    string aqs = SpiDevice.GetDeviceSelector();                     /* Get a selector string that will return all SPI controllers on the system */
                    var    dis = await DeviceInformation.FindAllAsync(aqs);         /* Find the SPI bus controller devices with our selector string             */

                    BrickPiSPI = await SpiDevice.FromIdAsync(dis[0].Id, settings);  /* Create an SpiDevice with our bus controller and SPI settings             */

                    if (BrickPiSPI == null)
                    {
                        Debug.WriteLine(string.Format(
                                            "SPI Controller {0} is currently in use by " +
                                            "another application. Please ensure that no other applications are using SPI.",
                                            dis[0].Id));
                        return;
                    }
                }
                BrickPi3Info = new BrickPiInfo();
                BrickPi3Info.Manufacturer    = get_manufacturer();
                BrickPi3Info.Board           = get_board();
                BrickPi3Info.HardwareVersion = get_version_hardware();
                BrickPi3Info.SoftwareVersion = get_version_firmware();
                BrickPi3Info.Id = get_id();
            }
            catch (Exception ex)
            {
                Debug.Write($"Exception: {ex.Message}");
            }
        }