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)); //核心代码
相关推荐
zybsjn1 小时前
后端系统做国际化改造,生成多语言包
java·python·c#
敲代码的 蜡笔小新2 小时前
【行为型之迭代器模式】游戏开发实战——Unity高效集合遍历与场景管理的架构精髓
unity·设计模式·c#·迭代器模式
yc_12242 小时前
SqlHelper 实现类,支持多数据库,提供异步操作、自动重试、事务、存储过程、分页、缓存等功能。
数据库·c#
Kookoos3 小时前
Redis + ABP vNext 构建分布式高可用缓存架构
redis·分布式·缓存·架构·c#·.net
Zhen (Evan) Wang5 小时前
ABP-Book Store Application中文讲解 - Part 2: The Book List Page
c#
小乖兽技术6 小时前
在 .NET 8 开发的WinForms 程序中展示程序版本号的几种方式
开发语言·c#·.net
TheWindofFate7 小时前
C# 基础 try-catch代码块
c#·try-catch
TIF星空11 小时前
【使用 C# 获取 USB 设备信息及进行通信】
开发语言·经验分享·笔记·学习·microsoft·c#
csdn_aspnet13 小时前
如何在 C# 中自定义 Datagridview 标题
c#·winform·datagridview
津津有味道13 小时前
MIFARE DESFire Light 卡C#读写更改卡片密钥源码
c#·light·desfire·ev2