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"); }
public void UartTest_LoopbackOut31In32() { //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); ObserverTxStatusUart bufferObserver = new ObserverTxStatusUart(); this.HandlerObservable_.Subscribe(bufferObserver); // add our own handler so we don't have to grovel aroudn in there 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 UartConfigureCommand commandCreate = new UartConfigureCommand( new DigitalInputSpec(32), new DigitalOutputSpec(31), 38400, UartParity.NONE, UartStopBits.ONE); commandCreate.Alloc(rManager); commandCreate.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(10); string helloWorld = "Hello World"; byte[] helloWorldBytes = System.Text.Encoding.ASCII.GetBytes(helloWorld); LOG.Debug("Sending Hello World"); UartSendDataCommand commandSend = new UartSendDataCommand(commandCreate.UartDef, helloWorldBytes); commandSend.Alloc(rManager); commandSend.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(50); LOG.Debug("Closing Uart"); UartCloseCommand commandClose = new UartCloseCommand(commandCreate.UartDef); commandClose.Alloc(rManager); commandClose.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(50); // IUartFrom is the parent interface for all messages coming from the UARt Assert.AreEqual(1 + 1 + helloWorldBytes.Count() + 1, this.CapturedSingleQueueAllType_.OfType <IUartFrom>().Count()); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartOpenFrom>().Count(), "didn't get IUartOpenFrom"); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartReportTxStatusFrom>().Count(), "didn't get IUartReportTXStatusFrom"); IEnumerable <IUartDataFrom> readValues = this.CapturedSingleQueueAllType_.OfType <IUartDataFrom>(); Assert.AreEqual(helloWorldBytes.Count(), readValues.Count(), "Didn't find the number of expected IUartFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + +this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartCloseFrom>().Count()); // should verify close command in the resource }
public void IOIOProtocolIncoming_CheckStreamClosure() { this.CreateCaptureLogHandlerSet(); MemoryStream fakeStream = new MemoryStream(); IOIOProtocolIncoming fooOut = new IOIOProtocolIncoming(fakeStream, HandlerObservable_); fakeStream.Close(); System.Threading.Thread.Sleep(3000); }
public void IOIOProtocolIncoming_StartRunLoop() { IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); LOG.Debug("Setup Complete"); IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); // wait for reply System.Threading.Thread.Sleep(2000); Assert.IsNotNull(CapturedConnectionState_.EstablishConnectionFrom_); }
public void IOIOProtocolOutgoing_CheckInterfaceVersion() { IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); LOG.Debug("Setup Complete"); 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 fooOut.checkInterfaceVersion(); // wait for reply System.Threading.Thread.Sleep(2000); Assert.IsTrue(CapturedConnectionState_.Supported_.IsSupported, " the HandlerContainer_ returned not supported interface."); }
public void ServoTest_SimpleServoTest() { //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream()); System.Threading.Thread.Sleep(20); // wait for us to get the hardware ids int pwmFrequency = 100; DigitalOutputSpec pwmPinSpec = new DigitalOutputSpec(3, DigitalOutputSpecMode.NORMAL); // configure for servo PwmOutputConfigureCommand commandCreatePWM = new PwmOutputConfigureCommand(pwmPinSpec, pwmFrequency); commandCreatePWM.Alloc(rManager); commandCreatePWM.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(100); for (int i = 0; i < 4; i++) { // change it after settling PwmOutputUpdateCommand lowValue = new PwmOutputUpdatePulseWidthCommand(commandCreatePWM.PwmDef, 600); lowValue.Alloc(rManager); lowValue.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(500); // change it after settling PwmOutputUpdateCommand highValue = new PwmOutputUpdatePulseWidthCommand(commandCreatePWM.PwmDef, 2000); highValue.Alloc(rManager); highValue.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(500); } PwmOutputCloseCommand commandReleasePwm = new PwmOutputCloseCommand(commandCreatePWM.PwmDef); commandReleasePwm.Alloc(rManager); commandReleasePwm.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(500); //IEnumerable<IReportAnalogPinValuesFrom> readValues = this.HandlerSingleQueueAllType_.CapturedMessages_ // .OfType<IReportAnalogPinValuesFrom>(); //Assert.IsTrue(readValues.Count() >= 1, "Didn't find the number of expected IReportAnalogPinValuesFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + +this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); // should verify close command }
public void CreateAnalogInputOutputTo_AnalogLoopbackOut31In32() { //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); 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 AnalogInputConfigureCommand commandCreateIn = new AnalogInputConfigureCommand(31, true); commandCreateIn.Alloc(rManager); commandCreateIn.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(10); DigitalOutputSpec pwmPinSpec = new DigitalOutputSpec(32, DigitalOutputSpecMode.NORMAL); // set analog "voltage" PwmOutputConfigureCommand commandCreatePWM = new PwmOutputConfigureCommand(pwmPinSpec, 1000, 0.3f); commandCreatePWM.Alloc(rManager); commandCreatePWM.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(100); // change it after settling PwmOutputUpdateCommand commandChangePWM = new PwmOutputUpdateDutyCycleCommand(commandCreatePWM.PwmDef, 0.7f); commandChangePWM.Alloc(rManager); commandChangePWM.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(100); PwmOutputCloseCommand commandReleasePwm = new PwmOutputCloseCommand(commandCreatePWM.PwmDef); commandReleasePwm.Alloc(rManager); commandReleasePwm.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(50); IEnumerable <IReportAnalogPinValuesFrom> readValues = this.CapturedSingleQueueAllType_ .OfType <IReportAnalogPinValuesFrom>(); Assert.IsTrue(readValues.Count() >= 1, "Didn't find the number of expected IReportAnalogPinValuesFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); // should verify close command }
public void IOIOProtocolOutgoing_ToggleLED() { IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); LOG.Debug("Setup Complete"); 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 fooOut.setPinDigitalOut(Spec.LED_PIN, false, DigitalOutputSpecMode.NORMAL); for (int i = 0; i < 8; i++) { System.Threading.Thread.Sleep(200); fooOut.setDigitalOutLevel(Spec.LED_PIN, true); System.Threading.Thread.Sleep(200); fooOut.setDigitalOutLevel(Spec.LED_PIN, false); } Assert.IsTrue(true, "there is no status to check"); }
public void IOIOProtocolOutgoing_DigitalLoopbackOut31In32() { IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); LOG.Debug("Setup Complete"); IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream()); System.Threading.Thread.Sleep(50); // receive the HW ID LOG.Info("This test requires Pin 31 and 32 be shorted together"); fooOut.setPinDigitalIn(31, DigitalInputSpecMode.FLOATING); // request to be told of state change. system will acknowledge this fooOut.setChangeNotify(31, true); // first change that will be captured... fooOut.setPinDigitalOut(32, false, DigitalOutputSpecMode.NORMAL); // second change that is captured fooOut.setDigitalOutLevel(32, true); // we could wait until our acknowledgements are received System.Threading.Thread.Sleep(300); // all log methods contain method name which is in the interface so this is reasonably safe // we get one change event as soon as the Pin input Pin is configured + 2 changes in test int matchingLogs = this.CapturedLogs_.CapturedLogs_.Count(s => s.Contains(typeof(ReportDigitalInStatusFrom).Name)); // sometimes we get 3 and sometimes 4 (!?) Assert.IsTrue(3 == matchingLogs || 4 == matchingLogs, "Should have captured 3 or 4 input changes, not " + matchingLogs + ". Are pins 31 and 32 shorted together"); // verify the system acknowledged our request to be notified of state change Assert.AreEqual(1, this.CapturedSingleQueueAllType_ .OfType <ISetChangeNotifyMessageFrom>().Where(m => m.Pin == 31).Count() , "Unexpected count for IReportDigitalInStatusFrom"); // verify we got Pin state changes for 31 Assert.AreEqual(3, this.CapturedSingleQueueAllType_ .OfType <IReportDigitalInStatusFrom>().Where(m => m.Pin == 31).Count() , "Unexpected count for IReportDigitalInStatusFrom"); }
public static string TryAndFindIOIODevice() { LOG.Debug("Starting TryAndFindIOIODevice"); IOIOConnectionFactory factory = new SerialConnectionFactory(); ICollection <IOIOConnection> connections = factory.CreateConnections(); LOG.Info("Found " + connections.Count + " possible com ports"); string goodConnectionName = null; // probably don't need this since we aren't connected. foreach (IOIOConnection oneConn in connections) { // uses custom setup because we are trying to find IOIO not trying to do work with them try { LOG.Info("Trying " + oneConn.ConnectionString()); try { oneConn.WaitForConnect(); // logging without real capture ObserverLogAndCaptureLog handlerLog = new ObserverLogAndCaptureLog(1); // so we can verify ObserverConnectionState handlerState = new ObserverConnectionState(); IOIOHandlerObservable observers = new IOIOHandlerObservable(); observers.Subscribe(handlerState); observers.Subscribe(handlerLog); IOIOProtocolIncoming foo = new IOIOProtocolIncoming(oneConn.GetInputStream(), observers); System.Threading.Thread.Sleep(50); // WaitForChangedResult for hw ids if (handlerState.EstablishConnectionFrom_ != null) { goodConnectionName = oneConn.ConnectionString(); LOG.Info("Selecting " + oneConn.ConnectionString()); oneConn.Disconnect(); break; } else { LOG.Info("Ignoring " + oneConn.ConnectionString()); oneConn.Disconnect(); } } catch (System.UnauthorizedAccessException e) { LOG.Info("No Permission " + oneConn.ConnectionString() + e.Message); } } catch (ConnectionLostException e) { LOG.Debug("Cought Exception Lost " + e.Message); // just ignore it because will get this when we Disconnect } } if (goodConnectionName != null) { LOG.Debug("TryAndFindIOIODevice successfull"); } else { LOG.Debug("TryAndFindIOIODevice failed"); } return(goodConnectionName); }