Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After altering the baud rate, serial communication no longer works. #234

Open
ramen2k10 opened this issue May 17, 2023 · 1 comment
Open

Comments

@ramen2k10
Copy link

ramen2k10 commented May 17, 2023

I'm attempting to contact with a chip card device using serial communication, which is linked to a reader via a serial port. The communication works fine when I use the initial baud rate 9600, but when I change the initial baud rate (9600) of my serial port communication to a higher baud rate value (e.g. - 115200), the device closes the connection, despite the fact that the same device works fine with a higher baud rate using the javax.comm library. Please see the code snippet attached.

public void setBaudRate(int rate) throws UnsupportedCommOperationException {
	if (null != serialPort) {
		if (serialPort.getBaudRate() != rate) {
			boolean rts = serialPort.isRTS();
			boolean dtr = serialPort.isDTR();
        	serialPort = nrSerialPort.getSerialPortInstance();// Extracting the serialPort instance
        	serialPort.setSerialPortParams(rate, serialPort.getDataBits(), serialPort.getStopBits(), serialPort.getParity());
        	serialPort.setDTR(dtr);
		serialPort.setRTS(rts);
		}
	}
}

Is the baud rate changing supported by the nrjavaserial library?

@fkamming
Copy link

fkamming commented Oct 5, 2023

I'm attempting to contact with a chip card device using serial communication, which is linked to a reader via a serial port. The communication works fine when I use the initial baud rate 9600, but when I change the initial baud rate (9600) of my serial port communication to a higher baud rate value (e.g. - 115200), the device closes the connection, despite the fact that the same device works fine with a higher baud rate using the javax.comm library. Please see the code snippet attached.

public void setBaudRate(int rate) throws UnsupportedCommOperationException {
	if (null != serialPort) {
		if (serialPort.getBaudRate() != rate) {
			boolean rts = serialPort.isRTS();
			boolean dtr = serialPort.isDTR();
        	serialPort = nrSerialPort.getSerialPortInstance();// Extracting the serialPort instance
        	serialPort.setSerialPortParams(rate, serialPort.getDataBits(), serialPort.getStopBits(), serialPort.getParity());
        	serialPort.setDTR(dtr);
		serialPort.setRTS(rts);
		}
	}
}

Is the baud rate changing supported by the nrjavaserial library?

Changing baud rate works fine in our code. I suspect what is missing in your code is disconnecting and reconnecting. Before you set the new baud rate call serialPort.disconnect(). And afterwards call serialPort.connect().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants