-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmTAC.cs
190 lines (169 loc) · 5.34 KB
/
frmTAC.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
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
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.IO.Ports;
using PCAN;
using Peak.Can.Basic;
using TAC.Driver;
namespace TACControler
{
public partial class frmTAC : Form
{
#region MEMBER
private const int TARGET_WAITING_10SECONDS = 30;
private int nbOfSecond = 0;
#endregion
#region INITIALIZATION
public frmTAC()
{
InitializeComponent();
PCANCom.Instance.OnMessageReceived += CANMessageReceived;
}
private void frmGripper_FormClosing(object sender, FormClosingEventArgs e)
{
PCANCom.Instance.disconnect();
}
#endregion
#region CAN MESSAGE RECEIVED
private void CANMessageReceived(object sender, PCANComEventArgs e)
{
if (e.CanMsg.DATA[2] == CANDeviceConstant.HARDWARE_FILTER_TAC)
{
packetDecoder(e.CanMsg.DATA);
}
}
#endregion
#region CAN MESSAGE TREATMENT
private void packetDecoder(byte[] packet)
{
if (this.InvokeRequired)
{
this.Invoke(new Action<byte[]>(packetDecoder), packet);
}
else
{
if(packet[3] == 1)
{
switch (packet[0])
{
case TACConstant.INST_GET_AGITATOR_STATE:
btnAgitatorEnable.Text = "Agitator Disable";
break;
case TACConstant.INST_GET_PELTIER_STATE:
btnPeltierEnable.Text = "Peltier Disable";
break;
case TACConstant.INST_GET_FAN_STATE:
btnFanEnable.Text = "Fan Disable";
break;
}
}
else if (packet[3] == 0)
{
switch (packet[0])
{
case TACConstant.INST_GET_AGITATOR_STATE:
btnAgitatorEnable.Text = "Agitator Enable";
break;
case TACConstant.INST_GET_PELTIER_STATE:
btnPeltierEnable.Text = "Peltier Enable";
break;
case TACConstant.INST_GET_FAN_STATE:
btnFanEnable.Text = "Fan Enable";
break;
}
}
}
}
#endregion
#region HANDLING EVENTS
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
{
if(tabControl.SelectedIndex == 1)
ctrProperties1.getAllProperties();
}
private void tmr10sec_Tick(object sender, EventArgs e)
{
ushort temperature;
if (nbOfSecond == 0)
{
if (ctrChart1.Target == 37)
temperature = 22;
else
temperature = 37;
TAC2CAN.setTemperatureTarget((ushort)(temperature * 10));
ctrChart1.Target = temperature;
}
nbOfSecond = (nbOfSecond + 1) % TARGET_WAITING_10SECONDS;
}
private void btnStartTest_Click(object sender, EventArgs e)
{
if (btnStartTest.Text == "Start Test")
{
btnStartTest.Text = "Stop Test";
nbOfSecond = 0;
tmr10sec_Tick(null, null);
tmr10sec.Enabled = true;
}
else
{
btnStartTest.Text = "Start Test";
tmr10sec.Enabled = false;
}
}
private void btnRefreshProperties_Click(object sender, EventArgs e)
{
ctrProperties1.getAllProperties();
}
private void btnSaveGraph_Click(object sender, EventArgs e)
{
ctrChart1.saveChart();
}
private void btnClear_Click(object sender, EventArgs e)
{
ctrChart1.clearChart();
}
private void btnPeltierEnable_Click(object sender, EventArgs e)
{
if(btnPeltierEnable.Text.Equals("Peltier Enable"))
{
TAC2CAN.setPeltierEnable(0);
}
else
{
TAC2CAN.setPeltierEnable(1);
}
TAC2CAN.getPeltierState();
}
private void btnFanEnable_Click(object sender, EventArgs e)
{
if (btnFanEnable.Text.Equals("Fan Enable"))
{
TAC2CAN.setFanEnable(0);
}
else
{
TAC2CAN.setFanEnable(1);
}
TAC2CAN.getFanState();
}
private void btnAgitatorEnable_Click(object sender, EventArgs e)
{
if (btnAgitatorEnable.Text.Equals("Agitator Enable"))
{
TAC2CAN.setAgitatorEnable(0);
}
else
{
TAC2CAN.setAgitatorEnable(1);
}
TAC2CAN.getAgitatorState();
}
#endregion
}
}