View difference between Paste ID: nFLk2XS6 and AatFELcJ
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
using System.IO.Ports;
11
using System.Threading;
12
namespace WindowsFormsApplication1
13
{
14
    public partial class Form1 : Form
15
    {
16
17
        volatile bool _devam1=false, _devam2=false,durum=true;
18
        //
19
       
20
        public Form1()
21
        {
22
            InitializeComponent();
23
24
25
            CheckForIllegalCrossThreadCalls = false;
26
27
            serialPort1.PortName = "COM3";
28
            serialPort1.BaudRate = 9600;
29
            serialPort1.DataBits = 8;
30
31
            serialPort2.PortName = "COM5";
32
            serialPort2.BaudRate = 9600;
33
            serialPort2.DataBits = 8;
34
35
            
36
        }
37
38
        //
39
        private void button1_Click(object sender, EventArgs e)
40
        {
41
42
        }
43
44
45
        //
46
        private void button2_Click(object sender, EventArgs e)
47
        {
48
49
            if (!serialPort1.IsOpen) { serialPort1.Open();  }
50
			
51
            _devam1 = true;
52
			
53
			(new Thread(new ThreadStart(this.Read1))).Start();
54
55
            
56
57
            if (!serialPort2.IsOpen) { serialPort2.Open();  }
58
               
59
            _devam2 = true;
60
61
           (new Thread(new ThreadStart(this.Read2))).Start();
62
        
63-
         
63+
         }
64
65
66
        //
67
        public void Read1()
68
        {   
69
            while (_devam1)
70
            {
71
                try
72
                {
73
                    string message1 = serialPort1.ReadExisting();
74
                    if (_devam1) { this.richTextBox1.Text += message1; }
75
                }
76
                catch (TimeoutException) { }
77
            }
78
        }
79
80
81
        //
82
        public void Read2()
83
        {
84
            while (_devam2)
85
            {
86
                try
87
                {
88
                    string message2 = serialPort2.ReadExisting();
89
                    if (_devam2) { this.richTextBox2.Text += message2;}
90
               }
91
               catch (TimeoutException) { }
92
            }
93
        }
94
95
        private void button3_Click(object sender, EventArgs e)
96
        {   
97
              if(durum){
98
			  _devam1 = true;
99
			  _devam2 = true; 
100
				}     
101
			
102
				if(!durum){
103
				_devam1 = false;
104
				_devam2 = false;    
105
				}
106
107
            durum = !durum;
108
        }
109
        }
110
111
112
113
114
115-
    }
115+
    }