Exemple #1
0
        internal void Start(IModbusRtuSerialPort serialPort)
        {
            if (this.Parity == Parity.None && this.StopBits != StopBits.Two)
            {
                throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits);
            }

            // "base..." is important!
            base.Stop();
            base.Start();

            this.RequestHandler = new ModbusRtuRequestHandler(serialPort, this);
        }
Exemple #2
0
        /// <summary>
        /// Starts the server. It will communicate using the provided <paramref name="serialPort"/>.
        /// </summary>
        /// <param name="serialPort">The serial port to be used.</param>
        public void Start(IModbusRtuSerialPort serialPort)
        {
            /* According to the spec (https://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf),
             * section 2.5.1 RTU Transmission Mode: "... the use of no parity requires 2 stop bits."
             * Remove this check to improve compatibility (#56).
             */

            //if (this.Parity == Parity.None && this.StopBits != StopBits.Two)
            //    throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits);

            base.StopProcessing();
            base.StartProcessing();

            this.RequestHandler = new ModbusRtuRequestHandler(serialPort, this);
        }