deno_serial icon indicating copy to clipboard operation
deno_serial copied to clipboard

Cannot print serial ports on Windows 10

Open fvilante opened this issue 1 year ago • 11 comments

Maybe I'm doing something wrong, but I could not make the example to work on Windows 10.

Here is the reproduction of the error:


╰─❯ deno upgrade

Looking up latest version
Found latest version 1.34.1
Downloading https://github.com/denoland/deno/releases/download/v1.34.1/deno-x86_64-pc-windows-msvc.zip
Deno is upgrading to version 1.34.1
Upgraded successfully
Release notes: https://github.com/denoland/deno/releases/tag/v1.34.1
Blog post: https://deno.com/blog/v1.34

╰─❯ git clone https://github.com/DjDeveloperr/deno_serial.git

Cloning into 'deno_serial'...
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (59/59), done.
Receiving objects:  58% (45/77)used 60 (delta 13), pack-reused 0
Receiving objects: 100% (77/77), 29.87 KiB | 2.99 MiB/s, done.
Resolving deltas: 100% (23/23), done.

╰─❯ cd .\deno_serial\examples\

╰─❯ deno run .\print_ports.ts

error: Uncaught TypeError: Deno.dlopen is not a function
export default Deno.dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", {
                    ^
    at file:///C:/TEMP/deno_study/deno_serial/src/darwin/iokit.ts:5:21
    
        
╰─❯ deno --version

deno 1.34.1 (release, x86_64-pc-windows-msvc)
v8 11.5.150.2
typescript 5.0.4

╰─❯ $PSVersionTable.OS

Microsoft Windows 10.0.19045

PS: I apologize. for not answering your former ask for PR, I did not saw your message. My fault.

related #2

fvilante avatar Jun 02 '23 04:06 fvilante

Sorry, I pushed some unfinished macOS platform code which is causing this error. I'll update it after work today.

DjDeveloperr avatar Jun 02 '23 06:06 DjDeveloperr

I have some equipment here to connect on the serial, so we can perform an field test on the lib.

fvilante avatar Jun 02 '23 16:06 fvilante

I've cleaned up some unfinished stuff. Windows backend should work now.

DjDeveloperr avatar Jun 02 '23 17:06 DjDeveloperr

Not working yet, but the error message changed which is good.

╰─❯ deno run --unstable --allow-ffi print_ports.ts
error: Uncaught TypeError: Cannot convert object to primitive value
    return Number(Deno.UnsafePointer.of(v));
           ^
    at Number (<anonymous>)
    at Module.toPointer (https://raw.githubusercontent.com/DjDeveloperr/deno_win32/18563d7/util.ts:7:12)
    at Module.SetupDiClassGuidsFromNameA (https://win32.deno.dev/18563d7/Devices.DeviceAndDriverInstallation:17811:102)
    at SetupDiClassGuidsFromNameA (file:///C:/TEMP/deno_study/deno_serial/src/windows/enumerate.ts:74:21)
    at getPortsWin (file:///C:/TEMP/deno_study/deno_serial/src/windows/enumerate.ts:118:19)
    at getPorts (file:///C:/TEMP/deno_study/deno_serial/src/serial_port.ts:7:12)
    at file:///C:/TEMP/deno_study/deno_serial/examples/print_ports.ts:3:15

fvilante avatar Jun 02 '23 21:06 fvilante

Oh right, I need to update the Windows API bindings - seems like a Deno FFI update broke them

DjDeveloperr avatar Jun 03 '23 04:06 DjDeveloperr

I've updated win32 version, try now!

DjDeveloperr avatar Jun 03 '23 04:06 DjDeveloperr

Not yet, but less errors than before.

╰─❯ deno run --unstable --allow-ffi print_ports.ts

error: Uncaught TypeError: Cannot convert object to primitive value
    unwrap(Number(devInfoList));
           ^
    at Number (<anonymous>)
    at getPortsWin (file:///C:/TEMP/deno_study/deno_serial/src/windows/enumerate.ts:126:12)
    at getPorts (file:///C:/TEMP/deno_study/deno_serial/src/serial_port.ts:7:12)
    at file:///C:/TEMP/deno_study/deno_serial/examples/print_ports.ts:3:15

fvilante avatar Jun 03 '23 06:06 fvilante

Pushed a fix again

DjDeveloperr avatar Jun 03 '23 07:06 DjDeveloperr

I have 3 serial ports currently. I can see them through the windows device manager app.

But the lib cannot identify it.

╰─❯ deno run --unstable --allow-ffi print_ports.ts
No serial ports found.

Do you have a windows machine ?

fvilante avatar Jun 03 '23 10:06 fvilante

I only recently switched to a Mac, but I can test on my old Windows machine later.

Today I also explored using the Rust crate tokio-serial for implementing Web Serial API in Deno itself, and it works pretty flawlessly. Trying to implement Serial API only using system libraries via FFI is getting unnecessarily complicated because of the less control over threading in non-blocking calls and some other factors.

The best option seems to be implementing it in Rust and exposing a higher-level interface to Deno via FFI, or simply just implementing this API (since it is a web standard) and PR'ing it to Deno, which honestly sounds great. I'll give it some more time and finish my implementation to integrate Web Serial API into Deno!

DjDeveloperr avatar Jun 04 '23 17:06 DjDeveloperr

related https://github.com/denoland/deno/issues/9710

fvilante avatar Jun 04 '23 23:06 fvilante