串口通信线程问题 [英] Serial port communication thread problem

查看:106
本文介绍了串口通信线程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

Hi Friends,

I am trying to get data from POS machine to my pc .My program is magnetic card reading program using my POS machine. 1st time I swipe the card then data received successfully and again I just swipe the card data was receiving slowly.As I think some thread is running.here is code and errors.  





我的尝试:





What I have tried:

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        SerialPortManager _spManager;
        public Form1()
        {
            InitializeComponent();
            UserInitialization();
           _spManager.StartListening();

            label1.Hide();
            label12.Hide();
            comboBox1.Hide();



        }
      
        private void UserInitialization()
        {
            _spManager = new SerialPortManager();
            SerialSettings mySerialSettings = _spManager.CurrentSerialSettings;
            bindingSource1.DataSource = mySerialSettings;
            portNameComboBox.DataSource = mySerialSettings.PortNameCollection;
            baudRateComboBox.DataSource = mySerialSettings.BaudRateCollection;
             dataBitsComboBox.DataSource = mySerialSettings.DataBitsCollection;
             parityComboBox.DataSource = Enum.GetValues(typeof(System.IO.Ports.Parity));
             stopBitsComboBox.DataSource = Enum.GetValues(typeof(System.IO.Ports.StopBits));


            _spManager.NewSerialDataRecieved += new EventHandler<SerialDataEventArgs>(_spManager_NewSerialDataRecieved);
            this.FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
        }


        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            _spManager.Dispose();
        }

        void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {

            if (this.InvokeRequired)
            {
                // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                this.BeginInvoke(new EventHandler<SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e });
                return;
            }

            int maxTextLength = 1000; // maximum text length in text box
            if (tbData.TextLength > maxTextLength)
            {
                tbData.Text = tbData.Text.Remove(0, tbData.TextLength - maxTextLength);
            }
            // This application is connected to a GPS sending ASCCI characters, so data is converted to text
    
             
             string str = Encoding.ASCII.GetString(e.Data);
            Console.WriteLine(str);
         
                tbData.AppendText(str);
          
            tbData.ScrollToCaret();
         



           
        }

8098765432000007
'AES Card Encoder.vshost.exe' (CLR v4.0.30319: AES Card Encoder.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\12.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll'. Module was built without symbols.
'AES Card Encoder.vshost.exe' (CLR v4.0.30319: AES Card Encoder.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC\office\12.0.0.0__71e9bce111e9429c\office.dll'. Module was built without symbols.
'AES Card Encoder.vshost.exe' (CLR v4.0.30319: AES Card Encoder.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'AES Card Encoder.vshost.exe' (CLR v4.0.30319: AES Card Encoder.vshost.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 

8098
765432000007

80987
654320
000
7
The thread 0xe44 has exited with code 259 (0x103).
The thread 0x2890 has exited with code 259 (0x103).

What is this "The thread 0xe44 has exited with code 259 (0x103)." error?

推荐答案

实际上这不是错误。这里有一些信息: c# - 什么是线程退出代码 - Stack Overflow [ ^ ]。
It is not an error, actually. Some info here: c# - What is a thread exit code - Stack Overflow[^].


Why data receiving slower than 1st time?


这篇关于串口通信线程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