🎉 串口基础API
This commit is contained in:
parent
7b9706456d
commit
4e1d211e40
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>Base_1_Create</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.IO.Ports" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<Application x:Class="Base_2_Window.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Base_2_Window"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -0,0 +1,12 @@
|
|||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace Base_2_Window;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
|
@ -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)
|
||||
)]
|
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<RootNamespace>Base_2_Window</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,19 @@
|
|||
<Window x:Class="Base_2_Window.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
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">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0">
|
||||
<TextBlock>XXX</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue