public void IOIOHandlerObservableTest_SingleThread() { IOIOHandlerObservable notifier = new IOIOHandlerObservable(); UartFromObserver fromObsv = new UartFromObserver(); UartFromPolyObserver dataFromObsv = new UartFromPolyObserver(); notifier.Subscribe(fromObsv); notifier.Subscribe(dataFromObsv); notifier.HandleMessage(new UartDataFrom(0, 0, null)); notifier.HandleMessage(new UartCloseFrom(0)); notifier.HandleMessage(new UartOpenFrom(0)); System.Threading.Thread.Sleep(20); Assert.AreEqual(3, fromObsv.count); Assert.AreEqual(1, dataFromObsv.countData); Assert.AreEqual(1, dataFromObsv.countOpen); Assert.AreEqual(1, dataFromObsv.countClose); Assert.AreEqual(1, fromObsv.managedThreads.Count); Assert.IsTrue(fromObsv.managedThreads.SetEquals(dataFromObsv.managedThreads)); }
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); }