-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
120 lines (108 loc) · 4.2 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UB482
{
public partial class Form1 : Form
{
#region .. Double Buffered function ..
public static void SetDoubleBuffered(System.Windows.Forms.Control c)
{
if (System.Windows.Forms.SystemInformation.TerminalServerSession)
return;
System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
aProp.SetValue(c, true, null);
}
#endregion
//object defining
SerialPortManager serialPortManager;
Data data;
public TextBox[] textBoxes;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
//object instantiating
serialPortManager = new SerialPortManager(serialPort1);
data = new Data();
textBoxes = new TextBox[]
{
//no header first byte
gnssTextBox, msgLenTextBox, yearTextBox, monthTextBox,
dayTextBox, hourTextBox, minTextBox, secTextBox, rtkStatTextBox,
headingStatTextBox, gpsStatTextBox, gloStatTextBox,
bdsStatTextBox, baselineNTextBox, baselineETextBox,
baselineUTextBox, baselineNStdTextBox, baselineEStdTextBox,
baselineUStdTextBox, headingTextBox, gpsPitchTextBox, gpsRollTextBox,
gpsSpeedTextBox, velNTextBox, velETextBox, velUpTextBox,
xigVxTextBox, xigVyTextBox, xigVzTextBox, latTextBox, lonTextBox,
roverHeiTextBox, ecefXTextBox, ecefYTextBox, ecefZTextBox, xigLatTextBox,
xigLonTextBox, xigAltTextBox, xigEcefXTextBox, xigEcefYTextBox,
xigEcefZTextBox, /*baseline konumu yok*/secLatTextBox, secLonTextBox,
secAltTextBox, gpsWeekSecTextBox, diffageTextBox, speedHeadingTextBox,
undulationTextBox, /*remain float yok*/galStatTextBox
};
serialPortManager.textBoxes = textBoxes;
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.AddRange(serialPortManager.CheckSerialPort());
try
{
comboBox1.SelectedIndex = 0;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
foreach (var textBox in textBoxes)
{
SetDoubleBuffered(textBox);
}
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
if (serialPort1.IsOpen)
{
serialPortManager.readBuffer = serialPort1.ReadLine();
rawByteMonitor.Text += serialPortManager.readBuffer + "\n";
serialPortManager.SplitBuffer(data);
serialPortManager.ViewDataAsync(data);
serialPortManager.receivedPacket++;
//serialPortManager.LogDataAsync(data);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (!serialPortManager.isEnabled)
{
serialPortManager.comboBox = comboBox1;
serialPortManager.OpenConnection();
timer1.Start();
}
else
{
serialPortManager.CloseConnection();
comboBox1.Items.AddRange(serialPortManager.CheckSerialPort());
timer1.Stop();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
timeIntervalTextBox.Text = serialPortManager.receivedPacket.ToString();
serialPortManager.receivedPacket = 0;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
data.CloseFile();
}
}
}