Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM library via libusb, expand to a monorepo, libsigrok bindings #697

Open
orangecms opened this issue Jan 29, 2022 · 6 comments
Open

WASM library via libusb, expand to a monorepo, libsigrok bindings #697

orangecms opened this issue Jan 29, 2022 · 6 comments

Comments

@orangecms
Copy link
Collaborator

orangecms commented Jan 29, 2022

Current State

Currently, the app is set up to depend on the pslab-python library. However, that is usually hard for end users to set up.

Now we have a WIP implementation to support PSLab in libsigrok, and besides using that in Sigrok's PulseView, we can also use it here in the PSLab Desktop App.

Next Step

The first step is to create bindings for Node.js using Node-API, then set up the IPC stack to forward data to and send requests from the Electron windows. With a monorepo (pulling in libsigrok as a git submodule), it becomes simpler to set up everything. Then we can gradually expand, and even provide a UI for other instruments etc supported by Sigrok.

@orangecms
Copy link
Collaborator Author

Even nicer would be to wrap libsigrok in WebAssembly, so that we can reuse it for a second build that can be used on the web directly, say, web.pslab.io.

For a related example, see:
https://github.com/GoogleChromeLabs/web-gphoto2

@orangecms orangecms changed the title Expand to a monorepo, libsigrok bindings WASM library via libusb, expand to a monorepo, libsigrok bindings Mar 26, 2022
@orangecms
Copy link
Collaborator Author

I've forked @rreverse's libusb fork again: https://github.com/orangecms/libusb

Built it like this with Emscripten:

#!/bin/sh

./autogen.sh
 # emconfigure add things like --host=wasm32
emconfigure ./configure
emmake make

and got some output:

make  all-recursive
make[1]: Entering directory '/home/dama/Projects/FOSSASIA/PSLab/libusb'
Making all in libusb
make[2]: Entering directory '/home/dama/Projects/FOSSASIA/PSLab/libusb/libusb'
  CC       core.lo
  CC       descriptor.lo
  CC       hotplug.lo
  CC       io.lo
  CC       strerror.lo
  CC       sync.lo
  CC       os/events_posix.lo
  CC       os/threads_posix.lo
  CC       os/linux_usbfs.lo
  CC       os/linux_udev.lo
  CXXLD    libusb-1.0.la
make[2]: Leaving directory '/home/dama/Projects/FOSSASIA/PSLab/libusb/libusb'
Making all in examples
make[2]: Entering directory '/home/dama/Projects/FOSSASIA/PSLab/libusb/examples'
  CC       dpfp.o
  CCLD     dpfp
  CC       dpfp_threaded-dpfp.o
  CCLD     dpfp_threaded
  CC       ezusb.o
  CC       fxload.o
  CCLD     fxload
  CC       hotplugtest.o
  CCLD     hotplugtest
  CC       listdevs.o
  CCLD     listdevs
  CC       sam3u_benchmark.o
  CCLD     sam3u_benchmark
  CC       testlibusb.o
  CCLD     testlibusb
  CC       xusb.o
  CCLD     xusb
make[2]: Leaving directory '/home/dama/Projects/FOSSASIA/PSLab/libusb/examples'
Making all in tests
make[2]: Entering directory '/home/dama/Projects/FOSSASIA/PSLab/libusb/tests'
  CC       stress.o
  CC       testlib.o
  CCLD     stress
make[2]: Leaving directory '/home/dama/Projects/FOSSASIA/PSLab/libusb/tests'
make[2]: Entering directory '/home/dama/Projects/FOSSASIA/PSLab/libusb'
make[2]: Leaving directory '/home/dama/Projects/FOSSASIA/PSLab/libusb'
make[1]: Leaving directory '/home/dama/Projects/FOSSASIA/PSLab/libusb'

will see where that takes us :)

@orangecms
Copy link
Collaborator Author

Note: There is also https://wicg.github.io/serial/ WebSerial, but it would be less portable to build on top of that.

@normanr
Copy link

normanr commented Apr 9, 2022

Note that browsers typically don't allow access to devices via multiple APIs, eg if a USB device supports HID then it's accessible via WebHID and not WebUSB (same for audio/storage/video/wifi etc). I expect that (probably eventually) WebUSB will not allow access for serial devices.

For serial devices (that use serial_open) you probably want to use WebSerial, for usb devices (that use libusb_open) you probably want to use WebUSB. For HID devices you'll probably have to use WebHID. SCPI device s you probably have to use WebSerial or WebUSB (depending on the transport). For TCP devices, you might be able to use Direct Sockets API (when it becomes available), otherwise Websockets with something like websockify.

@orangecms
Copy link
Collaborator Author

Yea, good points! There's multiple ways for us to integrate; I've done some more research and put together a presentation I'm giving at FOSSASIA Summit in about an hour @normanr

Slides are here: https://metaspora.org/pslab-goes-native-goes-web.pdf

Also, related PR regarding libusb: libusb/libusb#1057

@orangecms
Copy link
Collaborator Author

There’s a Pyodide JavaScript module:
https://www.npmjs.com/package/pyodide

It can simply spawn Python like we already do in the desktop app, but without the need for the extra module maintaining background tasks. 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants