Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
        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 ();
            }
        }
Ejemplo n.º 3
0
 /// <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;
 }
Ejemplo n.º 4
0
 /// <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);
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public AnalyzerNT(SerialAgent s)
     : base(s)
 {
 }
Ejemplo n.º 7
0
 public AnalyzerMac(SerialAgent s)
     : base(s)
 {
 }
Ejemplo n.º 8
0
 public AnalyzerLinux(SerialAgent s)
     : base(s)
 {
 }
Ejemplo n.º 9
0
 /// <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;
 }
Ejemplo n.º 10
0
 /// <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));
 }
Ejemplo n.º 11
0
 public Analyzer(SerialAgent s)
 {
     tempList = new List<Int32> ();
     this.s = s;
     this.s.BindDataDelegate (this.TransferDelegate);
 }