-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForm1.cs
More file actions
253 lines (225 loc) · 7.64 KB
/
Form1.cs
File metadata and controls
253 lines (225 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Diagnostics;
using ZedGraph;
namespace Seri_Port_Terminal
{
public partial class Form1 : Form
{
string Gelen = string.Empty;
string[] ports = SerialPort.GetPortNames();
// 1
GraphPane myPane = new GraphPane();
RollingPointPairList listPointsOne = new RollingPointPairList(40);
LineItem myCurveOne;
RollingPointPairList listPointsTwo = new RollingPointPairList(40);
LineItem myCurveTwo;
RollingPointPairList listPointsThree = new RollingPointPairList(40);
LineItem myCurveThree;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//1
myPane = zedGraphControl1.GraphPane;
myPane.XAxis.Title.Text = "Time";
myPane.YAxis.Title.Text = "Data";
zedGraphControl1.Invalidate();
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
/* Adding connected ports */
foreach (string port in ports)
{
cbComPort.Items.Add(port);
}
/* Baudrates are added */
cbBaud.Items.Add("2400");
cbBaud.Items.Add("4800");
cbBaud.Items.Add("9600");
cbBaud.Items.Add("19200");
cbBaud.Items.Add("38400");
cbBaud.Items.Add("57600");
cbBaud.Items.Add("115200");
cbBaud.SelectedIndex = 3;
}
private void btnBaglan_Click(object sender, EventArgs e)
{
if (SeriPort.IsOpen == false)
{
if (cbComPort.Text == "")
return;
SeriPort.PortName = cbComPort.Text;
SeriPort.BaudRate = Convert.ToInt32(cbBaud.Text);
try
{
SeriPort.Open();
}
catch (Exception er)
{
MessageBox.Show("Error:" + er.Message);
}
}
else
{
rtbEkran.Text = "seriport already open";
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (SeriPort.IsOpen == true)
{
SeriPort.Close();
}
}
private void btnKes_Click(object sender, EventArgs e)
{
if (SeriPort.IsOpen == true)
{
SeriPort.Close();
}
}
private void SeriPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
Gelen = SeriPort.ReadLine();
this.Invoke(new EventHandler(DisplayText));
}
catch (Exception er)
{
MessageBox.Show("Error:" + er.Message);
}
}
private void DisplayText(object s, EventArgs e)
{
label31.Text = Gelen;
if (timer1.Enabled == true)
{
string ctrl = Gelen.Substring(0, 1);
if (ctrl=="$")
{
string[] parsed = Gelen.Split(',');
string ArananC = ",";
int bulunanC = (Gelen.Length - Gelen.Replace(ArananC, "").Length) / ArananC.Length;
if (bulunanC == 4)
{
label17.Text = parsed[1];
label25.Text = parsed[2];
label24.Text = parsed[3];
}
}
}
rtbEkran.Text += Gelen;
rtbEkran.SelectionStart = rtbEkran.Text.Length;
rtbEkran.ScrollToCaret();
Gelen = String.Empty;
}
private void btnEkraniTemizle_Click(object sender, EventArgs e)
{
rtbEkran.Clear();
}
private void btnGonder_Click(object sender, EventArgs e)
{
if (SeriPort.IsOpen == true)
{
if (chbCR.Checked == true && chbLF.Checked == false)
{
SeriPort.Write(rtbGonder.Text + "\r");
}
else if (chbCR.Checked == false && chbLF.Checked == true)
{
SeriPort.Write(rtbGonder.Text + "\n");
}
else if (chbCR.Checked == true && chbLF.Checked == true)
{
SeriPort.Write(rtbGonder.Text + "\r\n");
}
else
{
SeriPort.Write(rtbGonder.Text);
}
}
else
{
MessageBox.Show("No Connection");
}
}
private void btnKaydet_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Please select place to save file";
saveFileDialog1.Filter = "(*.doc)|*.doc|(*.txt)|*.txt|Tüm dosyalar(*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.InitialDirectory = "C:\\";
saveFileDialog1.ShowDialog();
StreamWriter Kaydet = new StreamWriter(saveFileDialog1.FileName);
Kaydet.Write(rtbEkran.Text);
Kaydet.Close();
}
private void btnAc_Click(object sender, EventArgs e)
{
//Open button
if (openFileDialog1.ShowDialog() == DialogResult.OK)
try //
{
rtbGonder.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
}
catch
{
MessageBox.Show(openFileDialog1.FileName + " Can not open this file");
}
}
private void btnSil_Click(object sender, EventArgs e)
{
rtbGonder.Clear();
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void zedGraphControl1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
int sayi = Convert.ToInt32(label10.Text);
sayi++;
label10.Text = sayi.ToString();
//
myPane = zedGraphControl1.GraphPane;
//1
double x = Convert.ToDouble(label10.Text);
double y1 = double.Parse(label17.Text, System.Globalization.CultureInfo.InvariantCulture);
listPointsOne.Add(x, y1);
myCurveOne = myPane.AddCurve(null, listPointsOne, Color.Blue, SymbolType.Circle);
//2
double y2 = double.Parse(label25.Text, System.Globalization.CultureInfo.InvariantCulture);
listPointsOne.Add(x, y2);
myCurveTwo = myPane.AddCurve(null, listPointsTwo, Color.Red, SymbolType.Circle);
//3
double y3 = double.Parse(label24.Text, System.Globalization.CultureInfo.InvariantCulture);
listPointsOne.Add(x, y3);
myCurveThree = myPane.AddCurve(null, listPointsThree, Color.Green, SymbolType.Circle);
//Grafiği yenileme
zedGraphControl1.Invalidate();
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
}
}
}