Ejemplo n.º 1
0
        public void GpioStop()
        {
            if (cts != null)
            {
                cts.Cancel();
            }

            if (handle >= 0)
            {
                try
                {
                    GpioCommand(CMD_NC, handle, 0);
                }
                catch (GpiodIfException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                handle = -1;
            }

            if (this.TcpConnection != null)
            {
                // Execute handlers of StreamChanged event, and call Close()
                this.CommandStream = null;
                this.TcpConnection.Close();
            }
            if (NotifyTcpConnection != null)
            {
                // Execute handlers of NotifyStreamChanged event, and call Close()
                NotifyStream = null;
                NotifyTcpConnection.Close();
            }
        }
Ejemplo n.º 2
0
        public int GpioStart(string addrStr, string portStr)
        {
            handle = -1;

            if (string.IsNullOrWhiteSpace(addrStr))
            {
                addrStr = DEFAULT_SOCKET_ADDR_STR;
            }
            if (string.IsNullOrWhiteSpace(portStr))
            {
                portStr = DEFAULT_SOCKET_PORT_STR;
            }

            int port;

            if (int.TryParse(portStr, out port) == false)
            {
                throw new GpiodIfException("failed to find address of the device");
            }

            isConnecting = false;
            this.TcpConnection.Open(addrStr, port);
            NotifyTcpConnection.Open(addrStr, port);

            return(0);
        }