Properly close serial monitor

I on a Mac and using the CLI to program and debug an Electron. In a terminal window I launch the serial monitor using:

particle serial monitor
particle serial monitor /dev/tty.usbmodem331

no problem here until I want to reprogram the Electron. In order to stop the serial monitor I send a control Z in the terminal and get in response

[1]+ Stopped(SIGTSTP) particle serial monitor /dev/tty.usbmodem331

Good but then when I try to flash the electron I get:
! serial:
Error writing firmware…Error: Error Resource temporarily unavailable Cannot lock port
Error: Error Resource temporarily unavailable Cannot lock port
at Error (native)

If I try to relaunch the serial monitor I get:

particle serial monitor /dev/tty.usbmodem331
Opening serial monitor for com port: "/dev/tty.usbmodem331"
Serial err: Error: Error Resource temporarily unavailable Cannot lock port
Serial problems, please reconnect the device.
Caught Interrupt. Cleaning up.

The only way to clear the lock on the serial port appears to be to close the terminal window and relaunch it.

So the simple question is how do you terminate the CLI serial monitor process cleanly, i.e. the lock on the serial port is released on exit.

Control c works for me to close the serial connection.

1 Like

Yep that works.

Control Z actually suspends the process and pushes it to the back ground in the suspended state, the process can then be reactivated with a simple fg command. I guess old habits die hard.

1 Like

I’m stuck with particle serial monitor in a suspended state after entering the command “control Z” into my terminal. I tried entering “fg” into my terminal with no luck for bringing the monitor out of a suspended state. Am i entering the fg command correctly?

Please disregard. I was able to use the command particle usb reset to reset the connected device which then reestablished a serial connection