-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
93 lines (87 loc) · 2.67 KB
/
MainWindow.xaml.cs
File metadata and controls
93 lines (87 loc) · 2.67 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO.Ports;
namespace AudioSpectrum
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Analyzer _analyzer;
private SerialPort _port;
public MainWindow()
{
InitializeComponent();
_analyzer = new Analyzer(PbL, PbR, Spectrum, DeviceBox);
}
private void BtnEnable_Click(object sender, RoutedEventArgs e)
{
if (BtnEnable.IsChecked == true)
{
BtnEnable.Content = "Disable";
_analyzer.Enable = true;
}
else
{
_analyzer.Enable = false;
BtnEnable.Content = "Enable";
}
}
private void Comports_DropDownOpened(object sender, EventArgs e)
{
Comports.Items.Clear();
var ports = SerialPort.GetPortNames();
foreach (var port in ports) Comports.Items.Add(port);
}
private void CkbSerial_Click(object sender, RoutedEventArgs e)
{
try
{
if (CkbSerial.IsChecked == true)
{
Comports.IsEnabled = false;
_port = new SerialPort((Comports.Items[Comports.SelectedIndex] as string));
_port.BaudRate = 115200;
_port.StopBits = StopBits.One;
_port.Parity = Parity.None;
_port.DataBits = 8;
_port.DtrEnable = true;
_port.Open();
_analyzer.Serial = _port;
}
else
{
Comports.IsEnabled = true;
_analyzer.Serial = null;
if (_port != null)
{
_port.Close();
_port.Dispose();
_port = null;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void CkbDisplay_Click(object sender, RoutedEventArgs e)
{
_analyzer.DisplayEnable = (bool)CkbDisplay.IsChecked;
}
}
}