-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineTrackerSerial.linq
77 lines (66 loc) · 2.14 KB
/
LineTrackerSerial.linq
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
<Query Kind="Program">
<Reference><RuntimeDirectory>\System.Windows.Forms.DataVisualization.dll</Reference>
<Reference><RuntimeDirectory>\System.Windows.Forms.dll</Reference>
<NuGetReference>EntityFramework</NuGetReference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Bson</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System.IO.Ports</Namespace>
<Namespace>System.Windows.Forms</Namespace>
<Namespace>System.Windows.Forms.DataVisualization.Charting</Namespace>
<Namespace>System.Drawing</Namespace>
</Query>
void Main()
{
var portName="COM7";
var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), string.Format("arunio{0}.txt", Environment.TickCount));
var frm = new Form() { StartPosition = FormStartPosition.Manual, Left = 0, Top = 0, Size = new Size(800, 800) };
var series1 = new System.Windows.Forms.DataVisualization.Charting.Series
{
Name = "Series1" + Environment.TickCount,
Color = System.Drawing.Color.Green,
IsVisibleInLegend = false,
IsXValueIndexed = true,
ChartType = SeriesChartType.Line,
};
{
var chart1 = new Chart() { Dock = DockStyle.Fill };
frm.Controls.Add(chart1);
chart1.ChartAreas.Add(new ChartArea("Test1") { });
chart1.ChartAreas[0].AxisY.Maximum = 1000;
chart1.ChartAreas[0].AxisY.Minimum = -1000;
chart1.Series.Clear();
chart1.Series.Add(series1);
}
var btn = new Button() { Dock = DockStyle.Left };
btn.Size = new Size(100, 100);
frm.Controls.Add(btn);
btn.Click += (o2, e2) =>
{
var r=new Random();
for (int i = 0; i < 100; i++)
{
series1.Points.AddXY(r.Next(0,1000), r.Next(0,1000));
}
};
var port = new SerialPort(portName);
port.DataReceived += (o, e) =>
{
var res = port.ReadExisting().Dump();
File.AppendAllText(filePath, res);
};
try
{
port.Open();
}
catch (Exception ex)
{
ex.Dump();
}
Application.Run(frm);
}
// Define other methods and classes here