diff --git a/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj b/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj index 5cc54ea..c4fbee4 100644 --- a/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj +++ b/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj @@ -9,4 +9,14 @@ true + + + ..\..\..\..\..\..\..\software\Plugins\nuget\system.io.ports\5.0.1\ref\netstandard2.0\System.IO.Ports.dll + + + + + + + diff --git a/CSharp/SerialPort/Base-2-Window/MVVM/ViewModelBase.cs b/CSharp/SerialPort/Base-2-Window/MVVM/ViewModelBase.cs new file mode 100644 index 0000000..5fd8424 --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/MVVM/ViewModelBase.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Base_2_Window.MVVM; + +public class ViewModelBase : INotifyPropertyChanged +{ + public event PropertyChangedEventHandler? PropertyChanged; + + protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/MainWindow.xaml b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml index 04855b3..c369293 100644 --- a/CSharp/SerialPort/Base-2-Window/MainWindow.xaml +++ b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml @@ -3,17 +3,71 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:Base_2_Window" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> - - - - + + + + - - XXX - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs index c57fc25..7b7d245 100644 --- a/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs +++ b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs @@ -1,23 +1,26 @@ -using System.Text; +using System.IO.Ports; 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 Base_2_Window.ViewModel; namespace Base_2_Window; /// -/// Interaction logic for MainWindow.xaml +/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); + + DataContext = new MainWindowViewModel + { + SerialPortNames = SerialPort.GetPortNames().Select(s => s).ToList(), + BaudRates = new List { 9600 }, + DataBits = new List { 6, 7, 8 }, + StopBitsList = new List { StopBits.None, StopBits.One, StopBits.Two, StopBits.OnePointFive }, + ParityList = new List + { Parity.None, Parity.Even, Parity.Mark, Parity.None, Parity.Odd, Parity.Space } + }; } } \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/Model/SerialPortModel.cs b/CSharp/SerialPort/Base-2-Window/Model/SerialPortModel.cs new file mode 100644 index 0000000..57f79e2 --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/Model/SerialPortModel.cs @@ -0,0 +1,14 @@ +using System.IO.Ports; + +namespace Base_2_Window.Model; + +public class SerialPortModel +{ + public List? SerialPortNames { get; set; } + + public int? BaudRate { get; set; } + + public int? DataBits { get; set; } + + public StopBits? StopBits { get; set; } +} \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/ViewModel/MainWindowViewModel.cs b/CSharp/SerialPort/Base-2-Window/ViewModel/MainWindowViewModel.cs new file mode 100644 index 0000000..38e11dd --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/ViewModel/MainWindowViewModel.cs @@ -0,0 +1,17 @@ +using System.IO.Ports; +using Base_2_Window.MVVM; + +namespace Base_2_Window.ViewModel; + +public class MainWindowViewModel : ViewModelBase +{ + public List? SerialPortNames { get; set; } + + public List? BaudRates { get; set; } + + public List? StopBitsList { get; set; } + + public List? ParityList { get; set; } + + public List? DataBits { get; set; } +} \ No newline at end of file diff --git a/CSharp/SerialPort/SerialPort.sln.DotSettings.user b/CSharp/SerialPort/SerialPort.sln.DotSettings.user new file mode 100644 index 0000000..bba4a65 --- /dev/null +++ b/CSharp/SerialPort/SerialPort.sln.DotSettings.user @@ -0,0 +1,4 @@ + + ForceIncluded + ForceIncluded + ForceIncluded \ No newline at end of file