public void SerialConnectionFactory_CreateConnectionBad() { IOIOConnectionFactory factory = new SerialConnectionFactory(); IOIOConnection connection = factory.CreateConnection(TestHarnessSetup.BAD_CONN_NAME); LOG.Info("Should have failed test on " + TestHarnessSetup.BAD_CONN_NAME); }
/// <summary> /// Creates a "good" serial GoodConnection_ and registeres it for automatic closure /// </summary> /// <param name="leaveConnectionOpen">defaults to true because that is the way the first tests ran. /// set to false for IOIOImpl</param> /// <returns>connected that is set on instance variable</returns> internal IOIOConnection CreateGoodSerialConnection(bool leaveConnectionOpen = true) { IOIOConnectionFactory factory = new SerialConnectionFactory(); GoodConnection_ = factory.CreateConnection(TestHarnessSetup.GOOD_CONN_NAME); this.ConnectionsOpenedDuringTest.Add(GoodConnection_); // always add connections used by incoming if (leaveConnectionOpen) { GoodConnection_.WaitForConnect(); // actually IsOpen the GoodConnection_ } LOG.Debug("Done CreateGoodSerialConnection"); return(GoodConnection_); }
public void SerialConnectionFactory_CreateConnections() { IOIOConnectionFactory factory = new SerialConnectionFactory(); ICollection <IOIOConnection> connections = factory.CreateConnections(); Assert.IsTrue(connections.Count > 0); LOG.Info("Found " + connections.Count + " possible com ports"); /// probably don't need this since we aren't connected. foreach (IOIOConnection oneConn in connections) { oneConn.Disconnect(); } }
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 ConnectionViewModel( ConnectionManager connectionManager, SerialPortsProvider serialPortsProvider, SerialConnectionFactory serialPortConnectionFactory, SerialBoundRatesProvider serialPortBoundRatesProvider, MessageBoxDisplayer messageBoxDisplayer, UiDispatcherProvider uiDispatcherProvider) { this.SerialPorts = serialPortsProvider.GetPortNames(); this.BoundRates = serialPortBoundRatesProvider.GetBoundRates(); this.connectionManager = connectionManager; this.serialPortConnectionFactory = serialPortConnectionFactory; this.messageBoxDisplayer = messageBoxDisplayer; this.uiDispatcherProvider = uiDispatcherProvider; this.ConnectCommand = new RelayCommand(this.Connect, this.CanConnect); this.DisconnectCommand = new RelayCommand(this.Disconnect, this.CanDisconnect); this.SelectedSerialPort = this.SerialPorts.FirstOrDefault(); this.SelectedBoundRate = this.BoundRates.First(); }
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); }
public Gemini2000ClockReader(int clockAddress, string portName) { this.clockAddress = clockAddress; serialConnection = SerialConnectionFactory.GetSerialConnection(portName, baudRate, parity, dataBits, stopBits, isOverlappedRead); serialConnection.Open(); }