• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ProcessorPin类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ProcessorPin的典型用法代码示例。如果您正苦于以下问题:C# ProcessorPin类的具体用法?C# ProcessorPin怎么用?C# ProcessorPin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ProcessorPin类属于命名空间,在下文中一共展示了ProcessorPin类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Allocate

        /// <summary>
        /// Allocates the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void Allocate(ProcessorPin pin, PinDirection direction)
        {
            var gpioId = string.Format("gpio{0}", (int)pin);
            if (Directory.Exists(Path.Combine(gpioPath, gpioId)))
            {
                // Reinitialize pin virtual file
                using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "unexport"), false))
                    streamWriter.Write((int) pin);
            }

            // Export pin for file mode
            using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false))
                streamWriter.Write((int)pin);

            // Set the direction on the pin and update the exported list
            SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP);

            // Set direction in pin virtual file
            var filePath = Path.Combine(gpioId, "direction");
            using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, filePath), false))
                streamWriter.Write(direction == PinDirection.Input ? "in" : "out");

            if (direction == PinDirection.Input)
            {
                PinResistor pinResistor;
                if (!pinResistors.TryGetValue(pin, out pinResistor) || pinResistor != PinResistor.None)
                    SetPinResistor(pin, PinResistor.None);

                SetPinDetectedEdges(pin, PinDetectedEdges.Both);
                InitializePoll(pin);
            }
        }
开发者ID:sanyaade-iot,项目名称:raspberry-sharp-io,代码行数:37,代码来源:GpioConnectionDriver.cs


