在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → 钻机参数采集(winform串口数据实时绘图和静态绘图软件)

钻机参数采集(winform串口数据实时绘图和静态绘图软件)

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:7.43M
  • 下载次数:75
  • 浏览次数:515
  • 发布时间:2020-04-19
  • 实例类别:Windows系统编程
  • 发 布 人:robot666
  • 文件格式:.rar
  • 所需积分:2
 相关标签:

实例介绍

【实例简介】为实验室项目做的小软件,串口通信模式能够接收数据采集卡的数据进行动态显示,U盘数据处理模式能够读取文件进行静态图形显示。

【实例截图】

登录账号:123456 密码:123

from clipboard


from clipboard


from clipboard

【核心代码】

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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO.Ports;
 
namespace 酒店管理
{
    public partial class quankou : Form
    {
        private SerialPort ComDevice = new SerialPort();
        public quankou()
        {
            InitializeComponent();
            this.init();
        }
        string a1 ;
        string a2  ;
        string a3;
        double a4;
        double a5;
 
        string b1;
        string b2;
        string b3;
        double b4;
        double b5;
 
        string c1;
        string c2;
        string c3;
        double c4;
        double c5;
 
        string d1;
        string d2;
        string d3;
        double d4;
        double d5;
 
        string e1;
        string e2;
        string e3;
        double e4;
        double e5;
 
        string f1;
        string f2;
        string f3;
        double f4;
        double f5;
        
        public void init()
        {
            btnSend.Enabled = false;
            cbbComList.Items.AddRange(SerialPort.GetPortNames());
            if (cbbComList.Items.Count > 0)
            {
                cbbComList.SelectedIndex = 0;
            }
            cbbBaudRate.SelectedIndex = 5;
            cbbDataBits.SelectedIndex = 0;
            cbbParity.SelectedIndex = 0;
            cbbStopBits.SelectedIndex = 0;
            // pictureBox1.BackgroundImage = Properties.Resources.red;
            ComDevice.DataReceived  = new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件
        }
        private Timer timer2 = new Timer();
        private Timer timer3 = new Timer();
        private DataTable dt1 = new DataTable();
        private DateTime dtTime = new DateTime();
        private void btnOpen_Click(object sender, System.EventArgs e)
        {
            if (cbbComList.Items.Count <= 0)
            {
                MessageBox.Show("没有发现串口,请检查线路!");
                return;
            }
            if (ComDevice.IsOpen == false)
            {
                ComDevice.PortName = cbbComList.SelectedItem.ToString();
                ComDevice.BaudRate = Convert.ToInt32(cbbBaudRate.SelectedItem.ToString());
                ComDevice.Parity = (Parity)Convert.ToInt32(cbbParity.SelectedIndex.ToString());
                ComDevice.DataBits = Convert.ToInt32(cbbDataBits.SelectedItem.ToString());
                ComDevice.StopBits = (StopBits)Convert.ToInt32(cbbStopBits.SelectedItem.ToString());
                try
                {
                    ComDevice.Open();
                    btnSend.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                btnOpen.Text = "关闭串口";
                //pictureBox1.BackgroundImage = Properties.Resources.green;
            }
            else
            {
                try
                {
                    ComDevice.Close();
                    btnSend.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                btnOpen.Text = "打开串口";
                timer1.Enabled = false;
                //pictureBox1.BackgroundImage = Properties.Resources.red;
            }
            cbbComList.Enabled = !ComDevice.IsOpen;
            cbbBaudRate.Enabled = !ComDevice.IsOpen;
            cbbParity.Enabled = !ComDevice.IsOpen;
            cbbDataBits.Enabled = !ComDevice.IsOpen;
            cbbStopBits.Enabled = !ComDevice.IsOpen;
        }
        public void ClearSelf()
        {
            if (ComDevice.IsOpen)
            {
                ComDevice.Close();
            }
        }
        public bool SendData(byte[] data)
        {
            if (ComDevice.IsOpen)
            {
                try
                {
                    ComDevice.Write(data, 0, data.Length);//发送数据
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("串口未打开", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return false;
        }
        private void btnSend_Click(object sender, System.EventArgs e)
        
            if (cbTimeSend.Checked)
            {
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
            byte[] sendData = null;
 
            if (rbtnSendHex.Checked)
            {
                sendData = strToHexByte(txtSendData.Text.Trim());
            }
            else if (rbtnSendASCII.Checked)
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
           
           
            else
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
 
            if (this.SendData(sendData))//发送数据成功计数
            {
                lblSendCount.Invoke(new MethodInvoker(delegate
                {
                    lblSendCount.Text = (int.Parse(lblSendCount.Text)   txtSendData.Text.Length).ToString();
                }));
            }
            else
            {
            }
        }
        private byte[] strToHexByte(string hexString)
        {
            hexString = hexString.Replace(" ", "");
            if ((hexString.Length % 2) != 0) hexString  = " ";
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i  )
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2).Replace(" ", ""), 16);
            return returnBytes;
        }
        private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] ReDatas = new byte[ComDevice.BytesToRead];
            ComDevice.Read(ReDatas, 0, ReDatas.Length);//读取数据
            this.AddData(ReDatas);//输出数据
        }
        public void AddData(byte[] data)
        {
            if (rbtnHex.Checked)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < data.Length; i  )
                {
                    sb.AppendFormat("{0:x2}"   " ", data[i]);
                }
                AddContent(sb.ToString().ToUpper());
            }
            else if (rbtnASCII.Checked)
            {
                AddContent(new ASCIIEncoding().GetString(data));
            }
           
            
            else
            { }
 
