Example #1
0
        /// <summary>
        /// Connect to the specified <paramref name="port"/>.
        /// </summary>
        /// <param name="port">The COM port to be used, e.g. COM1.</param>
        /// <param name="endianness">Specifies the endianness of the data exchanged with the Modbus server.</param>
        public void Connect(string port, ModbusEndianness endianness)
        {
            IModbusRtuSerialPort serialPort;

            serialPort = new ModbusRtuSerialPort(new SerialPort(port)
            {
                BaudRate     = this.BaudRate,
                Handshake    = this.Handshake,
                Parity       = this.Parity,
                StopBits     = this.StopBits,
                ReadTimeout  = this.ReadTimeout,
                WriteTimeout = this.WriteTimeout
            });

            this.Connect(serialPort, endianness);
        }
Example #2
0
        /// <summary>
        /// Starts the server. It will listen on the provided <paramref name="port"/>.
        /// </summary>
        /// <param name="port">The COM port to be used, e.g. COM1.</param>
        public void Start(string port)
        {
            IModbusRtuSerialPort serialPort = new ModbusRtuSerialPort(new SerialPort(port)
            {
                BaudRate     = this.BaudRate,
                Handshake    = this.Handshake,
                Parity       = this.Parity,
                StopBits     = this.StopBits,
                ReadTimeout  = this.ReadTimeout,
                WriteTimeout = this.WriteTimeout
            });

            _serialPort = serialPort;

            this.Start(serialPort);
        }