Example #1
0
        /// <summary>
        /// Open a connection to the specified GPIO server.
        /// </summary>
        /// <param name="servername">Server domain name or IP address.</param>
        public static void Connect(Primitive servername)
        {
            IPAddress serveraddress;

            // Check for invalid parameter

            if (Uri.CheckHostName((string)servername) == UriHostNameType.Unknown)
            {
                throw new GPIOException("GPIO server name is invalid");
            }

            // Resolve the server IP address

            try
            {
                serveraddress = Dns.GetHostAddresses((string)servername)[0];
            }
            catch
            {
                throw new GPIOException("GPIO server name cannot be resolved");
            }

            try
            {
                // Create RPC client object

                server = new gpio_server_oncrpcClient(serveraddress, OncRpcProtocols.ONCRPC_UDP);

                // Reduce timeout to 2 seconds

                OncRpcUdpClient c = (OncRpcUdpClient)server.GetClient();

                c.setTimeout(2000);
                c.setRetransmissionTimeout(500);
            }
            catch
            {
                throw new GPIOException("GPIO server handle failed");
            }
        }
Example #2
0
 /// <summary>
 /// GPIO pin object constructor.
 /// </summary>
 /// <param name="server">ONC/RPC server handle.</param>
 /// <param name="number">GPIO pin number.</param>
 /// <remarks>
 /// Do not call this constructor directly; use the Server.OpenPin() factory method instead.
 /// </remarks>
 public Pin(gpio_server_oncrpcClient server, int number)
 {
     this.server = server;
     this.number = number;
 }