예제 #1
0
        public void TestPackingPayload()
        {
            var device  = new WifiModules.DW700();
            var message = device.GetChargeStateResp("UnitTest");

            Console.WriteLine(message);
        }
        public void Heartbeat(Action <string> messageReadedAction)
        {
            var module = new WifiModules.DW700();

            while (_continueFlag)
            {
                var message = module.GetWifiStat();
                Write(message);
                Thread.Sleep(10000);
            }
        }
        public void Write(Func <string> input)
        {
            StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
            string         command;
            var            module = new WifiModules.DW700();

            while (_continueFlag)
            {
                var args = input().Split(' ');
                if (args.Length == 0)
                {
                    continue;
                }
                command = args[0];
                if (stringComparer.Equals("q", command))
                {
                    Stop();
                }
                else if (command == "0")
                {
                    var message = module.ResetCommand();
                    Write(message);
                }
                else if (command == "e")
                {
                    if (args.Length < 2)
                    {
                        continue;
                    }
                    var message = module.NotifyError(int.Parse(args[1]));
                    Write(message);
                }
                else if (command == "clean")
                {
                    if (args.Length < 2)
                    {
                        continue;
                    }
                    var message = module.StartClean(args[1]);
                    Write(message);
                }
            }
        }
        public void Read(Action <string> messageReadedAction)
        {
            var module = new WifiModules.DW700();

            while (_continueFlag)
            {
                try
                {
                    //从串口读到消息(udp消息,或者操作app触发的消息)就会自动回复
                    string message = _serialPort.ReadLine();
                    messageReadedAction?.Invoke(message);
                    if (message.StartsWith("`"))
                    {
                        module.AutoResponse(message, Write);
                    }
                }
                catch (TimeoutException) { }
            }
            _serialPort.Close();
        }
예제 #5
0
        private void HandleRequest(string data)
        {
            var subs   = data.Split(' ');
            var module = new WifiModules.DW700();

            if (subs[0].ToLower() == "error")
            {
                var message = module.NotifyError(Convert.ToInt32(subs[1]));
                _spc.Write(message);
            }
            else if (subs[0].ToLower() == "clean")
            {
                var message = module.StartClean(subs[1]);
                _spc.Write(message);
            }
            else
            {
                return;
            }
            ResponseToSender();
        }