public static System.IO.Ports.Parity ToParity(this SerialPortParity source)
        {
            switch (source)
            {
            case SerialPortParity.None:
                return(System.IO.Ports.Parity.None);

            case SerialPortParity.Odd:
                return(System.IO.Ports.Parity.Odd);

            case SerialPortParity.Even:
                return(System.IO.Ports.Parity.Even);

            case SerialPortParity.Mark:
                return(System.IO.Ports.Parity.Mark);

            case SerialPortParity.Space:
                return(System.IO.Ports.Parity.Space);

            default:
                throw new ArgumentException($"Could not convert SerialPortParity of {source} to type System.IO.Ports.Parity");
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SerialPort"/> class. 
        /// Creates a new instance of SerialCom.
        /// </summary>
        /// <param>
        /// The name of the serial port to connect to.
        /// </param>
        /// <param>
        /// The baud rate at which the communications device operates.
        /// </param>
        /// <param>
        /// The number of stop bits to be used.
        /// </param>
        /// <param>
        /// The parity scheme to be used.
        /// </param>
        /// <param>
        /// The number of bits in the bytes to be transmitted and received.
        /// </param>
        /// <param name="portName">
        /// The port Name.
        /// </param>
        /// <param name="baudRate">
        /// The baud Rate.
        /// </param>
        /// <param name="stopBits">
        /// The stop Bits.
        /// </param>
        /// <param name="parity">
        /// The parity.
        /// </param>
        /// <param name="byteSize">
        /// The byte Size.
        /// </param>
        public SerialPort(string portName, int baudRate, StopBits stopBits, SerialPortParity parity, byte byteSize)
        {
            if (stopBits == StopBits.None)
                throw new ArgumentException("stopBits cannot be StopBits.None", "stopBits");

            if (byteSize < 5 || byteSize > 8)
                throw new ArgumentOutOfRangeException("The number of data bits must be 5 to 8 bits.", "byteSize");

            if (baudRate < 110 || baudRate > 256000)
                throw new ArgumentOutOfRangeException("Invalid baud rate specified.", "baudRate");

            if ((byteSize == 5 && stopBits == StopBits.Two) || (stopBits == StopBits.OnePointFive && byteSize > 5))
                throw new ArgumentException("The use of 5 data bits with 2 stop bits is an invalid combination, " +
                    "as is 6, 7, or 8 data bits with 1.5 stop bits.");

            this.sPortName = portName;
            this.iBaudRate = baudRate;
            this.byteSize = byteSize;
            this.stopBits = stopBits;
            this.parity = parity;
        }
Exemple #3
0
        /// <summary>
        /// Creates a new instance of SerialCom.
        /// </summary>
        /// <param>The name of the serial port to connect to</param>
        /// <param>The baud rate at which the communications device operates</param>
        /// <param>The number of stop bits to be used</param>
        /// <param>The parity scheme to be used</param>
        public SerialPort(string portName, int baudRate, StopBits stopBits, SerialPortParity parity)
            : this(portName, baudRate, stopBits, parity, 8)
        {

        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExternalDataConfigurationConnectionContext"/> class.
 /// </summary>
 /// <param name="name">
 /// The name.
 /// </param>
 /// <param name="systemName">
 /// The system Name.
 /// </param>
 /// <param name="portName">
 /// The port name.
 /// </param>
 /// <param name="baudRate">
 /// The baud rate.
 /// </param>
 /// <param name="parity">
 /// The parity.
 /// </param>
 /// <param name="dtr">
 /// The dtr.
 /// </param>
 /// <param name="flowControlHighSignal">
 /// The flow control high signal.
 /// </param>
 /// <param name="parityErrorChecking">
 /// The parity error checking.
 /// </param>
 /// <param name="flowControl">
 /// The flow control.
 /// </param>
 /// <param name="rts">
 /// The rts.
 /// </param>
 /// <param name="dataBits">
 /// The data bits.
 /// </param>
 /// <param name="connectionType">
 /// The connection type.
 /// </param>
 /// <param name="stopBits">
 /// The stop bits.
 /// </param>
 /// <param name="computerConnectionList">
 /// The computer connection list.
 /// </param>
 /// <param name="vid">
 /// The vid.
 /// </param>
 /// <param name="pid">
 /// The pid.
 /// </param>
 /// <param name="parentIdPrefix">
 /// The parent Id Prefix.
 /// </param>
 /// <param name="expression">
 /// </param>
 public ExternalDataConfigurationConnectionContext(
     string name,
     string systemName,
     string portName,
     string baudRate,
     SerialPortParity parity,
     bool dtr,
     int flowControlHighSignal,
     bool parityErrorChecking,
     FlowControl flowControl,
     bool rts,
     int dataBits,
     ConnectionType connectionType,
     StopBits stopBits,
     IEnumerable<ComputerConnectionContext> computerConnectionList, 
     string vid,
     string pid,
     string parentIdPrefix,
     string expression)
 {
     this._systemName = systemName;
     this._name = name;
     this._portName = portName;
     this._baudRate = baudRate;
     this._parity = parity;
     this._dtr = dtr;
     this._flowControlHighSignal = flowControlHighSignal;
     this._parityErrorChecking = parityErrorChecking;
     this._flowControl = flowControl;
     this._rts = rts;
     this._dataBits = dataBits;
     this._connectionType = connectionType;
     this._stopBits = stopBits;
     this._computerConnectionList = computerConnectionList;
     this._vid = vid;
     this._pid = pid;
     this._parentIdPrefix = parentIdPrefix;
     this._expresion = expression;
    
 }
        public static Windows.Devices.SerialCommunication.SerialParity ToSerialParity(this SerialPortParity source)
        {
            switch (source)
            {
            case SerialPortParity.None:
                return(Windows.Devices.SerialCommunication.SerialParity.None);

            case SerialPortParity.Odd:
                return(Windows.Devices.SerialCommunication.SerialParity.Odd);

            case SerialPortParity.Even:
                return(Windows.Devices.SerialCommunication.SerialParity.Even);

            case SerialPortParity.Mark:
                return(Windows.Devices.SerialCommunication.SerialParity.Mark);

            case SerialPortParity.Space:
                return(Windows.Devices.SerialCommunication.SerialParity.Space);

            default:
                throw new ArgumentException($"Could not convert SerialPortParity of {source} to type Windows.Devices.SerialCommunitcation.SerialParity");
            }
        }