Beispiel #1
0
        public static ManagedSerialPort CreateForPort(string portName, SerialPortOptions options)
        {
            var serialPortDevice = new System.IO.Ports.SerialPort(portName);
            var serialPortImpl   = new Win32SerialPortImplementation(serialPortDevice, options);

            return(new ManagedSerialPort(serialPortImpl));
        }
 public UWPSerialPortImplementation(SerialDevice serialDevice, SerialPortOptions options)
 {
     this.serialDevice              = serialDevice;
     this.serialDevice.BaudRate     = options.BaudRate;
     this.serialDevice.Parity       = options.Parity.ToSerialParity();
     this.serialDevice.StopBits     = options.StopBits.ToSerialStopBitCount();
     this.serialDevice.ReadTimeout  = TimeSpan.FromMilliseconds(options.ReadTimeoutMs);
     this.serialDevice.WriteTimeout = TimeSpan.FromMilliseconds(options.WriteTimeoutMs);
 }
 public Win32SerialPortImplementation(SerialPort serialPort, SerialPortOptions serialPortOptions)
 {
     this.serialPort              = serialPort;
     this.serialPort.BaudRate     = (int)serialPortOptions.BaudRate;
     this.serialPort.Parity       = serialPortOptions.Parity.ToParity();
     this.serialPort.StopBits     = serialPortOptions.StopBits.ToStopBits();
     this.serialPort.ReadTimeout  = serialPortOptions.ReadTimeoutMs;
     this.serialPort.WriteTimeout = serialPortOptions.WriteTimeoutMs;
 }
Beispiel #4
0
        public static async Task <ManagedSerialPort> CreateForDeviceIdAsync(string deviceId, SerialPortOptions options)
        {
            var serialPortDevice = await SerialDevice.FromIdAsync(deviceId);

            var serialPortImpl = new UWPSerialPortImplementation(serialPortDevice, options);

            return(new ManagedSerialPort(serialPortImpl));
        }
Beispiel #5
0
        public static async Task <ManagedSerialPort> CreateForVendorProductAsync(ushort vendorId, ushort productId, SerialPortOptions options)
        {
            var serialPortSelector = SerialDevice.GetDeviceSelectorFromUsbVidPid(vendorId, productId);
            var devices            = await DeviceInformation.FindAllAsync(serialPortSelector);

            if (devices.Count == 0)
            {
                throw new ArgumentException($"Unable to find serial device with VendorId 0x{vendorId:X}, ProductId 0x{productId:X}");
            }

            var serialPortDevice = await SerialDevice.FromIdAsync(devices[0].Id);

            var serialPortImpl = new UWPSerialPortImplementation(serialPortDevice, options);

            return(new ManagedSerialPort(serialPortImpl));
        }