From 4e1d211e401fce133ebbdcfdc181dddf97449003 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Mon, 23 Jun 2025 22:26:07 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20=E4=B8=B2=E5=8F=A3=E5=9F=BA=E7=A1=80AP?= =?UTF-8?q?I?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base-1-Create/Base-1-Create.csproj | 13 +++++++ CSharp/SerialPort/Base-1-Create/Program.cs | 35 ++++++++++++++++++ CSharp/SerialPort/Base-2-Window/App.xaml | 9 +++++ CSharp/SerialPort/Base-2-Window/App.xaml.cs | 12 +++++++ .../SerialPort/Base-2-Window/AssemblyInfo.cs | 10 ++++++ .../Base-2-Window/Base-2-Window.csproj | 12 +++++++ .../SerialPort/Base-2-Window/MainWindow.xaml | 19 ++++++++++ .../Base-2-Window/MainWindow.xaml.cs | 23 ++++++++++++ CSharp/SerialPort/SerialPort.sln | 36 +++++++++++++++++++ 9 files changed, 169 insertions(+) create mode 100644 CSharp/SerialPort/Base-1-Create/Base-1-Create.csproj create mode 100644 CSharp/SerialPort/Base-1-Create/Program.cs create mode 100644 CSharp/SerialPort/Base-2-Window/App.xaml create mode 100644 CSharp/SerialPort/Base-2-Window/App.xaml.cs create mode 100644 CSharp/SerialPort/Base-2-Window/AssemblyInfo.cs create mode 100644 CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj create mode 100644 CSharp/SerialPort/Base-2-Window/MainWindow.xaml create mode 100644 CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs create mode 100644 CSharp/SerialPort/SerialPort.sln diff --git a/CSharp/SerialPort/Base-1-Create/Base-1-Create.csproj b/CSharp/SerialPort/Base-1-Create/Base-1-Create.csproj new file mode 100644 index 0000000..13a1809 --- /dev/null +++ b/CSharp/SerialPort/Base-1-Create/Base-1-Create.csproj @@ -0,0 +1,13 @@ + + + + Exe + net5.0 + Base_1_Create + + + + + + + diff --git a/CSharp/SerialPort/Base-1-Create/Program.cs b/CSharp/SerialPort/Base-1-Create/Program.cs new file mode 100644 index 0000000..5baeab7 --- /dev/null +++ b/CSharp/SerialPort/Base-1-Create/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.IO.Ports; + +namespace Base_1_Create +{ + internal class Program + { + private static void Main(string[] args) + { + var serialPort = new SerialPort + { + // 串口名称 + PortName = "COM1", + // 值越大传输越快,默认9600 + BaudRate = 9600, + // 数据位 + DataBits = 8, + // 默认是 1 + StopBits = StopBits.One, + // 校验位,校验位 1 的个数 + Parity = Parity.Odd, + // 读取时缓冲区字节数 + ReadBufferSize = 4096 + }; + + // 打开串口 + serialPort.Open(); + + if (serialPort.IsOpen) Console.WriteLine("串口打开"); + + // 关闭串口 + // serialPort.Close(); + } + } +} \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/App.xaml b/CSharp/SerialPort/Base-2-Window/App.xaml new file mode 100644 index 0000000..8800935 --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/CSharp/SerialPort/Base-2-Window/App.xaml.cs b/CSharp/SerialPort/Base-2-Window/App.xaml.cs new file mode 100644 index 0000000..9e26992 --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/App.xaml.cs @@ -0,0 +1,12 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace Base_2_Window; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ +} \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/AssemblyInfo.cs b/CSharp/SerialPort/Base-2-Window/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] \ No newline at end of file diff --git a/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj b/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj new file mode 100644 index 0000000..5cc54ea --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/Base-2-Window.csproj @@ -0,0 +1,12 @@ + + + + WinExe + net6.0-windows + Base_2_Window + enable + enable + true + + + diff --git a/CSharp/SerialPort/Base-2-Window/MainWindow.xaml b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml new file mode 100644 index 0000000..04855b3 --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml @@ -0,0 +1,19 @@ + + + + + + + + + XXX + + + diff --git a/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs new file mode 100644 index 0000000..c57fc25 --- /dev/null +++ b/CSharp/SerialPort/Base-2-Window/MainWindow.xaml.cs @@ -0,0 +1,23 @@ +using System.Text; +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; + +namespace Base_2_Window; + +/// +/// Interaction logic for MainWindow.xaml +/// +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/CSharp/SerialPort/SerialPort.sln b/CSharp/SerialPort/SerialPort.sln new file mode 100644 index 0000000..50c4410 --- /dev/null +++ b/CSharp/SerialPort/SerialPort.sln @@ -0,0 +1,36 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36212.18 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ModuleBus", "ModuleBus", "{6C2EABF6-5D1B-41D1-9BA2-3AF2798FF5BB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Base", "Base", "{62565C31-44DB-4369-A8B1-76772A3CFA22}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Base-1-Create", "Base-1-Create\Base-1-Create.csproj", "{82D48C39-53F1-42D1-8EF7-74D589C06A64}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Base-2-Window", "Base-2-Window\Base-2-Window.csproj", "{09CDF9A7-1DA1-4452-94F5-E150B4AE15F4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82D48C39-53F1-42D1-8EF7-74D589C06A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82D48C39-53F1-42D1-8EF7-74D589C06A64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82D48C39-53F1-42D1-8EF7-74D589C06A64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82D48C39-53F1-42D1-8EF7-74D589C06A64}.Release|Any CPU.Build.0 = Release|Any CPU + {09CDF9A7-1DA1-4452-94F5-E150B4AE15F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09CDF9A7-1DA1-4452-94F5-E150B4AE15F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09CDF9A7-1DA1-4452-94F5-E150B4AE15F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09CDF9A7-1DA1-4452-94F5-E150B4AE15F4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {82D48C39-53F1-42D1-8EF7-74D589C06A64} = {62565C31-44DB-4369-A8B1-76772A3CFA22} + {09CDF9A7-1DA1-4452-94F5-E150B4AE15F4} = {62565C31-44DB-4369-A8B1-76772A3CFA22} + EndGlobalSection +EndGlobal