Ejemplo n.º 1
0
        // 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)
        {
            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;

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

            else
            {
                Interface = new NativeSerial(socket, baudRate, (Socket.SocketInterfaces.SerialParity)parity, (Socket.SocketInterfaces.SerialStopBits)stopBits, dataBits, (Socket.SocketInterfaces.HardwareFlowControl)hardwareFlowControlRequirement, module, portName, hwFlowSupported);
            }

            Interface.NewLine      = "\n";
            Interface.Encoding     = System.Text.Encoding.UTF8;
            Interface.ReadTimeout  = InfiniteTimeout;
            Interface.WriteTimeout = InfiniteTimeout;
        }
Ejemplo n.º 2
0
 private void OnInterfaceLineReceived(Socket.SocketInterfaces.Serial sender, string line)
 {
     OnLineReceivedEvent(this, line);
 }
Ejemplo n.º 3
0
 private void OnInterfaceDataReceived(Socket.SocketInterfaces.Serial sender)
 {
     OnDataReceivedEvent(this, SerialData.Chars);
 }
Ejemplo n.º 4
0
        // 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)
        {
            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;

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

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

            Interface.NewLine = "\n";
            Interface.Encoding = System.Text.Encoding.UTF8;
            Interface.ReadTimeout = InfiniteTimeout;
            Interface.WriteTimeout = InfiniteTimeout;
        }