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

Basic WebUSB support (mobile) #29

Merged

Conversation

slimonslimon
Copy link
Contributor

WebUSB api will be used as fallback API when WebSerial api is not available. It uses bundled javascript WebUSB FTDI Driver v0.01a from: https://github.com/pmp-p/webusb-ftdi/blob/master/webusb-ftdi.js

Write support with WebUSB is now disabled - need test.
Write support with WebSerial is not tested. I need secondary usb-to-serial, to check if it works.

WebUSB api will be used as fallback API when WebSerial api is not available.
It uses bundled javascript WebUSB FTDI Driver v0.01a from: https://github.com/pmp-p/webusb-ftdi/blob/master/webusb-ftdi.js

Write support is now disabled - need test.
@slimonslimon
Copy link
Contributor Author

FIY @kaklik

@NuclearPhoenixx
Copy link
Member

NuclearPhoenixx commented Feb 9, 2023

Please create the pull request for the dev branch not main. Thanks!

EDIT: Nevermind, I can do that too.

@NuclearPhoenixx NuclearPhoenixx changed the base branch from main to dev February 9, 2023 11:29
@NuclearPhoenixx NuclearPhoenixx self-assigned this Feb 9, 2023
@NuclearPhoenixx NuclearPhoenixx added the enhancement New feature or request label Feb 9, 2023
@NuclearPhoenixx
Copy link
Member

Did some changes to the code over at your fork: UniversalScientificTechnologies#2

Please merge and I'll have a look at it once again. Then I'll probably merge as well. The Web Serial stuff all still works, so if the Web USB works on your end, great job!

Copy link
Member

@NuclearPhoenixx NuclearPhoenixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NuclearPhoenixx NuclearPhoenixx changed the title basic WebUSB suport Basic WebUSB support Feb 9, 2023
@NuclearPhoenixx NuclearPhoenixx changed the title Basic WebUSB support Basic WebUSB support (mobile) Feb 9, 2023
source/serial.ts Outdated Show resolved Hide resolved
source/serial.ts Outdated Show resolved Hide resolved
Copy link
Member

@NuclearPhoenixx NuclearPhoenixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let me know once WebUSB works for you and I'll test WebSerial again.

@slimonslimon
Copy link
Contributor Author

Fix WebSerial Write means Fix WebUSB Write... sorry

@slimonslimon
Copy link
Contributor Author

I tested folowing setups using two USBToSerial devices:

PC terminal <-> PC OpenMCA (WebSerial)
PC terminal <-> PC OpenMCA (WebUSB - using modified main.ts - disable WebSerial)
PC terminal <-> Android OpenMCA (WebUSB)
PC OpenMCA (WebSerial) <-> Android OpenMCA(WebUSB)

@NuclearPhoenixx
Copy link
Member

And did everything work?

@slimonslimon
Copy link
Contributor Author

In my opinion yes.

But there are two things to discuse:

  • Send function consumes string, read functiuon produce Uint8Array - it's okey?
  • Send function add '\n'. as End of Line, but parser of incoming data expected '\r\n' as End of Line

@NuclearPhoenixx
Copy link
Member

Send function consumes string, read functiuon produce Uint8Array - it's okey?

Think that's fine. The only thing that's important is that both WebSerial and WebUSBSerial return the same type. The remaining conversion to strings is the same for both, so the SerialManager can handle that.

Send function add '\n'. as End of Line, but parser of incoming data expected '\r\n' as End of Line

I think it would actually be better to remove the \r from the EOL. It just needs to use \n actually. I'll need to have a look at the serial data reduction to catch cases where either \r\n and \n are received. I'll do that once this PR is finished. (Some whitespace trimming fun)

Copy link
Contributor Author

@slimonslimon slimonslimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shut i press this? (PR was accepted before)

@slimonslimon
Copy link
Contributor Author

I still see changes requesed, but i think that I accept all all changes by your PR...

@NuclearPhoenixx
Copy link
Member

Yeah, don't worry. Nice job.

@NuclearPhoenixx NuclearPhoenixx merged commit bad44bc into OpenGammaProject:dev Feb 10, 2023
@NuclearPhoenixx
Copy link
Member

@slimonslimon Can you please give the current dev branch another try with some WebUSB clients? I actually don't have any FTDI serial devices here, so can't test it unfortunately.

Had to fix some problems when multiple devices were connected and/or disconnected at the same time while recording. I haven't touched the WebUSBSerial class much, but just to be sure that the checks in main.ts didn't break something.

When this is working I will push the current dev branch to main, create a version tag and the new feature will be public.

@slimonslimon
Copy link
Contributor Author

Im sorry but, current dev doesnt work properly with WebUSBSerial.

First think i found: comment this line:
https://github.com/OpenGammaProject/Gamma-MCA/blob/dev/source/serial.ts#L34
cause that it makes infinite loop without "await", so javascript cannot do any other "task" than this. (As far as I understand javascript) (when device not sending data - our device sends data about 1time per 10 seconds)

But i stil doesnt work when i remove comment, and I dont see other problem directly.

@NuclearPhoenixx
Copy link
Member

cause that it makes infinite loop without "await", so javascript cannot do any other "task" than this. (As far as I understand javascript) (when device not sending data - our device sends data about 1time per 10 seconds)

Okay I see. That's something different with WebSerial then. Because WebSerial works without any delays. I will uncomment your delay in WebUSBSerial.

Is it more of a problem with finding and selecting the right port, or is there an issue with the recording on your end?

@slimonslimon
Copy link
Contributor Author

The issue was between keyboard and chair....

When I want use (for dev purpose) the WebUSB on PC (where chromium has debug menus), I should remove kernel module whose block the usb device... I forget this...

@NuclearPhoenixx
Copy link
Member

Ok cool, thanks for testing! Will bump it to main then (with the uncommented line from above).

@slimonslimon
Copy link
Contributor Author

Well... I tested it with two devices and PC with blocked WEBSerial API (one is USB2Serial which dont have opposite connection now, and second is LabDOS which produces data). When I have open GammaMCA-console with LABDOS and remove USB2Serial from USB, console keep recieving data.

GammaMCA.console works on Android.

So I thing you can publis it, because Im not able to setup more complicated experiment now. I will test it deeper on next week, if it is needed.

@NuclearPhoenixx
Copy link
Member

Yeah, all the WebSerial things still work just fine. So if at least something works for now (even rudimentary) with WebUSB, then it's a clear win. We can check more complicated scenarios in the future anyways.

@NuclearPhoenixx
Copy link
Member

Just tested it with a random, new USB UART converter and made some minor adjustments to the filter so that it accepts any FTDI chip, not only one productId. Works great now, tested with an Arduino Uno as a dummy, even the console shows fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants