Ejemplo n.º 1
0
        public GarageDoorButton(int socketNumber)
        {
            _socket = Socket.GetSocket(socketNumber, true, this, null);

            _socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, this);

            var input = InterruptInputFactory.Create(_socket, Socket.Pin.Three, GlitchFilterMode.On, ResistorMode.PullUp, InterruptMode.RisingAndFallingEdge, this);

            input.Interrupt += Input_Interrupt;


            //_output = DigitalOutputFactory.Create(_socket, Socket.Pin.Four, true, this);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Initializes the DaisyLink bus, resetting all devices on it and assigning them new addresses.
            /// Any existing GTM.DaisyLinkModule devices will no longer work, and they should be constructed again.
            /// </summary>
            internal void Initialize()
            {
                lock (portLock)
                {
                    bool lastFound    = false;
                    byte modulesFound = 0;

                    // Reset all modules in the chain and place the first module into Setup mode
                    SendResetPulse();

                    byte[] data = new byte[2];
                    // For all modules in the chain
                    while (!lastFound)
                    {
                        Address = defaultI2cAddress;
                        daisyLinkBus.LengthErrorBehavior = ErrorBehavior.SuppressException;
                        if (DaisyLinkVersionImplemented != ReadRegister((byte)DaisyLinkRegister.DaisyLinkVersion))
                        {
                            lastFound = true;       // If the correct version can't be read back from a device, there are no more devices in the chain
                        }
                        daisyLinkBus.LengthErrorBehavior = ErrorBehavior.ThrowException;

                        if (modulesFound != 0)      // If a device is left in Standby mode
                        {
                            data[0] = (byte)DaisyLinkRegister.Config;
                            data[1] = (byte)(lastFound ? 1 : 0);

                            Address = (byte)(totalNodeCount + modulesFound);
                            Write(data);     // Enable/disable I2C pull-ups depending on whether last in chain (place module in Active mode)
                        }

                        if (!lastFound)
                        {
                            // Next module in chain is in Setup mode so start setting it up
                            modulesFound++;         // Increase the total number of modules found connected to this socket

                            data[0] = (byte)DaisyLinkRegister.Address;
                            data[1] = (byte)(totalNodeCount + modulesFound);

                            Address = defaultI2cAddress;
                            Write(data);     // Set the I2C ID of the next module in the chain (place module in Standby mode)
                        }
                    }

                    this.StartAddress  = (byte)(totalNodeCount + 1);
                    this.NodeCount     = modulesFound;
                    this.ReservedCount = 0;
                    totalNodeCount    += modulesFound;
                    Ready = true;
                    if (modulesFound != 0)
                    {
                        socketModuleList = new DaisyLinkModule[modulesFound];       // Keep track of all DaisyLinkModules attached to this socket
                        try
                        {
                            daisyLinkInterruptPort = InterruptInputFactory.Create(Socket, daisyLinkPin, GlitchFilterMode.Off, ResistorMode.Disabled, InterruptMode.FallingEdge, null);
                        }

                        catch (Exception e)
                        {
                            throw new Socket.InvalidSocketException("There is an issue connecting the DaisyLink module to socket " + Socket +
                                                                    ". Please check that all modules are connected to the correct sockets or try connecting the DaisyLink module to a different socket", e);
                        }
                        daisyLinkInterruptPort.Interrupt += daisyLinkInterruptPort_OnInterrupt;
                    }
                }
            }