serialport-lib-dotnet icon indicating copy to clipboard operation
serialport-lib-dotnet copied to clipboard

Setting a new baudrate with SetPort(...) doesn't work

Open ghost opened this issue 5 years ago • 6 comments

Hi All,

I tried to set a new baudrate with SetPort() methode, but it doesn't work. Indeed, SetPort() test if a change occured for portName only, but not the other parameters. I suggest the following changes

public void SetPort(string portName, int baudRate = 115200, StopBits stopBits = StopBits.One, Parity parity = Parity.None, DataBits dataBits = DataBits.Eight)
{
	if (_portName != portName || _baudRate != baudRate || stopBits != _stopBits || parity != _parity || dataBits != _dataBits)
	{
		// set to error so that the connection watcher will reconnect
		// using the new port
		gotReadWriteError = true;
		logger.Trace("Port parameter changed (port name / baudrate / stopbits / parity / databits) = " + portName + " / " + baudRate + " / " + stopBits + " / " + parity + " / " + dataBits);
	}
	_portName = portName;
	_baudRate = baudRate;
	_stopBits = stopBits;
	_parity = parity;
	_dataBits = dataBits;
}

ghost avatar Feb 11 '20 10:02 ghost

Hi, Is this repository still alive ?

gitjsdr26 avatar Feb 17 '20 12:02 gitjsdr26

Hi @gitjsdr26, make a pull request with this fix and I will merge it and publish a new release. Also make sure that the code does not break backward compatibility because I have no time to test it in this very moment.

genemars avatar Apr 02 '20 11:04 genemars

@genemars , ok I'll do it. I've been testing these changes for 2 monthes on my application and it works well. Thank you Regards

gitjsdr26 avatar Apr 02 '20 11:04 gitjsdr26

can you already make a pull-request for this?

genemars avatar Apr 03 '20 10:04 genemars

Yes, within 6 hours.

gitjsdr26 avatar Apr 03 '20 11:04 gitjsdr26

It was done in #21

gitjsdr26 avatar Apr 04 '20 09:04 gitjsdr26