Please help me with serial port bluetooth. I'm trying to use the navigator.serial to connect to device and send data. Everything works on Windows. The problem occurs on a mac. I can connect to the device and send data, can turn off, can reconnect. But as soon as I turn off the device and send data, the bluetooth module seems to freeze. and turning on again I can't reconnect to this device. While on Windows, you can reconnect without any problems. And the only solution is to reset the mac bluetooth module in the terminal with command 'sudo pkill bluetoothd'. After that everything works again. Please note, the problem is only on the Monterey release. Could this be a Monterey release bug?
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class SerialportService {
private _navigator: any;
private reader: any;
private writer: any;
private encoder: any;
private decoder: any;
private stato: any;
private port: any = undefined;
constructor() {
this._navigator = navigator
}
async connect() {
if ("serial" in this._navigator) {
try {
//@ts-ignore
this.port = await this._navigator.serial.requestPort();
await this.port.open({ baudRate: 115200 })
this.writer = this.port.writable.getWriter();
this.encoder = new TextEncoder()
this.decoder = new TextDecoder()
} catch (e) {
console.log(e)
}
}
}
async calibrate() {
try {
const view = this.encoder.encode('[C]\n')
const data = await this.writer.write(view)
console.log(view);
await this.writer.releaseLock()
await this.listenToPort();
} catch (e) {
console.log(e)
await this.writer.releaseLock()
}
}
async listenToPort() {
this.reader = this.port.readable.getReader();
while (this.port.readable) {
try {
while (true) {
const { value, done } = await this.reader.read();
if (done) {
this.reader.releaseLock()
break;
}
console.log(this.decoder.decode(value))
}
} catch (error) {
console.log(error)
} finally {
this.reader.releaseLock();
}
await this.port.close();
}
}
async disconnect() {
try {
await this.port.close();
} catch (e) {
console.log(e)
}
}
on Windows, if I turn off the device and try to send data, I get this error. but on a macbook it does not give any error, it hangs on reading data.
