Beispiel #1
0
        /// <summary>
        /// This factory method configures the specified GPIO pin and returns a Pin object for it.
        /// </summary>
        /// <param name="number">GPIO pin number.</param>
        /// <param name="direction">GPIO pin direction, GPIO.Direction.Input or GPIO.Direction.Output.</param>
        /// <param name="state">GPIO output pin initial state, true or false.  Ignored for input pin.</param>
        /// <returns>Returns a configured GPIO Pin object.</returns>
        public Pin OpenPin(int number, Direction direction, bool state = false)
        {
            int status;

            try
            {
                status = server.gpio_open_1(number, (int)direction, state ? 1 : 0);
            }
            catch
            {
                throw new Exception("RPC gpio_open_1() failed");
            }

            if (status < 0)
            {
                throw new Exception("RPC gpio_open_1() returned error " + status.ToString());
            }
            try
            {
                return(new Pin(this.server, number));
            }
            catch
            {
                throw new Exception("Failed to construct Pin object");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Configure a GPIO pin
        /// </summary>
        /// <param name="pin">Pin number.</param>
        /// <param name="direction">Data direction: "input" or "output".  The values 0 and 1 are also allowed.</param>
        /// <param name="state">Initial output logic level: "true" or "false".  The values "high", "low", "on", "off", 1 and 0 are also allowed.  Ignored for input pins.</param>
        public static void Configure(Primitive pin, Primitive direction, Primitive state)
        {
            int p = (int)pin;
            int d = ToDirection(direction);
            int s = ToLogicLevel(state);
            int status;

            try
            {
                status = server.gpio_open_1(p, d, s);
            }
            catch
            {
                throw new GPIOException("RPC gpio_open_1() failed");
            }

            if (status < 0)
            {
                throw new GPIOException("RPC gpio_open_1() returned error " + status.ToString() + " " + p.ToString() + " " + d.ToString() + " " + s.ToString());
            }
        }