using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using System.IO;

namespace VitrosConsole.Port
{
    public class SerialPortListener
    {
        private readonly SerialPortConfig _portConfig;

        public SerialPortListener(IOptions<SerialPortConfig> options)
        {
            _portConfig = options.Value;
        }
        public SerialPort GetSerialPort()
        {
            return new SerialPort(_portConfig.PortName)
            {
                BaudRate = _portConfig.BaudRate,
                Parity = (Parity)Enum.Parse(typeof(Parity), _portConfig.Parity),
                StopBits = (StopBits)_portConfig.StopBits,
                DataBits = _portConfig.DataBits
            };
        }
    }
}
