コード例 #1
0
        /// <summary>
        /// Sets raspberry device pin value.
        /// </summary>
        /// <param name="pin">Raspberry pin</param>
        /// <param name="pinValue">Raspberry pin value</param>
        public void SetPinValue(RaspberyPin pin, PinValue pinValue)
        {
            if (!this.IsInitialized)
            {
                throw new Exception("Raspberry device not initialized");
            }

            if (!RaspberyPin.IsGPIOPin(pin.Code))
            {
                throw new Exception("Can not set pin value to non GPIO pin");
            }

            try
            {
                string pinAddress = pin.Code.ToString().Split('_').Last().Replace("0", "");
                string value      = "";
                switch (pinValue)
                {
                case PinValue.High:
                    value = "1";
                    break;

                case PinValue.Low:
                    value = "0";
                    break;
                }
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    ("echo " + value + " > /sys/class/gpio/gpio" + pinAddress + "/value").Bash();
                }
                this._devicePins.Where(p => p.Code == pin.Code).SingleOrDefault().Value = pinValue;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets raspbery device pin direction.
        /// </summary>
        /// <param name="pin">Raspberry pin</param>
        /// <param name="pinDirection">Raspberry pin direction</param>
        public void SetPinDirection(RaspberyPin pin, PinDirection pinDirection)
        {
            if (!this.IsInitialized)
            {
                throw new Exception("Raspberry device not initialized");
            }

            if (!RaspberyPin.IsGPIOPin(pin.Code))
            {
                throw new Exception("Can not set pin direction to non GPIO pin");
            }

            try
            {
                string pinAddress = pin.Code.ToString().Split('_').Last().Replace("0", "");
                string direction  = "";
                switch (pinDirection)
                {
                case PinDirection.In:
                    direction = "in";
                    break;

                case PinDirection.Out:
                    direction = "out";
                    break;
                }
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    ("echo " + direction + " > /sys/class/gpio/gpio" + pinAddress + "/direction").Bash();
                }
                this._devicePins.Where(p => p.Code == pin.Code).SingleOrDefault().Direction = pinDirection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }