public void MyTestCleanup() { DevicesOpenedDuringTest.ForEach(x => { //x.Sync(); // would like to reset so board is in original state every time we connect x.SoftReset(); // resets state without dropping connection // would we do this and wait instead //x.HardReset(); // like disconnecting the power x.Disconnect(); LOG.Info("Disconnected " + x.ToString()); }); ConnectionsOpenedDuringTest.ForEach(x => { if (x.CanClose()) { x.Disconnect(); LOG.Info("Disconnected " + x.ToString()); } }); GoodConnection_ = null; CapturedLogs_ = null; CapturedConnectionState_ = null; CapturedSingleQueueAllType_ = null; HandlerObservable_ = null; System.Threading.Thread.Sleep(100); LOG.Debug("Done MyTestCleanup"); }
/// <summary> /// Creates a standard HandlerContainer_ set and put it in instance variables so all tests can use. /// Create one of each of the standard types /// </summary> internal void CreateCaptureLogHandlerSet() { // create handlers of our own so we don't have to peek in and understand how IOIOImpl is configured CapturedSingleQueueAllType_ = new ObserverCaptureSingleQueue(); CapturedLogs_ = new ObserverLogAndCaptureLog(10); CapturedConnectionState_ = new ObserverConnectionState(); HandlerObservable_ = new IOIOHandlerObservableNoWait(); HandlerObservable_.Subscribe(CapturedLogs_); HandlerObservable_.Subscribe(CapturedConnectionState_); HandlerObservable_.Subscribe(CapturedSingleQueueAllType_); }
public MainWindow() { InitializeComponent(); string comPort = FindDeviceHack.TryAndFindIOIODevice(); ComPort_Field.Text = comPort; if (comPort != null) { IOIOConnection connection = new SerialConnectionFactory().CreateConnection(comPort); ObserverConnectionState handlerCaptureState = new ObserverConnectionState(); RotationObserver rotationObserver = new RotationObserver( L3G4200DConstants.Gyro_DPS_LSB_2000, // must match the sensitivity in register initialization PollingIntervalMsec, this.X_Angle, this.Y_Angle, this.Z_Angle, this.X_RawField, this.Y_RawField, this.Z_RawField, this.X_CallibField, this.Y_CallibField, this.Z_CallibField, this.Teapot ); OurImpl_ = new IOIOImpl(connection, new List <IObserverIOIO>() { handlerCaptureState, rotationObserver } ); OurImpl_.WaitForConnect(); IConnectedDeviceResponse device = handlerCaptureState.ConnectedDeviceDescription(); if (device != null) { // could display board details } CommandFactory_ = new IOIOMessageCommandFactory(); ConfigureCompass(); ConfigureTimedEvents(); } else { ComPort_Field.Text = "Unable to find an IOIO device"; } }
public MainWindow() { InitializeComponent(); string comPort = FindDeviceHack.TryAndFindIOIODevice(); ComPort_Field.Text = comPort; if (comPort != null) { IOIOConnection connection = new SerialConnectionFactory().CreateConnection(comPort); ObserverConnectionState handlerCaptureState = new ObserverConnectionState(); MessageObserver textBoxObserver = new MessageObserver(this.MessageLog); OurImpl_ = new IOIOImpl(connection, new List <IObserverIOIO>() { handlerCaptureState, textBoxObserver } ); OurImpl_.WaitForConnect(); IConnectedDeviceResponse device = handlerCaptureState.ConnectedDeviceDescription(); if (device != null) { BoardDetails.Text = "Bootloader:" + device.BootloaderId + "\n" + "Firmware:" + device.FirmwareId + "\n" + "Hardware: " + device.HardwareId; } IOIOMessageCommandFactory commandFactory = new IOIOMessageCommandFactory(); ConfigurePwm(commandFactory); ConfigureLed(commandFactory); ConfigureDigitalInput(commandFactory); } else { //this.Close(); BoardDetails.Text = "Unable to find an IOIO device"; } }
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); }