public ModbusRtuRequestHandler(IModbusRtuSerialPort serialPort, ModbusRtuServer rtuServer) : base(rtuServer, 256) { _serialPort = serialPort; _serialPort.Open(); base.Start(); }
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); }
internal void Connect(IModbusRtuSerialPort serialPort) { if (this.Parity == Parity.None && this.StopBits != StopBits.Two) { throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits); } _frameBuffer = new ModbusFrameBuffer(256); _serialPort?.Close(); _serialPort = serialPort; _serialPort.Open(); }
/// <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); }
/// <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); }
internal void Connect(IModbusRtuSerialPort serialPort, ModbusEndianness endianness) { if (this.Parity == Parity.None && this.StopBits != StopBits.Two) { throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits); } base.SwapBytes = BitConverter.IsLittleEndian && endianness == ModbusEndianness.BigEndian || !BitConverter.IsLittleEndian && endianness == ModbusEndianness.LittleEndian; _frameBuffer = new ModbusFrameBuffer(256); _serialPort?.Close(); _serialPort = serialPort; _serialPort.Open(); }
internal void Connect(IModbusRtuSerialPort serialPort, ModbusEndianness endianness) { /* 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.SwapBytes = BitConverter.IsLittleEndian && endianness == ModbusEndianness.BigEndian || !BitConverter.IsLittleEndian && endianness == ModbusEndianness.LittleEndian; _frameBuffer = new ModbusFrameBuffer(256); _serialPort?.Close(); _serialPort = serialPort; _serialPort.Open(); }
internal void Connect(IModbusRtuSerialPort serialPort) { this.Connect(serialPort, ModbusEndianness.LittleEndian); }