I am currently trying to open a COM port with Deno. This works so far and I can read the data with
file.read(buffer)
.
The only problem now is that if there is no more data in the COM port and I try to read the data with file.read(buffer)
, Deno stops at that point.
How can I tell if there is no more data in the COM port?
This is my current class:
export class COM {
constructor(COMPort : number) {
this.COMPort = COMPort
}
async open() : Promise<void> {
this.#file = await Deno.open(`\\\.\\COM${this.COMPort}`, {read: true, write: true})
}
close() : void {
this.#file.close()
}
async #_readChar(readBuffer : Uint8Array) : Promise<Uint8Array> {
await this.#file.read(readBuffer)
return readBuffer
}
async readChar(chars : number) : Promise<Uint8Array> {
return await this.#_readChar(new Uint8Array(chars))
}
}
this is my main file:
const com = new COM(4)
await com.open()
while (true) {
result = await com.readChar(1)
console.log(result, decoder.decode(result))
if (result == /* ??? empty ??? */) {
break
}
}