当前位置: 首页>>代码示例>>C#>>正文


C# Socket.SupportsType方法代码示例

本文整理汇总了C#中Socket.SupportsType方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.SupportsType方法的具体用法?C# Socket.SupportsType怎么用?C# Socket.SupportsType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Socket的用法示例。


在下文中一共展示了Socket.SupportsType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        /// <summary>
        /// Creates an instance of <see cref="Serial" /> for the given socket.
        /// </summary>
        /// <remarks>This automatically checks that the socket supports Type U, and reserves the pins.
        /// An exception will be thrown if there is a problem with these checks.</remarks>
        /// <param name="baudRate">The baud rate for the serial port.</param>
        /// <param name="parity">A value from the <see cref="SerialParity"/> enumeration that specifies 
        /// the parity for the port.</param>
        /// <param name="stopBits">A value from the <see cref="SerialStopBits"/> enumeration that specifies 
        /// the stop bits for the port.</param>
        /// <param name="dataBits">The number of data bits.</param>
        /// <param name="socket">The socket for this serial interface.</param>
        /// <param name="hardwareFlowControlRequirement">Specifies whether the module must use hardware flow control, will use hardware flow control if available, or does not use hardware flow control.</param>
        /// <param name="module">The module using this interface (which can be null if unspecified).</param>
        /// <returns>An instance of <see cref="Serial" /> for the given socket.</returns>
        public static Serial Create(Socket socket, int baudRate, SerialParity parity, SerialStopBits stopBits, int dataBits, HardwareFlowControl hardwareFlowControlRequirement, Module module)
        {
            bool hwFlowSupported = false;

            if (hardwareFlowControlRequirement == HardwareFlowControl.Required)
                socket.EnsureTypeIsSupported('K', module);
            else
            {
                hwFlowSupported = socket.SupportsType('K');

                if (!hwFlowSupported)
                    socket.EnsureTypeIsSupported('U', module);
            }

            socket.ReservePin(Socket.Pin.Four, module);
            socket.ReservePin(Socket.Pin.Five, module);
            if (hardwareFlowControlRequirement != HardwareFlowControl.NotRequired)
            {
                // must reserve hardware flow control pins even if not using them, since they are electrically connected.
                socket.ReservePin(Socket.Pin.Six, module);
                socket.ReservePin(Socket.Pin.Seven, module);
            }

            string portName = socket.SerialPortName;

            Serial instance;

            if ((portName == null || portName == "") && socket.SerialIndirector != null)
                instance = socket.SerialIndirector(socket, baudRate, (SerialParity)parity, (SerialStopBits)stopBits, dataBits, (HardwareFlowControl)hardwareFlowControlRequirement, module);

            else
                instance = new NativeSerial(socket, baudRate, (SerialParity)parity, (SerialStopBits)stopBits, dataBits, (HardwareFlowControl)hardwareFlowControlRequirement, module, portName, hwFlowSupported);

            instance.NewLine = "\n";
            instance.ReadTimeout = System.Threading.Timeout.Infinite;
            instance.WriteTimeout = System.Threading.Timeout.Infinite;            
            return instance;
        }
开发者ID:EmiiFont,项目名称:MyShuttle_RC,代码行数:53,代码来源:SerialFactory.cs

示例2: Serial

        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <remarks>This automatically checks that the socket supports Type U, and reserves the pins.
        /// An exception will be thrown if there is a problem with these checks.</remarks>
        /// <param name="baudRate">The baud rate for the serial port.</param>
        /// <param name="parity">A value from the <see cref="SerialParity"/> enumeration that specifies 
        /// the parity for the port.</param>
        /// <param name="stopBits">A value from the <see cref="SerialStopBits"/> enumeration that specifies 
        /// the stop bits for the port.</param>
        /// <param name="dataBits">The number of data bits.</param>
        /// <param name="socket">The socket for this serial interface.</param>
        /// <param name="hardwareFlowControlRequirement">Specifies whether the module must use hardware flow control, will use hardware flow control if available, or does not use hardware flow control.</param>
        /// <param name="module">The module using this interface (which can be null if unspecified).</param>
        public Serial(Socket socket, int baudRate, SerialParity parity, SerialStopBits stopBits, int dataBits, HardwareFlowControl hardwareFlowControlRequirement, Module module)
        {
            if (!socket.SupportsType('U'))
            {
                if (module != null)
                {
                    throw new Socket.InvalidSocketException("Module " + module + " cannot use socket " + socket + " because it requires a socket supporting type 'K'" + (hardwareFlowControlRequirement == HardwareFlowControl.Required ? "" : " or type 'U'."));
                }
                else
                {
                    throw new Socket.InvalidSocketException("Cannot use socket " + socket + " because it does not support socket type 'K'" + (hardwareFlowControlRequirement == HardwareFlowControl.Required ? "" : " or type 'U'."));
                }
            }

            bool socketSupportsHardwareFlowControl = socket.SupportsType('K');
            if (hardwareFlowControlRequirement == HardwareFlowControl.Required && !socketSupportsHardwareFlowControl)
            {
                if (module != null)
                {
                    throw new Socket.InvalidSocketException("Module " + module + " cannot use socket " + socket + " because it requires a socket supporting type 'K'.");
                }
                else
                {
                    throw new Socket.InvalidSocketException("Cannot use socket " + socket + " because it does not support socket type 'K' and hardware flow control is required. Please relax the requirement for hardware flow control or use a socket supporting type 'K'.");
                }
            }

            string portName = socket.SerialPortName;

            if (portName == null || portName == "")
            {
                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Serial functionality. Please try a different socket.");

            }

            socket.ReservePin(Socket.Pin.Four, module);
            socket.ReservePin(Socket.Pin.Five, module);
            if (hardwareFlowControlRequirement != HardwareFlowControl.NotRequired)
            {
                // must reserve hardware flow control pins even if not using them, since they are electrically connected.
                socket.ReservePin(Socket.Pin.Six, module);
                socket.ReservePin(Socket.Pin.Seven, module);
            }

            this.LineReceivedEventDelimiter = "\n";

            this.Encoding = System.Text.Encoding.UTF8;

            this._serialPort = new SerialPort(portName, baudRate, (System.IO.Ports.Parity)parity, dataBits, (System.IO.Ports.StopBits)stopBits);
            if ((hardwareFlowControlRequirement != HardwareFlowControl.NotRequired) && socketSupportsHardwareFlowControl)
            {
                this._serialPort.Handshake = Handshake.RequestToSend;
                this._hardwareFlowControl = true;
            }
            else
            {
                this._hardwareFlowControl = false;
            }

            this._serialPort.DataReceived += new SerialDataReceivedEventHandler(this._serialPort_DataReceived);
            this.ReadTimeout = InfiniteTimeout;
            this.WriteTimeout = InfiniteTimeout;
        }
开发者ID:EmiiFont,项目名称:MyShuttle_RC,代码行数:77,代码来源:Serial.cs


注:本文中的Socket.SupportsType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。