alielie
2025-11-21 3a471ae651b228231bebb3a2d438baa1d4ac0261
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using HMI.Util;
using System;
using System.IO.Ports;
 
namespace HMI.UI.Entity
{
    public class ScannerConfig
    {
        public string PortName { get; set; }
 
        public int BaudRate { get; set; }
        public Parity Parity { get; set; } = Parity.None;
        public int DataBits { get; set; }
        public StopBits StopBits { get; set; } = StopBits.One;
        public Handshake Handshake { get; set; } = Handshake.None;
        public bool DtrEnable { get; set; } = true;
        public bool RtsEnable { get; set; } = true;
 
 
        public static ScannerConfig ReadFromIni(string iniFile, string section)
        {
            var res = new ScannerConfig();
            res.PortName = IniFileHelper.ReadIniData(section, "PortName", "COM1", iniFile);
            res.BaudRate = int.Parse(IniFileHelper.ReadIniData(section, "BaudRate", "9600", iniFile));
            res.Parity = (Parity)Enum.Parse(typeof(Parity), IniFileHelper.ReadIniData(section, "Parity", "None", iniFile));
            res.DataBits = int.Parse(IniFileHelper.ReadIniData(section, "DataBits", "8", iniFile));
            res.StopBits = (StopBits)Enum.Parse(typeof(StopBits), IniFileHelper.ReadIniData(section, "StopBits", "One", iniFile));
            res.Handshake = (Handshake)Enum.Parse(typeof(Handshake), IniFileHelper.ReadIniData(section, "Handshake", "None", iniFile));
            res.DtrEnable = bool.Parse(IniFileHelper.ReadIniData(section, "DtrEnable", "true", iniFile));
            res.RtsEnable = bool.Parse(IniFileHelper.ReadIniData(section, "RtsEnable", "true", iniFile));
            return res;
        }
    }
}