示例2: SpiConnection

        public SpiConnection(ProcessorPin clock, ProcessorPin ss, ProcessorPin? miso, ProcessorPin? mosi, Endianness endianness)
        {
            this.clock = clock;
            this.ss = ss;
            this.miso = miso;
            this.mosi = mosi;
            this.endianness = endianness;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(clock, PinDirection.Output);
            driver.Write(clock, false);

            driver.Allocate(ss, PinDirection.Output);
            driver.Write(ss, true);

            if (mosi.HasValue)
            {
                driver.Allocate(mosi.Value, PinDirection.Output);
                driver.Write(mosi.Value, false);
            }

            if (miso.HasValue)
                driver.Allocate(miso.Value, PinDirection.Input);
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:25,代码来源:SpiConnection.cs


示例3: GpioOutputPin

        public GpioOutputPin(IGpioConnectionDriver driver, ProcessorPin pin)
        {
            this.driver = driver;
            this.pin = pin;

            driver.Allocate(pin, PinDirection.Output);
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:7,代码来源:GpioOutputPin.cs


示例4: Allocate

        /// <summary>
        /// Allocates the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void Allocate(ProcessorPin pin, PinDirection direction)
        {
            Release(pin);

            using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false))
                streamWriter.Write((int)pin);

            if (!gpioPathList.ContainsKey(pin))
            {
                var gpio = new FileGpioHandle { GpioPath = GuessGpioPath(pin) };
                gpioPathList.Add(pin, gpio);
            }

            var filePath = Path.Combine(gpioPathList[pin].GpioPath, "direction");
            try {
                SetPinDirection(filePath, direction);
            }
            catch (UnauthorizedAccessException) {
                // program hasn't been started as root, give it a second to correct file permissions
                Thread.Sleep(TimeSpan.FromSeconds(1));
                SetPinDirection(filePath, direction);
            }

            gpioPathList[pin].GpioStream = new FileStream(Path.Combine(GuessGpioPath(pin), "value"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
        }
开发者ID:sjastrze,项目名称:raspberry-sharp-io,代码行数:30,代码来源:FileGpioConnectionDriver.cs


示例5: I2cDriver

        /// <summary>
        /// Initializes a new instance of the <see cref="I2cDriver"/> class.
        /// </summary>
        /// <param name="sdaPin">The SDA pin.</param>
        /// <param name="sclPin">The SCL pin.</param>
        public I2cDriver(ProcessorPin sdaPin, ProcessorPin sclPin)
        {
            this.sdaPin = sdaPin;
            this.sclPin = sclPin;

            var bscBase = GetBscBase(sdaPin, sclPin);

            var memoryFile = Interop.open("/dev/mem", Interop.O_RDWR + Interop.O_SYNC);
            try
            {
                gpioAddress = Interop.mmap(IntPtr.Zero, Interop.BCM2835_BLOCK_SIZE, Interop.PROT_READ | Interop.PROT_WRITE, Interop.MAP_SHARED, memoryFile, Interop.BCM2835_GPIO_BASE);
                bscAddress = Interop.mmap(IntPtr.Zero, Interop.BCM2835_BLOCK_SIZE, Interop.PROT_READ | Interop.PROT_WRITE, Interop.MAP_SHARED, memoryFile, bscBase);
            }
            finally
            {
                Interop.close(memoryFile);
            }

            if (bscAddress == (IntPtr) Interop.MAP_FAILED)
                throw new InvalidOperationException("Unable to access device memory");

            // Set the I2C pins to the Alt 0 function to enable I2C access on them
            SetPinMode((uint) (int) sdaPin, Interop.BCM2835_GPIO_FSEL_ALT0); // SDA
            SetPinMode((uint) (int) sclPin, Interop.BCM2835_GPIO_FSEL_ALT0); // SCL

            // Read the clock divider register
            var dividerAddress = bscAddress + (int) Interop.BCM2835_BSC_DIV;
            var divider = (ushort) SafeReadUInt32(dividerAddress);
            waitInterval = GetWaitInterval(divider);

            var addressAddress = bscAddress + (int) Interop.BCM2835_BSC_A;
            SafeWriteUInt32(addressAddress, (uint) currentDeviceAddress);
        }
开发者ID:Zelxin,项目名称:RPiKeg,代码行数:38,代码来源:I2cDriver.cs


示例6: Allocate

        /// <summary>
        /// Allocates the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void Allocate(ProcessorPin pin, PinDirection direction)
        {
            // Set the direction on the pin and update the exported list
            SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP);

            if (direction == PinDirection.Input)
                SetPinResistor(pin, PinResistor.None);
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:13,代码来源:MemoryGpioConnectionDriver.cs


示例7: GpioOutputBinaryPin

        /// <summary>
        /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
        {
            this.driver = driver;
            this.pin = pin;

            driver.Allocate(pin, PinDirection.Output);
            driver.SetPinResistor(pin, resistor);
        }
开发者ID:gamondue,项目名称:raspberry-sharp-io,代码行数:14,代码来源:GpioOutputBinaryPin.cs


示例8: Hd44780LcdConnection

        /// <summary>
        /// Initializes a new instance of the <see cref="Hd44780LcdConnection"/> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="registerSelectPin">The register select pin.</param>
        /// <param name="clockPin">The clock pin.</param>
        /// <param name="dataPins">The data pins.</param>
        public Hd44780LcdConnection(Hd44780LcdConnectionSettings settings, ProcessorPin registerSelectPin, ProcessorPin clockPin, IEnumerable<ProcessorPin> dataPins)
        {
            settings = settings ?? new Hd44780LcdConnectionSettings();

            this.registerSelectPin = registerSelectPin;
            this.clockPin = clockPin;
            this.dataPins = dataPins.ToArray();

            if (this.dataPins.Length != 4 && this.dataPins.Length != 8)
                throw new ArgumentOutOfRangeException("dataPins", this.dataPins.Length, "There must be either 4 or 8 data pins");

            width = settings.ScreenWidth;
            height = settings.ScreenHeight;
            if (height < 1 || height > 2)
                throw new ArgumentOutOfRangeException("ScreenHeight", height, "Screen must have either 1 or 2 rows");
            if (width * height > 80)
                throw new ArgumentException("At most 80 characters are allowed");

            if (settings.PatternWidth != 5)
                throw new ArgumentOutOfRangeException("PatternWidth", settings.PatternWidth, "Pattern must be 5 pixels width");
            if (settings.PatternHeight != 8 && settings.PatternHeight != 10)
                throw new ArgumentOutOfRangeException("PatternHeight", settings.PatternWidth, "Pattern must be either 7 or 10 pixels height");
            if (settings.PatternHeight == 10 && height == 2)
                throw new ArgumentException("10 pixels height pattern cannot be used with 2 rows");

            functions = (settings.PatternHeight == 8 ? Functions.Matrix5x8 : Functions.Matrix5x10)
                | (height == 1 ? Functions.OneLine : Functions.TwoLines)
                | (this.dataPins.Length == 4 ? Functions.Data4bits : Functions.Data8bits);

            entryModeFlags = /*settings.RightToLeft
                ? EntryModeFlags.EntryRight | EntryModeFlags.EntryShiftDecrement
                :*/ EntryModeFlags.EntryLeft | EntryModeFlags.EntryShiftDecrement;

            encoding = settings.Encoding;

            connectionDriver = new MemoryGpioConnectionDriver();

            connectionDriver.Allocate(registerSelectPin, PinDirection.Output);
            connectionDriver.Write(registerSelectPin, false);

            connectionDriver.Allocate(clockPin, PinDirection.Output);
            connectionDriver.Write(clockPin, false);

            foreach (var dataPin in this.dataPins)
            {
                connectionDriver.Allocate(dataPin, PinDirection.Output);
                connectionDriver.Write(dataPin, false);
            }

            WriteByte(0x33, false); // Initialize
            WriteByte(0x32, false);

            WriteCommand(Command.SetFunctions, (int) functions);
            WriteCommand(Command.SetDisplayFlags, (int) displayFlags);
            WriteCommand(Command.SetEntryModeFlags, (int) entryModeFlags);

            Clear();
        }
开发者ID:spokino,项目名称:raspberry-sharp-io,代码行数:65,代码来源:Hd44780LcdConnection.cs


示例9: Time

        /// <summary>
        /// Waits for a pin to reach the specified state, then measures the time it remains in this state.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The measure pin.</param>
        /// <param name="waitForUp">if set to <c>true</c>, wait for the pin to be up.</param>
        /// <param name="phase1Timeout">The first phase timeout.</param>
        /// <param name="phase2Timeout">The second phase timeout.</param>
        /// <returns>
        /// The time the pin remains up, in milliseconds.
        /// </returns>
        public static decimal Time(this IGpioConnectionDriver driver, ProcessorPin pin, bool waitForUp = true, decimal phase1Timeout = 0, decimal phase2Timeout = 0)
        {
            driver.Wait(pin, waitForUp, phase1Timeout);

            var waitDown = DateTime.Now.Ticks;
            driver.Wait(pin, !waitForUp, phase2Timeout);

            return (DateTime.Now.Ticks - waitDown)/10000m;
        }
开发者ID:gamondue,项目名称:raspberry-sharp-io,代码行数:20,代码来源:GpioConnectionDriverExtensionMethods.cs


示例10: GpioOutputBinaryPin

        /// <summary>
        /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None)
        {
            this.driver = driver;
            this.pin = pin;

            driver.Allocate(pin, PinDirection.Output);
            if ((driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0)
                driver.SetPinResistor(pin, resistor);
        }
开发者ID:Code1110,项目名称:raspberry-sharp-io,代码行数:15,代码来源:GpioOutputBinaryPin.cs


示例11: Read

        /// <summary>
        /// Reads the status of the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <returns>
        /// The pin status.
        /// </returns>
        public bool Read(ProcessorPin pin)
        {
            int shift;
            var offset = Math.DivRem((int) pin, 32, out shift);

            var pinGroupAddress = gpioAddress + (int) (Interop.BCM2835_GPLEV0 + offset);
            var value = SafeReadUInt32(pinGroupAddress);

            return (value & (1 << shift)) != 0;
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:17,代码来源:MemoryGpioConnectionDriver.cs


示例12: HcSr04Connection

        /// <summary>
        /// Initializes a new instance of the <see cref="HcSr04Connection"/> class.
        /// </summary>
        /// <param name="triggerPin">The trigger pin.</param>
        /// <param name="echoPin">The echo pin.</param>
        public HcSr04Connection(ProcessorPin triggerPin, ProcessorPin echoPin)
        {
            this.triggerPin = triggerPin;
            this.echoPin = echoPin;

            driver = new MemoryGpioConnectionDriver();

            driver.Allocate(triggerPin, PinDirection.Output);
            driver.Allocate(echoPin, PinDirection.Input);
        }
开发者ID:spokino,项目名称:raspberry-sharp-io,代码行数:15,代码来源:HcSr04Connection.cs


示例13: Read

        /// <summary>
        /// Reads the status of the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <returns>
        /// The pin status.
        /// </returns>
        public bool Read(ProcessorPin pin)
        {
            var gpioId = string.Format("gpio{0}", (int) pin);
            var filePath = Path.Combine(gpioId, "value");

            using (var streamReader = new StreamReader(new FileStream(Path.Combine(gpioPath, filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                var rawValue = streamReader.ReadToEnd();
                return !string.IsNullOrEmpty(rawValue) && rawValue[0] == '1';
            }
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:18,代码来源:FileGpioConnectionDriver.cs


示例14: Read

        /// <summary>
        /// Reads the status of the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <returns>
        /// The pin status.
        /// </returns>
        public bool Read(ProcessorPin pin)
        {
            var shift = (byte)((int)pin % 32);
            var value = Interop.bcm2835_gpioperi_read((uint)pin / 32);

            return (value & (1 << shift)) != 0;

            /*
            var value = Interop.bcm2835_gpio_lev((uint)pin);
            return value != 0;
            */
        }
开发者ID:spokino,项目名称:raspberry-sharp-io,代码行数:19,代码来源:MemoryGpioConnectionDriver.cs


示例15: Wait

        /// <summary>
        /// Waits for the specified pin to reach a given state.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="waitForUp">if set to <c>true</c>, waits for the pin to become up; otherwise, waits for the pin to become down.</param>
        /// <param name="timeout">The timeout.</param>
        public static void Wait(this IGpioConnectionDriver driver, ProcessorPin pin, bool waitForUp = true, int timeout = 0)
        {
            if (timeout == 0)
                timeout = 5000;

            var startWait = DateTime.Now;
            while (driver.Read(pin) != waitForUp)
            {
                if (DateTime.Now.Ticks - startWait.Ticks >= 10000*timeout)
                    throw new TimeoutException();
            }
        }
开发者ID:spokino,项目名称:raspberry-sharp-io,代码行数:19,代码来源:GpioConnectionDriverExtensionMethods.cs


示例16: Allocate

        /// <summary>
        /// Allocates the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void Allocate(ProcessorPin pin, PinDirection direction)
        {
            var gpioId = string.Format("gpio{0}", (int)pin);
            if (Directory.Exists(Path.Combine(gpioPath, gpioId)))
                Release(pin);

            using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false))
                streamWriter.Write((int)pin);

            var filePath = Path.Combine(gpioId, "direction");
            using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, filePath), false))
                streamWriter.Write(direction == PinDirection.Input ? "in" : "out");
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:18,代码来源:FileGpioConnectionDriver.cs


示例17: Time

        /// <summary>
        /// Measures the time the specified pin remains up.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="pin">The measure pin.</param>
        /// <param name="waitForDown">if set to <c>true</c>, waits for the pin to become down; otherwise, waits for the pin to become up.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>
        /// The time the pin remains up, in milliseconds.
        /// </returns>
        public static decimal Time(this IGpioConnectionDriver driver, ProcessorPin pin, bool waitForDown = true, int timeout = 0)
        {
            if (timeout == 0)
                timeout = 5000;

            var waitDown = DateTime.Now;
            while (driver.Read(pin) == waitForDown)
            {
                if (DateTime.Now.Ticks - waitDown.Ticks >= 10000*timeout)
                    throw new TimeoutException();
            }

            return (DateTime.Now.Ticks - waitDown.Ticks)/10000m;
        }
开发者ID:spokino,项目名称:raspberry-sharp-io,代码行数:24,代码来源:GpioConnectionDriverExtensionMethods.cs


示例18: Allocate

        /// <summary>
        /// Allocates the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void Allocate(ProcessorPin pin, PinDirection direction)
        {
            // Set the direction on the pin and update the exported list
            // BCM2835_GPIO_FSEL_INPT = 0
            // BCM2835_GPIO_FSEL_OUTP = 1
            Interop.bcm2835_gpio_fsel((uint)pin, (uint)(direction == PinDirection.Input ? 0 : 1));

            if (direction == PinDirection.Input)
            {
                // BCM2835_GPIO_PUD_OFF = 0b00 = 0
                // BCM2835_GPIO_PUD_DOWN = 0b01 = 1
                // BCM2835_GPIO_PUD_UP = 0b10 = 2
                Interop.bcm2835_gpio_set_pud((uint)pin, 0);
            }
        }
开发者ID:spokino,项目名称:raspberry-sharp-io,代码行数:20,代码来源:MemoryGpioConnectionDriver.cs


示例19: HcSr04Connection

        /// <summary>
        /// Initializes a new instance of the <see cref="HcSr04Connection"/> class.
        /// </summary>
        /// <param name="triggerPin">The trigger pin.</param>
        /// <param name="echoPin">The echo pin.</param>
        public HcSr04Connection(ProcessorPin triggerPin, ProcessorPin echoPin)
        {
            this.triggerPin = triggerPin;
            this.echoPin = echoPin;

            Timeout = DefaultTimeout;

            driver = GpioConnectionSettings.DefaultDriver;

            driver.Allocate(echoPin, PinDirection.Input);
            driver.Allocate(triggerPin, PinDirection.Output);

            try
            {
                GetDistance();
            } catch {}
        }
开发者ID:ranma209,项目名称:raspberry-sharp-io,代码行数:22,代码来源:HcSr04Connection.cs


示例20: Allocate

        /// <summary>
        /// Allocates the specified pin.
        /// </summary>
        /// <param name="pin">The pin.</param>
        /// <param name="direction">The direction.</param>
        public void Allocate(ProcessorPin pin, PinDirection direction)
        {
            var gpioId = string.Format("gpio{0}", (int)pin);
            if (Directory.Exists(Path.Combine(gpioPath, gpioId)))
                Release(pin);

            using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false))
                streamWriter.Write((int)pin);

            var filePath = Path.Combine(gpioPath, gpioId, "direction");
            try {
                SetPinDirection(filePath, direction);
            } catch (UnauthorizedAccessException) {
                // program hasn't been started as root, give it a second to correct file permissions
                Thread.Sleep(TimeSpan.FromSeconds(1));
                SetPinDirection(filePath, direction);
            }
        }
开发者ID:gamondue,项目名称:raspberry-sharp-io,代码行数:23,代码来源:FileGpioConnectionDriver.cs



注:本文中的ProcessorPin类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Product类代码示例发布时间:2022-05-24
下一篇:
C# ProcessorArgumentCollection类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap