Dushan Madushanka Ответов: 2

Проблема потока связи последовательного порта


Привет Друзья,
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.  


Что я уже пробовал:

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?

2 Ответов

Рейтинг:
1

CPallini

На самом деле это не ошибка. Немного информации здесь: c# - что такое код выхода потока-переполнение стека[^].


Dushan Madushanka

Почему данные поступают медленнее, чем в 1-й раз?

Dushan Madushanka

Почему получение данных происходит медленнее, чем в 1-й раз?

Рейтинг:
0

Dushan Madushanka

Why data receiving slower than 1st time?