public async void Connect_Should_Return_Connected_On_Valid_Data(int readTimeout, int writeTimeout, int pingTimeout) { //Act var result = await _connector.Connect(readTimeout, writeTimeout, pingTimeout); //Assert Assert.Equal(ConnectionStatus.Connected, result); }
public IoSession Open(SerialPortConfig config = null) { using (var scope = ObjectHost.Host.BeginLifetimeScope()) { if (!IsOpened()) { try { config = config ?? new SerialPortConfig(); endpoint = new SerialEndPoint(config.PortName, config.BaudRate); var serial = new SerialConnector(); serial.FilterChain.AddLast("logger", new LoggingFilter()); serial.FilterChain.AddLast("codec", new ProtocolCodecFilter(new PacketCodecFactory())); serial.FilterChain.AddLast("exceptionCounter", scope.Resolve<ExceptionCounterFilter>()); serial.Handler = scope.Resolve<PacketHandler>(); serial.SessionCreated += (sender, e) => { e.Session.SetAttributeIfAbsent(KeyName.SESSION_ERROR_COUNTER, 0); }; future = serial.Connect(endpoint); future.Await(); } catch (Exception ex) { Log.Error(ErrorCode.SerialPortSessionOpenError, ex); throw new SerialSessionOpenException(endpoint, ex); } } } if (IsOpened()) return future.Session; else throw new SerialSessionOpenException(endpoint); }
// Use this for initialization void Start() { currentMode = MotorMode.isTrackingHand; enc = gameObject.GetComponent <EncoderController>(); serialPort = gameObject.GetComponent <SerialConnector>(); serialPort.Connect(portNumber); enc.resetCount(InitialStringLength + 1000); records = new List <SpeedRecord>(); isPulling = false; }
public void KeepConnAlive() { while (_continue) { try { if (_keepConnected) { if (_serialCon.IsConnected() == false) { _serialCon.Connect(); } } } catch (TimeoutException) { } Thread.Sleep(5000); } }
static void Main(string[] args) { IoConnector serial = new SerialConnector(); // Add two filters : a logger and a codec serial.FilterChain.AddLast("logger", new LoggingFilter()); serial.FilterChain.AddLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Encoding.UTF8))); serial.ExceptionCaught += (s, e) => e.Session.Close(true); serial.MessageReceived += (s, e) => { Console.WriteLine(e.Message); }; SerialEndPoint serialEP = new SerialEndPoint("COM3", 38400); IConnectFuture future = serial.Connect(serialEP); future.Await(); if (future.Connected) { while (true) { String line = Console.ReadLine(); if (line.Trim().Equals("quit", StringComparison.OrdinalIgnoreCase)) { future.Session.Close(true); break; } future.Session.Write(line); } } else if (future.Exception != null) { Console.WriteLine(future.Exception); } Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); }
public IoSession Open(SerialPortConfig config = null) { using (var scope = ObjectHost.Host.BeginLifetimeScope()) { if (!IsOpened()) { try { config = config ?? new SerialPortConfig(); endpoint = new SerialEndPoint(config.PortName, config.BaudRate); var serial = new SerialConnector(); serial.FilterChain.AddLast("logger", new LoggingFilter()); serial.FilterChain.AddLast("codec", new ProtocolCodecFilter(new PacketCodecFactory())); serial.FilterChain.AddLast("exceptionCounter", scope.Resolve <ExceptionCounterFilter>()); serial.Handler = scope.Resolve <PacketHandler>(); serial.SessionCreated += (sender, e) => { e.Session.SetAttributeIfAbsent(KeyName.SESSION_ERROR_COUNTER, 0); }; future = serial.Connect(endpoint); future.Await(); } catch (Exception ex) { Log.Error(ErrorCode.SerialPortSessionOpenError, ex); throw new SerialSessionOpenException(endpoint, ex); } } } if (IsOpened()) { return(future.Session); } else { throw new SerialSessionOpenException(endpoint); } }
public SysTrayApp() { // Setup tray icon _ni = new NotifyIcon(); _ni.Icon = Resources.iconfinder_audio_console_44847; _ni.Text = "Arduino Volume Service"; _ni.Visible = true; // Logger to reccord info/debug stuff _logger = new Logger(100); // Setup tray icon to have a menu _contextMenus = new ContextMenus(); _contextMenus.ExitClicked += _contextMenus_ExitClicked; _contextMenus.ShowLogsClicked += _contextMenus_ShowLogsClicked; _ni.ContextMenuStrip = _contextMenus.Create(); // Device control connects to windows OS _deviceController = new DeviceController(); _deviceController.DeviceVolChangedEvent += _deviceController_DeviceVolChangedEvent; _deviceController.DeviceListResponseEvent += _deviceController_DeviceListChangedEvent; // Setup serial connector _serialCon = new SerialConnector(); _serialCon.StateChangeEvent += _serialCon_StateChangeEvent; _serialCon.CommandReceivedEvent += _serialCon_CommandReceivedEvent; _connKeepAliveThread = new Thread(KeepConnAlive); _webAccessHost = new WebConnector(_webHostUrl); _webAccessHost.WebStateChangeEvent += _webAccessHost_WebStateChangeEvent; _webAccessHost.WebCommandEvent += _webAccessHost_WebCommandEvent; _webAccessHost.WebRequestBoundDevicesChangeEvent += _webAccessHost_WebRequestBoundDevicesChangeEvent; _webAccessHost.StartWeb(); _serialCon.Connect(); _connKeepAliveThread.Start(); }
// Use this for initialization void Start() { serial = gameObject.GetComponent <SerialConnector>(); serial.Connect(3); }
public void Connect() => SerialConnector.Connect();