Beispiel #1
0
        public static bool TryParseFromUri(Uri uri, out SerialPortConfig opt)
        {
            if (!"serial".Equals(uri.Scheme, StringComparison.InvariantCultureIgnoreCase))
            {
                opt = null;
                return(false);
            }

            var coll = HttpUtility.ParseQueryString(uri.Query);

            opt = new SerialPortConfig
            {
                PortName  = uri.LocalPath,
                BoundRate = int.Parse(coll["br"] ?? "57600"),
                Parity    = (Parity)Enum.Parse(typeof(Parity), coll["parity"] ?? Parity.None.ToString()),
                DataBits  = int.Parse(coll["dataBits"] ?? "8"),
                StopBits  = (StopBits)Enum.Parse(typeof(StopBits), coll["stopBits"] ?? StopBits.One.ToString()),
            };
            return(true);
        }
Beispiel #2
0
        public static IPort Create(string connectionString)
        {
            var uri = new Uri(connectionString);

            UdpPortConfig udp;

            if (UdpPortConfig.TryParseFromUri(uri, out udp))
            {
                return(new UdpPort(udp));
            }

            SerialPortConfig ser;

            if (SerialPortConfig.TryParseFromUri(uri, out ser))
            {
                return(new CustomSerialPort(ser));
            }

            throw new Exception(string.Format(RS.RemoteStreamFactory_CreateStream_Connection_string_is_invalid, connectionString));
        }
 public CustomSerialPort(SerialPortConfig config)
 {
     _config = config;
 }