I have a Tauri app that is opening a connection to a serial port over USB and am having problems with freeing up the port once I am done. I have this code to drop the connection:
pub async fn drop_connection<R: Runtime>(
serial_state: State<'_, SerialState>,
window: Window<R>,
) -> Result<String, SerialError> {
let guard = serial_state.connection.lock().await;
drop(guard);
}
The serial connection
is defined here:
pub struct SerialState {
pub port: Arc<Mutex<String>>,
pub connection: Arc<Mutex<Option<Box<dyn serialport::SerialPort>>>>,
pub baud_rate: u32,
pub ports: Arc<Mutex<Vec<SerialPort>>>,
}
Everything works well on Mac but on Windows after dropping my connection and trying to re-connect I am seeing:
'COM4': Access is denied.
It looks like the port is still locked by my program. Are there any suggestions on where I am going wrong? Thanks!