            lblRevCount.Invoke(new MethodInvoker(delegate
            {
                lblRevCount.Text = (int.Parse(lblRevCount.Text)   data.Length).ToString();
            }));
        }
        private void AddContent(string content)
        {
            this.BeginInvoke(new MethodInvoker(delegate
            {
                if (chkAutoLine.Checked && txtShowData.Text.Length > 0)
                {
                    txtShowData.AppendText("\r\n");
                }
                txtShowData.AppendText(content);
            }));
        }
        private void btnClearRev_Click(object sender, System.EventArgs e)
        {
            txtShowData.Clear();
        }
        private void btnClearSend_Click(object sender, System.EventArgs e)
        {
            txtSendData.Clear();
        }
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
        }
        
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            string strSecond = txtSecond.Text;
            try
            {
                int isecond = int.Parse(strSecond) * 100;//Interval以微秒为单位 
                timer1.Interval = isecond;
                if (timer1.Enabled == true)
                {
                    btnSend.PerformClick(); //产生“发送”的click事件 
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("错误的定时输入!", "Error");
            
        }
        double index = 0;
        Int32 num = 0;
        private void timer2_tick(object sender, EventArgs e)
        {
            string str = txtShowData.Text.ToString();
            string[] strArr = str.Split(new char[] { ' ', '\n', '-' });
             a1 = strArr[3   21 * num];
             a2 = strArr[4   21 * num];
             a3 = a1   a2;
             a4 = Convert.ToInt32(a3, 16);
             a5 = a4;
 
             b1 = strArr[5   21 * num];
             b2 = strArr[6   21 * num];
             b3 = b1   b2;
             b4 = Convert.ToInt32(b3, 16);
             b5 = b4;
 
             c1 = strArr[7   21 * num];
             c2 = strArr[8   21 * num];
             c3 = c1   c2;
             c4 = Convert.ToInt32(c3, 16);
             c5 = c4 ;
 
             d1 = strArr[9   21 * num];
             d2 = strArr[10   21 * num];
             d3 = d1   d2;
             d4 = Convert.ToInt32(d3, 16);
             d5 = d4 ;
 
             e1 = strArr[11   21 * num];
             e2 = strArr[12   21 * num];
             e3 = e1   e2;
             e4 = Convert.ToInt32(e3, 16);
             e5 = e4 ;
 
             f1 = strArr[13   21 * num];
             f2 = strArr[14   21 * num];
             f3 = f1   f2;
             f4 = Convert.ToInt32(f3, 16);
             f5 = f4;
 
            double dy = a5;
            double dy1 = b5;
            double dy2 = c5;
            double dy3 = d5;
            double dy4 = e5;
            double dy5 = f5;
            dy = dy * 0.03 * 0.2;
            dy1 = dy1 * 0.03 * 0.2;
            dy2 = dy2 * 0.03 * 0.2;
            dy3 = dy3 * 0.03 * 0.2;
            dy4 = dy4 * 0.02;
            dy5 = dy5 * 0.4;
            this.chart1.Series[0].Points.RemoveAt(0);
            this.chart1.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy.ToString("0.00"));
            this.chart2.Series[0].Points.RemoveAt(0);
            this.chart2.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy1.ToString("0.00"));
            this.chart3.Series[0].Points.RemoveAt(0);
            this.chart3.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy2.ToString("0.00"));
            this.chart4.Series[0].Points.RemoveAt(0);
            this.chart4.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy3.ToString("0.00"));
            this.chart5.Series[0].Points.RemoveAt(0);
            this.chart5.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy4.ToString("0.00"));
            this.chart6.Series[0].Points.RemoveAt(0);
            this.chart6.Series[0].Points.AddXY(dtTime.AddSeconds(index).ToString("HH:mm:ss"), dy5.ToString("0.00"));
            index = index 0.1;
            num  ;
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
 
            chart1.Series[0].Points.Clear();
            chart2.Series[0].Points.Clear();
            chart3.Series[0].Points.Clear();
            chart4.Series[0].Points.Clear();
            chart5.Series[0].Points.Clear();
            chart6.Series[0].Points.Clear();
 
            txtSendData.Text = "64 04 03 E7 00 08 48 4A";
            cbTimeSend.Checked = true;
            txtSecond.Text = "1";
 
            if (cbTimeSend.Checked)
            {
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
            byte[] sendData = null;
 
            if (rbtnSendHex.Checked)
            {
                sendData = strToHexByte(txtSendData.Text.Trim());
            }
            else if (rbtnSendASCII.Checked)
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
 
 
            else
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
 
            if (this.SendData(sendData))//发送数据成功计数
            {
                lblSendCount.Invoke(new MethodInvoker(delegate
                {
                    lblSendCount.Text = (int.Parse(lblSendCount.Text)   txtSendData.Text.Length).ToString();
                }));
            }
            else
            {
            }
 
          
 
                this.chart1.Titles.Add("液压缸进口压力");
                this.chart1.ChartAreas[0].AxisX.Title = "时间";
                this.chart1.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart1.ChartAreas[0].AxisX.Interval = 10;
                this.chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart1.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart1.ChartAreas[0].AxisY.Interval = 5;
                this.chart1.ChartAreas[0].AxisY.Maximum = 30;
                //this.chart1.Series.Add("series1");
 
                this.chart2.Titles.Add("液压缸出口压力");
                this.chart2.ChartAreas[0].AxisX.Title = "时间";
                this.chart2.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart2.ChartAreas[0].AxisX.Interval = 10;
                this.chart2.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart2.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart2.ChartAreas[0].AxisY.Interval = 5;
                this.chart2.ChartAreas[0].AxisY.Maximum = 30;
                //this.chart2.Series.Add("series1");
 
                this.chart3.Titles.Add("液压马达进口压力");
                this.chart3.ChartAreas[0].AxisX.Title = "时间";
                this.chart3.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart3.ChartAreas[0].AxisX.Interval = 10;
                this.chart3.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart3.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart3.ChartAreas[0].AxisY.Interval = 5;
                this.chart3.ChartAreas[0].AxisY.Maximum =30;
                //this.chart3.Series.Add("series1");
 
                this.chart4.Titles.Add("液压马达出口压力");
                this.chart4.ChartAreas[0].AxisX.Title = "时间";
                this.chart4.ChartAreas[0].AxisY.Title = "压力(MPa)";
                this.chart4.ChartAreas[0].AxisX.Interval = 10;
                this.chart4.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart4.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart4.ChartAreas[0].AxisY.Interval = 5;
                this.chart4.ChartAreas[0].AxisY.Maximum = 30;
                //this.chart4.Series.Add("series1");
 
                this.chart5.Titles.Add("液压马达流量");
                this.chart5.ChartAreas[0].AxisX.Title = "时间";
                this.chart5.ChartAreas[0].AxisY.Title = "流量(L/min)";
                this.chart5.ChartAreas[0].AxisX.Interval = 10;
                this.chart5.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart5.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart5.ChartAreas[0].AxisY.Interval = 10;
                this.chart5.ChartAreas[0].AxisY.Maximum = 100;
               // this.chart5.Series.Add("series1");
 
                this.chart6.Titles.Add("主轴转速");
                this.chart6.ChartAreas[0].AxisX.Title = "时间";
                this.chart6.ChartAreas[0].AxisY.Title = "转速(n/min)";
                this.chart6.ChartAreas[0].AxisX.Interval = 10;
                this.chart6.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
                this.chart6.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
                this.chart6.ChartAreas[0].AxisY.Interval = 200;
                this.chart6.ChartAreas[0].AxisY.Maximum = 2000;
                //this.chart6.Series.Add("series1");
                //使图标刚开始的时候是空的,随着时间的推移才逐渐画满,可以在初始化的时候填几个Y坐标为0的点:
                for (int i = 0; i < 60; i  )
                {
                    System.Windows.Forms.DataVisualization.Charting.DataPoint dp = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                    dp.SetValueXY(DateTime.Now.AddSeconds(-60   i).ToString("HH:mm:ss"), 0);
                    this.chart1.Series[0].Points.Add(dp);
                    this.chart2.Series[0].Points.Add(dp);
                    this.chart3.Series[0].Points.Add(dp);
                    this.chart4.Series[0].Points.Add(dp);
                    this.chart5.Series[0].Points.Add(dp);
                    this.chart6.Series[0].Points.Add(dp);
                }
 
                chart1.Series[0].IsValueShownAsLabel = false ;
                this.chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line ;
                this.chart1.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart1.Series[0].BorderWidth = 3;
                chart2.Series[0].IsValueShownAsLabel = false;
                this.chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart2.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart2.Series[0].BorderWidth = 3;
                chart3.Series[0].IsValueShownAsLabel = false;
                this.chart3.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart3.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart3.Series[0].BorderWidth = 3;
                chart4.Series[0].IsValueShownAsLabel = false;
                this.chart4.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart4.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart4.Series[0].BorderWidth = 3;
                chart5.Series[0].IsValueShownAsLabel = false;
                this.chart5.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart5.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart5.Series[0].BorderWidth = 3;
                chart6.Series[0].IsValueShownAsLabel = false;
                this.chart6.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                this.chart6.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
                this.chart6.Series[0].BorderWidth = 3;
                 
        
                timer2.Interval = 100 * 1;
                timer2.Tick  = new EventHandler(timer2_tick);
                timer2.Start();
                dtTime = DateTime.Now;
           // }
 
        }
 
        private void btnstart_Click(object sender, EventArgs e)
        {
            txtSendData.Text = "64 04 03 E7 00 08 48 4A";
            cbTimeSend.Checked=true ;
            txtSecond.Text  = "1";
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Stop();
           cbTimeSend.Checked = false ;
        }
 
        private void continu_show_Click(object sender, EventArgs e)
        {
            chart1.Series[0].Points.Clear();
            chart2.Series[0].Points.Clear();
            chart3.Series[0].Points.Clear();
            chart4.Series[0].Points.Clear();
            chart5.Series[0].Points.Clear();
            chart6.Series[0].Points.Clear();
 
            txtSendData.Text = "64 04 03 E7 00 08 48 4A";
            cbTimeSend.Checked = true;
            txtSecond.Text = "1";
 
            if (cbTimeSend.Checked)
            {
                timer1.Enabled = true;
            }
            else
            {
                timer1.Enabled = false;
            }
            byte[] sendData = null;
 
            if (rbtnSendHex.Checked)
            {
                sendData = strToHexByte(txtSendData.Text.Trim());
            }
            else if (rbtnSendASCII.Checked)
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
 
 
            else
            {
                sendData = Encoding.ASCII.GetBytes(txtSendData.Text.Trim());
            }
 
            if (this.SendData(sendData))//发送数据成功计数
            {
                lblSendCount.Invoke(new MethodInvoker(delegate
                {
                    lblSendCount.Text = (int.Parse(lblSendCount.Text)   txtSendData.Text.Length).ToString();
                }));
            }
            else
            {
            }
 
 
            this.chart1.Titles.Clear();
            this.chart1.Titles.Add("液压缸进口压力");
            this.chart1.ChartAreas[0].AxisX.Title = "时间";
            this.chart1.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart1.ChartAreas[0].AxisX.Interval = 10;
            this.chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart1.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart1.ChartAreas[0].AxisY.Interval = 5;
            this.chart1.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart1.Series.Add("series1");
            this.chart2.Titles.Clear();
            this.chart2.Titles.Add("液压缸出口压力");
            this.chart2.ChartAreas[0].AxisX.Title = "时间";
            this.chart2.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart2.ChartAreas[0].AxisX.Interval = 10;
            this.chart2.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart2.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart2.ChartAreas[0].AxisY.Interval = 5;
            this.chart2.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart2.Series.Add("series1");
            this.chart3.Titles.Clear();
            this.chart3.Titles.Add("液压马达进口压力");
            this.chart3.ChartAreas[0].AxisX.Title = "时间";
            this.chart3.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart3.ChartAreas[0].AxisX.Interval = 10;
            this.chart3.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart3.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart3.ChartAreas[0].AxisY.Interval = 5;
            this.chart3.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart3.Series.Add("series1");
            this.chart4.Titles.Clear();
            this.chart4.Titles.Add("液压马达出口压力");
            this.chart4.ChartAreas[0].AxisX.Title = "时间";
            this.chart4.ChartAreas[0].AxisY.Title = "压力(MPa)";
            this.chart4.ChartAreas[0].AxisX.Interval = 10;
            this.chart4.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart4.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart4.ChartAreas[0].AxisY.Interval = 5;
            this.chart4.ChartAreas[0].AxisY.Maximum = 30;
            //this.chart4.Series.Add("series1");
            this.chart5.Titles.Clear();
            this.chart5.Titles.Add("液压马达流量");
            this.chart5.ChartAreas[0].AxisX.Title = "时间";
            this.chart5.ChartAreas[0].AxisY.Title = "流量(L/min)";
            this.chart5.ChartAreas[0].AxisX.Interval = 10;
            this.chart5.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart5.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart5.ChartAreas[0].AxisY.Interval = 10;
            this.chart5.ChartAreas[0].AxisY.Maximum = 100;
            // this.chart5.Series.Add("series1");
            this.chart6.Titles.Clear();
            this.chart6.Titles.Add("主轴转速");
            this.chart6.ChartAreas[0].AxisX.Title = "时间";
            this.chart6.ChartAreas[0].AxisY.Title = "转速(n/min)";
            this.chart6.ChartAreas[0].AxisX.Interval = 10;
            this.chart6.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.NotSet;
            this.chart6.ChartAreas[0].AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            this.chart6.ChartAreas[0].AxisY.Interval = 200;
            this.chart6.ChartAreas[0].AxisY.Maximum = 2000;
            //this.chart6.Series.Add("series1");
            //使图标刚开始的时候是空的,随着时间的推移才逐渐画满,可以在初始化的时候填几个Y坐标为0的点:
            for (int i = 0; i < 60; i  )
            {
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                dp.SetValueXY(DateTime.Now.AddSeconds(-60   i).ToString("HH:mm:ss"), 0);
                this.chart1.Series[0].Points.Add(dp);
                this.chart2.Series[0].Points.Add(dp);
                this.chart3.Series[0].Points.Add(dp);
                this.chart4.Series[0].Points.Add(dp);
                this.chart5.Series[0].Points.Add(dp);
                this.chart6.Series[0].Points.Add(dp);
            }
 
            chart1.Series[0].IsValueShownAsLabel = false;
            this.chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart1.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart1.Series[0].BorderWidth = 3;
            chart2.Series[0].IsValueShownAsLabel = false;
            this.chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart2.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart2.Series[0].BorderWidth = 3;
            chart3.Series[0].IsValueShownAsLabel = false;
            this.chart3.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart3.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart3.Series[0].BorderWidth = 3;
            chart4.Series[0].IsValueShownAsLabel = false;
            this.chart4.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart4.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart4.Series[0].BorderWidth = 3;
            chart5.Series[0].IsValueShownAsLabel = false;
            this.chart5.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart5.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart5.Series[0].BorderWidth = 3;
            chart6.Series[0].IsValueShownAsLabel = false;
            this.chart6.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            this.chart6.Series[0].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            this.chart6.Series[0].BorderWidth = 3;
            timer2.Interval = 100 * 1;
            //timer2.Tick  = new EventHandler(timer2_tick);
            timer2.Start();
            dtTime = DateTime.Now;
        }
        
    }
}

标签:

实例下载地址

钻机参数采集(winform串口数据实时绘图和静态绘图软件)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警