FrmLight.cs
3.9 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
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;
namespace CodeSplice
{
public partial class FrmLight : Asa.Theme.FlatForm
{
private string Command;
private System.IO.Ports.SerialPort port;
public FrmLight()
{
InitializeComponent();
}
private void WriteCmd()
{
if (!port.IsOpen) return;
Command = "S";
if (flatCheck1.Checked)
Command += string.Format("{0:000}T", flatTrack1.Value);
else
Command += "001F";
if (flatCheck2.Checked)
Command += string.Format("{0:000}T", flatTrack2.Value);
else
Command += "001F";
if (flatCheck3.Checked)
Command += string.Format("{0:000}T", flatTrack3.Value);
else
Command += "001F";
if (flatCheck4.Checked)
Command += string.Format("{0:000}T", flatTrack4.Value);
else
Command += "001F";
Command += "C#";
port.Write(Command);
}
private void FrmLight_Load(object sender, EventArgs e)
{
port = new System.IO.Ports.SerialPort
{
BaudRate = 19200,
DataBits = 8,
Parity = System.IO.Ports.Parity.None,
StopBits = System.IO.Ports.StopBits.One
};
Command = Common.Config.LightOpen;
flatTrack1.Value = Convert.ToInt32(Command.Substring(1, 3));
flatCheck1.Checked = Command.Substring(4, 1) == "T" ? true : false;
flatTrack2.Value = Convert.ToInt32(Command.Substring(5, 3));
flatCheck2.Checked = Command.Substring(8, 1) == "T" ? true : false;
flatTrack3.Value = Convert.ToInt32(Command.Substring(9, 3));
flatCheck3.Checked = Command.Substring(12, 1) == "T" ? true : false;
flatTrack4.Value = Convert.ToInt32(Command.Substring(13, 3));
flatCheck4.Checked = Command.Substring(16, 1) == "T" ? true : false;
flatLabel1.Text = flatTrack1.Value.ToString();
flatLabel2.Text = flatTrack2.Value.ToString();
flatLabel3.Text = flatTrack3.Value.ToString();
flatLabel4.Text = flatTrack4.Value.ToString();
CboPort.ItemAdd(System.IO.Ports.SerialPort.GetPortNames());
CboPort.Text = Common.Config.LightPort;
}
private void FrmLight_FormClosing(object sender, FormClosingEventArgs e)
{
if (port == null) return;
if (port.IsOpen) port.Close();
}
private void BtnOK_Click(object sender, EventArgs e)
{
Common.Config.LightPort = CboPort.Text;
Common.Config.LightOpen = Command;
Close();
}
private void BtnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void CboPort_SelectedIndexChanged(object sender)
{
if (CboPort.SelectedIndex == -1) return;
if (port == null) return;
try
{
if (port.IsOpen) port.Close();
port.PortName = CboPort.Text;
port.Open();
}
catch (Exception ex)
{
Common.Log.Out("Error: " + ex.Message);
MessageBox.Show(ex.Message);
}
}
private void FlatCheck_CheckedChanged(object sender)
{
WriteCmd();
}
private void FlatTrack_ValueChanged(object sender)
{
WriteCmd();
Asa.Theme.FlatTrack ft = sender as Asa.Theme.FlatTrack;
string s = ft.Name.Substring(9);
Controls["flatLabel" + s].Text = ft.Value.ToString();
}
}
}