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); }
private void PostImpl(int id, string command) { string commandWithId = $"#{id} {command}"; byte[] cmd = Encoding.ASCII.GetBytes(commandWithId + "\n"); SerialConnector.Post(cmd); SendRawData?.Invoke(this, new UArmRawMessageEventArgs(commandWithId)); }
// Use this for initialization void Start() { samples = new List <EncoderCount>(); AnglePerCount = 2.0f * Mathf.PI / 360 / EncoderCounts; LengthPerCount = AnglePerCount * ItomakiRadius; serialPort = gameObject.GetComponent <SerialConnector>(); }
// 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 Connect(SerialConnector con) { if (con != null) { con.PropertyChanged -= bindingConnection_CurrentItemChanged; } this.con = con; //bindingConnection.DataSource = con; con.PropertyChanged += bindingConnection_CurrentItemChanged; bindingConnection_CurrentItemChanged(null, null); }
public void InitializeConnector() { DeviceMessage = new DeviceListener(); SourceInitialized += DeviceMessage.RegisterListener; Serialcon = new SerialConnector { Mw = this }; Serialcon.Event += new ConnectorHandler(ConnectorCallBack); DeviceMessage.Event += Serialcon.SerialChangedEvent; }
public SerialSession(SerialConnector service, SerialEndPoint endpoint, SerialPort serialPort) : base(service) { _processor = service; base.Config = new SessionConfigImpl(serialPort); if (service.SessionConfig != null) Config.SetAll(service.SessionConfig); _filterChain = new DefaultIoFilterChain(this); _serialPort = serialPort; _endpoint = endpoint; _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived); }
public void ConnectSerial(string portName, int baudRate, Parity parity, int databits, StopBits stopbits, Handshake handshake, int readTimeout, int writeTimeout) { SerialConnector con = (SerialConnector)dp.Connections.First(x => x is SerialConnector); con.PortName = portName; con.BaudRate = baudRate; con.Parity = parity; con.DataBits = databits; con.StopBits = stopbits; con.Handshake = handshake; con.ReadTimeout = readTimeout; con.WriteTimeout = writeTimeout; dp.Connection = con; Connect(); }
public void ConnectSerial(string portName, int baudRate) { SerialConnector con = (SerialConnector)dp.Connections.First(x => x is SerialConnector); con.PortName = portName; con.BaudRate = baudRate; con.Parity = con.Parity <= 0 ? Parity.None : con.Parity; con.DataBits = con.DataBits <= 0 ? 8 : con.DataBits; con.StopBits = con.StopBits <= 0 ? StopBits.One : con.StopBits; con.Handshake = con.Handshake <= 0 ? Handshake.None : con.Handshake; con.ReadTimeout = con.ReadTimeout <= 0 ? 500 : con.ReadTimeout; con.WriteTimeout = con.WriteTimeout <= 0 ? 500 : con.WriteTimeout; dp.Connection = con; Connect(); }
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(); }
static IFilter GetFilter() { double Fl = Common.Normalize(5000); double Fh = Common.Normalize(15000); LowPassFir lpf = new LowPassFir(16, Fl); BandPassFir bpf = new BandPassFir(16, Fl, Fh); HighPassFir hpf = new HighPassFir(16, Fh); PeakingEqualizer peql = new PeakingEqualizer(Common.Normalize(900), 3, 1.5); PeakingEqualizer peqm = new PeakingEqualizer(Common.Normalize(8000), 5, 2); PeakingEqualizer peqh = new PeakingEqualizer(Common.Normalize(20000), 2, 4); Delay dl = new Delay(4); Delay dm = new Delay(8); Delay dh = new Delay(16); #if OUTPUT_COEF using (StreamWriter writer = new StreamWriter("coef.txt")) { Write(writer, "LPF", lpf); Write(writer, "BPF", bpf); Write(writer, "HPF", hpf); Write(writer, "PEQ L", peql); Write(writer, "PEQ M", peqm); Write(writer, "PEQ H", peqh); Write(writer, "DLY L", dl); Write(writer, "DLY M", dm); Write(writer, "DLY H", dh); } #endif IFilter low = new SerialConnector(new IFilter[] { lpf, peql, dl }); IFilter mid = new SerialConnector(new IFilter[] { bpf, peqm, dm }); IFilter hig = new SerialConnector(new IFilter[] { hpf, peqh, dh }); IFilter filter = new Mixer( new IFilter[] { low, mid, hig }, new Double[] { 2, 1, 0.5 }); return(filter); }
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(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); SerialConnector serialconnector = (SerialConnector)target; if (GUILayout.Button("Open")) { serialconnector.OnClick_Open(); } if (GUILayout.Button("Close")) { serialconnector.OnClick_Close(); } if (GUILayout.Button("Write test")) { serialconnector.OnClick_Write(); } if (GUILayout.Button("Reset")) { serialconnector.OnClick_Reset(); } }
private static BasicConnector CreateConnectorByMode(ConnectionModes mode, CommunicationInfoStruct info) { BasicConnector res; //TODO: add more modes switch (mode) { case ConnectionModes.Usb: case ConnectionModes.Bluetooth: res = new SerialConnector(info.SerialInfo.RxPort, info.SerialInfo.TxPort, info.SerialInfo.Baudrate); break; case ConnectionModes.WiFi: res = new TcpConnector(info.TcpInfo.Ip, info.TcpInfo.Port); break; default: res = null; break; } return(res); }
public SerialConnectorTests() { //Arrange _connector = new SerialConnector(new FakeSerialSocket()); }
public void ConnectWith(SerialConnector c) { connector = c; }
public void Connect() => SerialConnector.Connect();
public void Disconnect() => SerialConnector.Disconnect();
// Use this for initialization void Start() { serialPort = gameObject.GetComponent <SerialConnector>(); }
// Use this for initialization void Start() { serial = gameObject.GetComponent <SerialConnector>(); serial.Connect(3); }
public void PostWithoutId(string command) { SerialConnector.Post(Encoding.ASCII.GetBytes(command + "\n")); }
public void Connect(SerialConnector con) { this.con = con; bindingConnection.DataSource = con; bindingConnection_CurrentItemChanged(null, null); }
public void mainloop() { var hvc_tracking_result = new HVCTrackingResult(); var img = new GrayscaleImage(); HVCP2Api.EXECUTE_RET exec_ret; var sw = new Stopwatch(); while (true) { try { if (this.isConnectRequest) { var connector = new SerialConnector(); var exec_func = 0x00; if (BodyDetectionCheck.Checked == true) { exec_func += p2def.EX_BODY; } if (HandDetectionCheck.Checked == true) { exec_func += p2def.EX_HAND; } if (FaceDetectionCheck.Checked == true) { exec_func += p2def.EX_FACE; } if (FaceDirectionCheck.Checked == true) { exec_func += p2def.EX_DIRECTION; } if (AgeDetectionCheck.Checked == true) { exec_func += p2def.EX_AGE; } if (GenderDetectionCheck.Checked == true) { exec_func += p2def.EX_GENDER; } if (GazeDetectionCheck.Checked == true) { exec_func += p2def.EX_GAZE; } if (BlinkDetectionCheck.Checked == true) { exec_func += p2def.EX_BLINK; } if (ExpressionDetectionCheck.Checked == true) { exec_func += p2def.EX_EXPRESSION; } if (RecognitionDetectionCheck.Checked == true) { exec_func += p2def.EX_RECOGNITION; } this.hvc_p2_api = new HVCP2Api(connector, exec_func, StablirizationCheck.Checked); var comnum = int.Parse(this.connect_comport.Substring(3)); var ret = this.hvc_p2_api.connect(comnum, 9600, timeout * 1000); if (ret == true) { HVCP2Wrapper.GET_VERSION_RET result; this.isConnectRequest = false; var retcode = _check_connection(this.hvc_p2_api, out result); if (retcode == true) { _get_hvc_version(result); _set_hvc_p2_parameters(this.hvc_p2_api); // Sets STB library parameters _set_stb_parameters(hvc_p2_api); this.isConnected = true; } else { this.SetToDefault(); try { this.hvc_p2_api.disconnect(); } catch { } } } } if (this.isConnected) { if (this.isRegistExecute) { _regist_exec(this.hvc_p2_api); this.SetToDefault(); try { this.hvc_p2_api.disconnect(); } catch { } } else { this.isExecuting = true; sw.Reset(); sw.Start(); exec_ret = hvc_p2_api.execute(output_img_type, hvc_tracking_result, img); sw.Stop(); this.isExecuting = false; if (output_img_type != p2def.OUT_IMG_TYPE_NONE) { img.save(img_fname); } this.SetText(string.Format(" ==== Elapsed time:{0}[msec] ====", sw.ElapsedMilliseconds)); this.SetText(Environment.NewLine); this.SetText(hvc_tracking_result.ToString()); this.SetText(Environment.NewLine); this.SetText(string.Format(" Press Stop Button to end:", sw.ElapsedMilliseconds)); this.SetText(Environment.NewLine); this.SetText(Environment.NewLine); System.Windows.Forms.Application.DoEvents(); } } if (this.isEndRequest) { try { this.hvc_p2_api.disconnect(); } catch { } break; } } catch (Exception ex) { this.SetText(string.Format("Unexpected exception : {0}", ex.Message)); this.SetText(Environment.NewLine); this.SetToDefault(); try { this.hvc_p2_api.disconnect(); } catch { } } System.Threading.Thread.Sleep(10); } }
public void TestConstructorNull() { IConnector serialConnector = new SerialConnector(null, 100, 100, 100); }
public void TestSerialConnectorWrite() { IConnector serialConnector = new SerialConnector(); Assert.AreEqual(false, serialConnector.Write("speed", "200")); }