C# INI文件读取串口参数,string转枚举

在使用ini读取串口配置时,ini文件读取的数据类型为string ,而串口的参数设置校验位和停止位为枚举类型,因类型不匹配,读取出来的字符串不能直接使用,需要作进一步处理,将字符串转换为枚举类型

ini读取字符串并转换为枚举类型示例代码如下:

cs 复制代码
  string _PortName = ReadIni.IniReadValue("ServerPort", "PortName", ReadIni.FileSysIni);读取ini
  string _BaudRate = ReadIni.IniReadValue("ServerPort", "BaudRate", ReadIni.FileSysIni);
  string _Parity = ReadIni.IniReadValue("ServerPort", "Parity", ReadIni.FileSysIni);
  string _DataBits = ReadIni.IniReadValue("ServerPort", "DataBits", ReadIni.FileSysIni);
  string _StopBits = ReadIni.IniReadValue("ServerPort", "StopBits", ReadIni.FileSysIni);
  SerialPort = new SerialPort(_PortName,int.Parse(_BaudRate), (Parity)Enum.Parse(typeof(Parity), _Parity), 8, (StopBits)Enum.Parse(typeof(StopBits), _StopBits)); //核心代码
相关推荐
Vae_Mars10 小时前
C#中的delegate委托
开发语言·c#
公子小六15 小时前
基于.NET的Windows窗体编程之WinForms音频控件
windows·microsoft·c#·.net·音视频·winforms
绿浪198416 小时前
c# 结构体 能不能直接封送检测
开发语言·c#
新手unity自用笔记16 小时前
unity基于Socket的网络学习
网络·网络协议·学习·unity·c#·游戏引擎
格林威17 小时前
C#图像像素放大:邻域平均、双线性插值实现像素放大的C#实现代码
开发语言·人工智能·数码相机·计算机视觉·c#·视觉检测·工业相机
用户298698530141 天前
C# 实现 PowerPoint 多格式转换:图片、PDF 与 SVG 实战
c#·.net·svg
格林威1 天前
C#图像处理:使用imagemagick实现像素放大水印转换等多种功能
android·开发语言·图像处理·人工智能·计算机视觉·c#·视觉检测
胖纸不争1 天前
Clasp:一个带插件系统的 .NET 10 命令行工具箱
c#·net core
曹牧1 天前
C#:数字的定义和表示方式
算法·c#
Young_Gnay2 天前
.NET 之 WebApi学习笔记 (持续更新)
后端·c#