Skip to content

Commit e4833fa

Browse files
committed
Implemented saving, reading and click actions
1 parent 03cdf37 commit e4833fa

5 files changed

Lines changed: 286 additions & 20 deletions

File tree

QS_DS_Program/QS_DS_Program.Designer.cs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

QS_DS_Program/QS_DS_Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public QS_DS_Program()
1717
InitializeComponent();
1818
AssignItems();
1919
DisableFunctionAll();
20+
MainSerialPort.DataReceived += SerialDataReceived;
21+
FillComboBox();
2022
}
2123

2224

2325
private void QS_DS_Program_Load(object sender, EventArgs e)
2426
{
2527
}
2628

29+
2730
}
2831
}

QS_DS_Program/QS_DS_Program_Data_Handling.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,14 @@ private void ReceivedDataHandle(object sender, EventArgs e)
2525
FunctionsShowTable();
2626
}
2727
}
28+
private string GenerateDataToSend()
29+
{
30+
string MSG = "S,";
31+
MSG += GenerateCheckBoxData();
32+
MSG += GenerateNumericData();
33+
MSG.Remove(MSG.Length - 1);
34+
return MSG;
35+
}
36+
2837
}
2938
}

QS_DS_Program/QS_DS_Program_Interface_Control.cs

Lines changed: 164 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ private void AssignItems()
124124

125125

126126
CheckBoxData.Add(QSEnable_Check);
127-
CheckBoxData.Add(Push_Check_QS);
128127
CheckBoxData.Add(DSEnable_Check);
128+
CheckBoxData.Add(Push_Check_QS);
129+
129130

130131
NumericData.Add(Pulses);
131132
NumericData.Add(PreDelayQS);
@@ -212,10 +213,49 @@ private void DisableFunctionAll()
212213

213214
}
214215

216+
private string GenerateCheckBoxData()
217+
{
218+
string message = "";
219+
for (int i = 0; i < CheckBoxData.Count; i++)
220+
{
221+
message += CheckBoxData[i].Checked ? "1," : "0,";
222+
}
223+
return message;
224+
}
225+
226+
private string GenerateNumericData()
227+
{
228+
string message = "";
229+
if (NumericData[0].Value <= decimal.Parse("0,5"))
230+
{
231+
message += "0.5,";
232+
}
233+
else if (NumericData[0].Value == decimal.Parse("1,0"))
234+
{
235+
message += "1.0,";
236+
}
237+
else if (NumericData[0].Value == decimal.Parse("2,0"))
238+
{
239+
message += "2.0,";
240+
}
241+
else if (NumericData[0].Value == decimal.Parse("3,0"))
242+
{
243+
message += "3.0,";
244+
}
245+
else if (NumericData[0].Value == decimal.Parse("4,0"))
246+
{
247+
message += "4.0,";
248+
}
249+
for (int i = 1; i < NumericData.Count; i++)
250+
{
251+
message += NumericData[i] + ",";
252+
}
253+
return message;
254+
}
215255
private void SetRPMSensor(string RPM, string sensor)
216256
{
217257
RPMRead.Text = RPM;
218-
LabelSensorReading.Text = String.Empty + (Int32.Parse(sensor) - 2000);
258+
LabelSensorReading.Text = "" + (Int32.Parse(sensor) - 2000);
219259
ProgressBarSensor.Value = Int32.Parse(sensor);
220260
}
221261
private void FunctionsEnableConnection()
@@ -225,6 +265,7 @@ private void FunctionsEnableConnection()
225265
TopButtons[i].Visible = true;
226266
}
227267
Connect_BTN.Text = "Disconnect";
268+
comboBox1.Enabled = false;
228269
}
229270

230271
private void FunctionsEnableGeneral()
@@ -249,38 +290,34 @@ private void FunctionsShowTable()
249290
Tabs_All.Visible = true;
250291
}
251292

