public void MessageReceivedEventHandler(object sender, TerminalInformationEventArgs args)
        {
            Dispatcher.Invoke((ThreadStart)delegate()
            {
                if (args.MessageByteLength < 1)
                    return;
                int len = 0;
                if (args.MessageByte.Length < args.MessageByteLength)
                    len = args.MessageByte.Length;
                else
                    len = args.MessageByteLength;
                byte[] ba = new byte[len];
                for (int i = 0; i < len; i++)
                {
                    ba[i] = args.MessageByte[i];
                }
                string resp = Encoding.UTF8.GetString(ba, 0, len);
                if (resp.StartsWith(Consts.TERM_INVALID_REQUEST, StringComparison.CurrentCultureIgnoreCase) == true)
                {
                    Run runDTUCmd = new Run("失去到DTU的连接");
                    Paragraph parDTUCmd = new Paragraph(runDTUCmd);
                    parDTUCmd.Foreground = Brushes.Red;
                    fdTerminal.Blocks.Add(parDTUCmd);
                    TI.State = TerminalInformation.TiState.Disconnected;
                }
                else
                    rtxtTerminal.AppendText(resp);

                rtxtTerminal.ScrollToEnd();
            }, null);
        }
        public void SocketStateChangeEventHandler(object sender, TerminalInformationEventArgs args)
        {
            string s = args.Message;
            if (s == null)
                return;

            Dispatcher.Invoke((ThreadStart)delegate()
            {
                if (fdTerminal.Blocks.Count > 0)
                {
                    Run runReturn = new Run("\n");
                    Paragraph parReturn = new Paragraph(runReturn);
                    parReturn.Foreground = Brushes.Black;
                    fdTerminal.Blocks.Add(parReturn);
                }
                Run runDTUCmd = new Run(s);
                Paragraph parDTUCmd = new Paragraph(runDTUCmd);
                parDTUCmd.Foreground = Brushes.Red;
                fdTerminal.Blocks.Add(parDTUCmd);

                rtxtTerminal.ScrollToEnd();
            }, null);
        }
Пример #3
0
 private void OnSocketStateChanged(object sender, TerminalInformationEventArgs args)
 {
 }