Ejemplo n.º 1
0
        private void AddLog(string log)
        {
            if (TxtLog.IsDisposed)
            {
                return;
            }

            // 从ui线程去操作ui
            if (TxtLog.InvokeRequired)
            {
                TxtLog.Invoke(new AddLogHandler(AddLog), log);
            }
            else
            {
                TxtLog.AppendText($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {log}\r\n");
            }
        }
Ejemplo n.º 2
0
        private async void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string RfcNumber = string.Empty;

            if (CheckConnect())
            {
                try
                {
                    string line = serialPort1.ReadLine();
                    TxtLog.Invoke(new MethodInvoker(delegate
                    {
                        TxtLog.Text          += DateTime.Now + ": " + line + "\n";
                        TxtLog.SelectionStart = TxtLog.Text.Length;
                        TxtLog.ScrollToCaret();
                    }));

                    if (line == "timeWait is Done\r")
                    {
                        timeWaitIsDone = true;
                    }
                    else
                    if (line.Substring(0, CardIDStringBegin.Length) == CardIDStringBegin)
                    {
                        RfcNumber = line.Substring(CardIDStringBegin.Length, line.Length - CardIDStringBegin.Length);
                        TxtCardID.Invoke(new MethodInvoker(delegate
                        {
                            TxtCardID.Text = RfcNumber;
                        }));


                        await PostNfcCard(RfcNumber);
                    }
                }
                catch (Exception ex)
                { }
            }
        }