293+
private void FunctionsBase()
294+
{
295+
Connect_BTN.Text = "Connect";
296+
DisableFunctionAll();
297+
comboBox1.Enabled = true;
298+
}
252299
private void FunctionsAssignValues(string[] splitData)
253300
{
254-
255301

256-
if (splitData[3] == "1")
302+
FunctionsEnableGeneral();
303+
if (splitData[3].Equals("1"))
257304
{
258305
FunctionsEnableQS1();
259306
}
260-
else if (splitData[3] == "2")
307+
else if (splitData[3].Equals("2"))
261308
{
262309
FunctionsEnableQS2();
263310
}
264-
if (splitData[4] == "1")
311+
if (splitData[4].Equals("1"))
265312
{
266313
FunctionsEnableDS1();
267314
}
268-
if (splitData[5] == "0")
269-
{
270-
QSEnable_Check.Checked = false;
271-
}
272-
else if (splitData[5] == "1")
273-
{
274-
QSEnable_Check.Checked = true;
275-
}
276-
if (splitData[6] == "0")
277-
{
278-
DSEnable_Check.Checked = false;
279-
}
280-
else if (splitData[6] == "1")
315+
316+
for (int i = 0; i < CheckBoxData.Count - 1; i++)
281317
{
282-
DSEnable_Check.Checked = true;
318+
CheckBoxData[i].Checked = splitData[5 + i].Equals("1") ? true : false;
283319
}
320+
284321
if (splitData[7] == "0")
285322
{
286323
Pull_Check_QS.Checked = true;
@@ -295,7 +332,9 @@ private void FunctionsAssignValues(string[] splitData)
295332
Push_Check_DS.Checked = false;
296333
Pull_Check_DS.Checked = true;
297334
}
335+
298336
Pulses.Value = Decimal.Parse(splitData[8], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
337+
299338
for (int i = 1; i < NumericData.Count; i++)
300339
{
301340
NumericData[i].Value = Int32.Parse(splitData[i + 9]);
@@ -364,5 +403,110 @@ private void FunctionsEnableDS1()
364403
DS1Numerics[i].Visible = true;
365404
}
366405
}
406+
407+
private void FillComboBox()
408+
{
409+
comboBox1.Items.Clear();
410+
foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
411+
{
412+
comboBox1.Items.Add(s);
413+
}
414+
}
415+
416+
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
417+
{
418+
}
419+
420+
private void MinRPMDS_ValueChanged(object sender, EventArgs e)
421+
{
422+
if (MinRPMDS.Value > (MaxRPMDS.Value - Int32.Parse("500")))
423+
{
424+
MinRPMDS.Value = (MaxRPMDS.Value - Int32.Parse("500"));
425+
}
426+
}
427+
428+
private void MaxRPMDS_ValueChanged(object sender, EventArgs e)
429+
{
430+
if (MaxRPMDS.Value < (MinRPMDS.Value + Int32.Parse("500")))
431+
{
432+
MaxRPMDS.Value = (MinRPMDS.Value + Int32.Parse("500"));
433+
}
434+
}
435+
436+
private void Pulses_ValueChanged(object sender, EventArgs e)
437+
{
438+
if (Pulses.Value == 0)
439+
{
440+
Pulses.Value = decimal.Parse("0,5");
441+
}
442+
else if (Pulses.Value == decimal.Parse("1,5"))
443+
{
444+
Pulses.Value = 1;
445+
}
446+
}
447+
448+
private void Pull_Check_QS_CheckedChanged(object sender, EventArgs e)
449+
{
450+
if (Pull_Check_QS.Checked)
451+
{
452+
Push_Check_QS.Checked = false;
453+
Pull_Check_DS.Checked = false;
454+
Push_Check_DS.Checked = true;
455+
}
456+
else if (!Pull_Check_QS.Checked)
457+
{
458+
Push_Check_QS.Checked = true;
459+
Pull_Check_DS.Checked = true;
460+
Push_Check_DS.Checked = false;
461+
}
462+
}
463+
464+
private void Push_Check_QS_CheckedChanged(object sender, EventArgs e)
465+
{
466+
if (Push_Check_QS.Checked)
467+
{
468+
Pull_Check_QS.Checked = false;
469+
Pull_Check_DS.Checked = true;
470+
Push_Check_DS.Checked = false;
471+
}
472+
else if (!Push_Check_QS.Checked)
473+
{
474+
Pull_Check_QS.Checked = true;
475+
Pull_Check_DS.Checked = false;
476+
Push_Check_DS.Checked = true;
477+
}
478+
}
479+
480+
private void Pull_Check_DS_CheckedChanged(object sender, EventArgs e)
481+
{
482+
if (Pull_Check_DS.Checked)
483+
{
484+
Push_Check_DS.Checked = false;
485+
Pull_Check_QS.Checked = false;
486+
Push_Check_QS.Checked = true;
487+
}
488+
else if (!Pull_Check_DS.Checked)
489+
{
490+
Push_Check_DS.Checked = true;
491+
Pull_Check_QS.Checked = true;
492+
Push_Check_QS.Checked = false;
493+
}
494+
}
495+
496+
private void Push_Check_DS_CheckedChanged(object sender, EventArgs e)
497+
{
498+
if (Push_Check_DS.Checked)
499+
{
500+
Pull_Check_DS.Checked = false;
501+
Pull_Check_QS.Checked = true;
502+
Push_Check_QS.Checked = false;
503+
}
504+
else if (!Push_Check_DS.Checked)
505+
{
506+
Pull_Check_DS.Checked = true;
507+
Pull_Check_QS.Checked = false;
508+
Push_Check_QS.Checked = true;
509+
}
510+
}
367511
}
368512
}

0 commit comments

Comments
 (0)