I'm doing a project in Angular and I need to make the connection to a scale through the serial input (data input and output). I'm using the serialPort web API.
I have already enabled the experimental web platform features of my browser. Chrome version is 86.0.4240.198.
My system is showing the available entries. However, when I do an .open, it cannot make the connection.
This is my code:
...
reader: ReadableStreamDefaultReader;
writer: WritableStreamDefaultWriter;
encoder = new TextEncoder();
decoder = new TextDecoder();
...
async init() {
if ('serial' in navigator) {
try {
const port = await (navigator as any).serial.requestPort();
await console.log(port)
await port.open({ baudrate: 4800 });
this.reader = port.readable.getReader();
this.writer = port.writable.getWriter();
this.verificacao = true;
} catch(err) {
console.error('There was an error opening the serial port:', err);
this.verificacao = false;
}
} else {
console.error('Web serial doesn\'t seem to be enabled in your browser. Try enabling it by visiting:')
console.error('chrome://flags/#enable-experimental-web-platform-features');
console.error('opera://flags/#enable-experimental-web-platform-features');
console.error('edge://flags/#enable-experimental-web-platform-features');
}
}
...
I can identify the serial input:
But this error happens:
Failed to execute 'open' on 'SerialPort': required member baudRate is undefined.
When selecting the serial input, the port variable returns: