Ejemplo n.º 1
0
        public void IOIOImpl_ToggleLED()
        {
            IOIOConnection ourConn = this.CreateGoodSerialConnection(false);

            this.CreateCaptureLogHandlerSet();
            // we'll add the handler state on top of the default handlers so we don't have to peek into impl
            IOIO ourImpl = CreateIOIOImplAndConnect(ourConn,
                                                    new List <IObserverIOIO>()
            {
                this.CapturedConnectionState_, this.CapturedSingleQueueAllType_, this.CapturedLogs_
            });

            LOG.Debug("Setup Complete");
            System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids

            DigitalOutputSpec ledSpec = new DigitalOutputSpec(Spec.LED_PIN);
            // SHOULD USE THE FACTORY instead of this lame ...
            IDigitalOutputConfigureCommand confDigitalOut = new DigitalOutputConfigureCommand(
                ledSpec);
            IDigitalOutputValueSetCommand turnItOn  = new DigitalOutputSetValueCommand(ledSpec, true);
            IDigitalOutputValueSetCommand turnItOff = new DigitalOutputSetValueCommand(ledSpec, false);

            ourImpl.PostMessage(confDigitalOut);
            for (int i = 0; i < 8; i++)
            {
                System.Threading.Thread.Sleep(150);
                ourImpl.PostMessage(turnItOn);
                System.Threading.Thread.Sleep(150);
                ourImpl.PostMessage(turnItOff);
            }
            // this test can fail if we can't connect to the device but otherwise no way to read pin 1 values
            Assert.IsTrue(true, "there is no status to check");
        }
        public void CreateDigitalOutputTo_ToggleLED()
        {
            IOIOConnection ourConn = this.CreateGoodSerialConnection();

            this.CreateCaptureLogHandlerSet();
            // add our handlers on to p of default so we don't have to grovel around in the internal variables
            IOIOProtocolIncoming fooIn  = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_);
            IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream());

            System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids

            DigitalOutputSpec ledSpec = new DigitalOutputSpec(Spec.LED_PIN);
            IDigitalOutputConfigureCommand commandSetup = new DigitalOutputConfigureCommand(
                ledSpec, false);
            IDigitalOutputValueSetCommand commandOn  = new DigitalOutputSetValueCommand(ledSpec, true);
            IDigitalOutputValueSetCommand commandOff = new DigitalOutputSetValueCommand(ledSpec, false);

            //// TODO should use the hardware from the captured connection
            IResourceManager rManager = new ResourceManager(Hardware.IOIO0003);

            commandSetup.Alloc(rManager);
            commandOn.Alloc(rManager);
            commandOff.Alloc(rManager);

            commandSetup.ExecuteMessage(fooOut);
            for (int i = 0; i < 8; i++)
            {
                System.Threading.Thread.Sleep(200);
                commandOn.ExecuteMessage(fooOut);
                System.Threading.Thread.Sleep(200);
                commandOff.ExecuteMessage(fooOut);
            }
            Assert.IsTrue(true, "there is no status to check");
        }
Ejemplo n.º 3
0
        public void IOIOImpl_DigitaLoopbackOut31In32()
        {
            IOIOConnection ourConn = this.CreateGoodSerialConnection(false);

            this.CreateCaptureLogHandlerSet();
            LOG.Debug("Setup Complete");

            // we'll add the handler state on top of the default handlers so we don't have to peek into impl
            IOIO ourImpl = CreateIOIOImplAndConnect(ourConn,
                                                    new List <IObserverIOIO>()
            {
                this.CapturedConnectionState_, this.CapturedSingleQueueAllType_, this.CapturedLogs_
            });

            System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids

            // SHOULD USE THE FACTORY instead of this lame ...
            IDigitalOutputConfigureCommand confDigitalOut =
                new DigitalOutputConfigureCommand(new DigitalOutputSpec(31));
            IDigitalInputConfigureCommand configDigitalIn =
                new DigitalInputConfigureCommand(new DigitalInputSpec(32, DigitalInputSpecMode.PULL_UP), true);

            IDigitalOutputValueSetCommand turnItOn  = new DigitalOutputSetValueCommand(new DigitalOutputSpec(31), true);
            IDigitalOutputValueSetCommand turnItOff = new DigitalOutputSetValueCommand(new DigitalOutputSpec(31), false);

            ourImpl.PostMessage(confDigitalOut);
            ourImpl.PostMessage(configDigitalIn);
            for (int i = 0; i < 8; i++)
            {
                System.Threading.Thread.Sleep(100);
                ourImpl.PostMessage(turnItOn);
                System.Threading.Thread.Sleep(100);
                ourImpl.PostMessage(turnItOff);
            }
            System.Threading.Thread.Sleep(100);

            IEnumerable <IMessageFromIOIO> digitalMessagesIn = this.CapturedSingleQueueAllType_;
            int changeCount =
                digitalMessagesIn.OfType <IReportDigitalInStatusFrom>().Where(m => m.Pin == 32).Count();

            Assert.AreEqual(1 + (2 * 8), changeCount, "trying to figure out how many changes we'd see");
        }