-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
115 lines (84 loc) · 3.3 KB
/
MainWindow.xaml.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
using System;
using System.Windows;
using System.Windows.Controls;
using System.IO;
using MiunskeBoardProject.classes;
namespace MiunskeBoardProject
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static event EventHandler<CanFoxRxEventArg> Event_RxCanMessage;
public MainWindow()
{
InitializeComponent();
string[] boardFiles = Directory.GetFiles("../../../boards", "*xaml.cs");
foreach (string boardName in boardFiles)
{
string trimmedString = boardName.Substring(16, boardName.Length - 24);
BoardList.Items.Add(trimmedString);
}
BoardList.SelectionChanged += new SelectionChangedEventHandler(switch_Board_Visual);
canButton.Click += new RoutedEventHandler(can_button_click);
}
/// <summary>
/// Subskyrbent zdarzenia kliknięcia nazyw płytki w oknie głównym, renderuje nową płytkę o takiej nazwie
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void switch_Board_Visual(object sender, EventArgs e)
{
if (BoardList.SelectedItem == null)
return;
boardHolder.Children.Clear();
string boardClassName = "MiunskeBoardProject.boards." +BoardList.SelectedItem.ToString();
var a = Activator.CreateInstance(Type.GetType(boardClassName), null);
boardHolder.Children.Add((UIElement)a);
}
private void CANFox_Event_RxCanMessage(object sender, CanFoxRxEventArg e)
{
FireEventRxCanMessage(e);
}
private void FireEventRxCanMessage(CANMessages newMessages)
{
EventHandler<CanFoxRxEventArg> event_RxCanMessage = Event_RxCanMessage;
if (event_RxCanMessage != null)
{
event_RxCanMessage(this, new CanFoxRxEventArg(newMessages));
}
}
private void FireEventRxCanMessage(CanFoxRxEventArg EventMessages)
{
EventHandler<CanFoxRxEventArg> event_RxCanMessage = Event_RxCanMessage;
if (event_RxCanMessage != null)
{
event_RxCanMessage(this, EventMessages);
}
}
/// <summary>
/// Subskrybent zdarzneia kliknięcia przycisku "Otrzymuj iwadomośći CAN"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void can_button_click(object sender, EventArgs e)
{
CANFox cf = new CANFox();
try
{
CANFox.ErrorCode res = cf.openCan();
if(res != CANFox.ErrorCode.NTCAN_SUCCESS)
{
MessageBox.Show(Enum.GetName(typeof(CANFox.ErrorCode), res));
return;
}
CANFox.Event_RxCanMessage += CANFox_Event_RxCanMessage;
}
catch(Exception e1)
{
MessageBox.Show(e1.Message);
}
}
}
}