Repository navigation
Expand file tree
/
Copy pathForm_Center.cs
More file actions
117 lines (95 loc) · 2.96 KB
/
Copy pathForm_Center.cs
File metadata and controls
117 lines (95 loc) · 2.96 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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;
namespace Game
{
public partial class Form_Main : Form
{
public Form_Main()
{
InitializeComponent();
}
public class MyList<T> : List<T>
{
public event EventHandler OnAdd;
public new void Add(T item) // "new" to avoid compiler-warnings, because we're hiding a method from base-class
{
base.Add(item);
if (null != OnAdd)
{
OnAdd(this, null);
}
}
}
MyList<string> AllAnswers = new MyList<string>();
List<SerialFunction> AllFunctions = new List<SerialFunction>();
/**********************/
/*** IMPLEMENTATION ***\
/**********************/
private void Form_Center_Load(object sender, EventArgs e)
{
foreach (string s in SerialPort.GetPortNames())
{
cob_choosePort.Items.Add(s);
}
Props.stack_rawAnswers = new Props.MyList<string>();
Props.stack_rawAnswers.OnAdd += new EventHandler(List_AddItemEvent);
}
void List_AddItemEvent(object sender, EventArgs e)
{
foreach(SerialFunction s in AllFunctions)
{
if(AllAnswers[0]==s.keyWord)
{
}
}
}
public void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port = (SerialPort)sender;
AllAnswers.Add(port.ReadLine());
this.Invoke(new Action(() =>
{
lbl_traffic.Text += "\n" + port.ReadLine();
// Leo.
}));
}
private void cmd_connect_Click(object sender, EventArgs e)
{
if(Props.serialPort.IsOpen)
{
Serial_functions.ClosePort(this);
cmd_connect.Text="open port";
}
else
{
Props.serialPort.PortName = cob_choosePort.Text;
Props.serialPort.BaudRate = 9600;
Serial_functions.OpenPort(this);
cmd_connect.Text="close port";
}
}
private void cmd_createNewFunction(object sender, EventArgs e)
{
SerialFunction newFunction = new SerialFunction
{
keyWord = txt_keyword.Text,
displayText = txt_displayText.Text,
functionIdx = cob_chooseFunction.Text,
functionPanel = pan_functionTest
};
AllFunctions.Add(newFunction);
}
}
public class SerialFunction
{
public string
keyWord,
displayText,
functionIdx;
public Label targetLabel;
public Panel functionPanel;
}
}