/// <summary> /// Open this instance. /// </summary> public void Open() { _sa = new SerialAgent(PortName, BaudRate, Parity, DataBits, StopBits); _analyzer = new Analyzer(); _analyzer.SetLineBreak(_lineBreak); _analyzer.DataListReadyEvent += OnDataListReady; _analyzer.SetAgent(_sa); IsOpen = true; }
public static void Main(string[] args) { Type t = Type.GetType ("Mono.Runtime"); var r = t != null ? "Mono" : ".NET"; Console.WriteLine ("WindupConsoleTest v1.0.0"); Console.WriteLine ("OS: " + Environment.OSVersion.Platform); Console.WriteLine ("Runtime: " + r + Environment.Version.Major); /* var list = SerialList.ReturnSerialList (); foreach (var port in list) { Console.WriteLine (port + "\t"); } */ if (SerialAgent.TouchAgentPort ("COM3", 9600)) { SerialAgent s; AnalyzerNT a; MyCodecFactory f; Codec codec; s = new SerialAgent ("COM3", 9600); s.AgentOpen (); a = new AnalyzerNT (s); f = new MyCodecFactory (); codec = new Codec (f, a); while (true) { Console.Write ("> "); var cmd = Console.ReadLine (); if ("EXIT" == cmd.ToUpper ()) { Console.WriteLine ("< See you later."); Thread.Sleep (700); break; } else { codec.WriteData (cmd); Thread.Sleep (200); } if (0 < codec.queue.Count) { var d = codec.queue.Dequeue (); foreach (var kv in d) { Console.WriteLine ("< " + kv.Value); } } } s.AgentClose (); } else { Console.WriteLine ("Serial ports may be occupied."); Console.WriteLine ("Press Enter exit."); Console.Read (); } }
/// <summary> /// 设置SerialAgent /// </summary> /// <returns>The agent.</returns> /// <param name="sa">Sa.</param> public ChangeFlag SetAgent(SerialAgent sa) { try { if (null != _sa) { _sa.DataRxEvent -= OnDataRxEvent; _sa.AgentClose(); } _sa = sa; _sa.DataRxEvent += OnDataRxEvent; _sa.AgentOpen(); } catch /*(Exception ex)*/ { return ChangeFlag.Failed; } return ChangeFlag.Succeed; }
/// <summary> /// 设置SerialAgent /// </summary> /// <returns>The agent.</returns> /// <param name="sa">Sa.</param> public ChangeFlag SetAgent(SerialAgent sa) { try { if (null != _sa) { _sa.DataRxEvent -= OnDataRxEvent; _sa.AgentClose(); } _sa = sa; _sa.DataRxEvent += OnDataRxEvent; _sa.AgentOpen(); } catch /*(Exception ex)*/ { return(ChangeFlag.Failed); } return(ChangeFlag.Succeed); }
public void SerialAgentConstructTest() { SerialAgent s = null; s = new SerialAgent(); Assert.IsNotNull(s); s = null; s = new SerialAgent("COM3"); Assert.IsNotNull(s); Assert.AreEqual(s.AgentPortName, "COM3"); s = null; s = new SerialAgent("COM3", 9600); Assert.IsNotNull(s); Assert.AreEqual(s.AgentPortName, "COM3"); Assert.AreEqual(s.AgentBaudRate, 9600); }
public AnalyzerNT(SerialAgent s) : base(s) { }
public AnalyzerMac(SerialAgent s) : base(s) { }
public AnalyzerLinux(SerialAgent s) : base(s) { }
/// <summary> /// Open this instance. /// </summary> public void Open() { _sa = new SerialAgent (PortName, BaudRate, Parity, DataBits, StopBits); _analyzer = new Analyzer (); _analyzer.SetLineBreak (_lineBreak); _analyzer.DataListReadyEvent += OnDataListReady; _analyzer.SetAgent (_sa); IsOpen = true; }
/// <summary> /// Touchs the agent port. /// </summary> /// <returns><c>true</c>, if agent port was touched, <c>false</c> otherwise.</returns> /// <param name="portName">Port name.</param> /// <param name="baudRate">Baud rate.</param> public static bool TouchSerialPort(string portName, int baudRate) { return(SerialAgent.TouchAgentPort(portName, baudRate)); }
public Analyzer(SerialAgent s) { tempList = new List<Int32> (); this.s = s; this.s.BindDataDelegate (this.TransferDelegate); }