I need to disable and then enable a serial port for testing purposes on a Java program.
Since the man
page of setserial
is stating: "Using UART type none will disable the port.", I use sudo setserial /dev/ttyS4 uart none
to disable the port. This successfully disables the serial port. To enable the serial port again, I use sudo setserial /dev/ttyS4 -a autoconfig
and the port is up as expected.
After I've disabled the port, I do try to open the port using the Java gnu.io.CommPortIdentifier function. When I try to enable the port after the executing the gnu.io.CommPortIdentifier
function, I get this output:
$ sudo setserial /dev/ttyS4 -a autoconfig
Cannot autoconfigure port: Device or resource busy
How can I work around this problem? Is there a better way to enable/disable the serial port? Or can I clear the list of requests made to the port?
I obviously can't just kill the process, since my test is running in it.