Esempio n. 1
0
        private void CmdQueryState(object sender, RoutedEventArgs e)
        {
            if (_commandService == null || !_commandService.IsOpen)
            {
                MessageBox.Show("The port is not opened.");
                return;
            }

            bool isError;
            var  reault = _commandService.QueryState(out isError);

            if (reault == SendResult.Success)
            {
                MessageBox.Show($"The terminal state is {isError}.");
                return;
            }
            else
            {
                MessageBox.Show($"Command failed:{reault}.");
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter serial port name:");
            var portName = Console.ReadLine();

            Console.WriteLine("Enter serial port baud rate:");
            var baudRate = Console.ReadLine();
            MyCommandService _commandService = new MyCommandService(portName, Convert.ToInt32(baudRate));

            _commandService.HeartReport += _commandService_HeartReport;
            _commandService.Open();
            while (true)
            {
                Console.WriteLine("Enter command");
                Console.WriteLine("QueryState: Send query-state command to serinal port.");
                Console.WriteLine("Exit: Exit the application.");
                var key = Console.ReadLine();
                if (key.Equals("QueryState", StringComparison.OrdinalIgnoreCase))
                {
                    bool isError;
                    var  reault = _commandService.QueryState(out isError);
                    if (reault == SendResult.Success)
                    {
                        Console.WriteLine($"The terminal state is {isError}.");
                        return;
                    }
                    else
                    {
                        Console.WriteLine($"Command failed:{reault}.");
                    }
                }
                else if (key.Equals("Exit", StringComparison.OrdinalIgnoreCase))
                {
                    _commandService.Close();
                    Environment.Exit(0);
                }
            }
        }