7

is it possible to force any communication from e.g. Javascript/JQuery to any serial comport?!

google is not able to answer that question.. but anyway it should be possible.. env is firefox in my case..

ideas/knowledge is very welcome.

kindly tape

Alex Tape
  • 2,291
  • 4
  • 26
  • 36
  • _"but anyway it should be possible"_ - Why should it be possible? As a general rule, JavaScript running in the browser can't access anything outside the browser. This is a deliberate security feature. Are you talking about providing this com feature on a public web page (where you can't control what browser the user might have), or are you talking only about FF, or...? – nnnnnn Aug 22 '13 at 12:05
  • you are completly right - i know that.. but maybe it is possible to force it via about:config or whatever.. i´m talking about a desktop solution, no (public) internet and ONLY for firefox usage! i have to solve that problem.. if it is not possible i have to install a simple server on the client and grab the port via ajax - thats the fallback.. – Alex Tape Aug 22 '13 at 12:14

5 Answers5

8

I think it is possible..

Look to: jUART, Cross platform browser plugin for serial port communication from JavaScript https://github.com/billhsu/jUART

kimstik
  • 1,611
  • 2
  • 15
  • 14
5

with chrome it's possible ,

here is the link for documentations : https://developer.chrome.com/apps/app_serial

or

http://www.fabiobiondi.com/blog/2014/02/html5-chrome-packaged-apps-and-arduino-bidirectional-communication-via-serial/

Mimouni
  • 3,564
  • 3
  • 28
  • 37
  • Chrome has moved away from supporting Chrome apps in anything other than ChromeOS according to [this blog post](https://blog.chromium.org/2016/08/from-chrome-apps-to-web.html). – JIntro Aug 11 '17 at 18:59
4

Yes you can, but not with a typical browser. Browsers are sandboxed to not have access to the local file system (except cookies) so that malicious sites can't read from / write to your hard drive. As far as I know there is no way to override this behvior (short of writing your own browser).

However, this can be done in JavaScript using Node.js. It runs as a process rather than in a browser window and can access the file system. Specifically, there is already an npm module (node library) for serial communication: https://github.com/voodootikigod/node-serialport

Alternatively, you could always just spin up a local web server (via node.js, php, rails, etc). Web servers can access file systems, and therefore should be able to access serial ports.

Hope this helps.

markle976
  • 957
  • 1
  • 6
  • 10
1

kimstik's suggestion, using the jUART plugin for the browser is an excellent solution.

Another possibility is to use a middleware, that facilitates the serial communication and provides a web interface, that JavaScript can interface with using AJAX requests.

Python could be used, e.g. a script using a combination of pySerial and python-bobo.

Matthias
  • 21
  • 2
  • 1
    Update on this: Sept 15, 2015 Chrome will no longer support the NPAPI and the solution will Likely no longer work. [see here](https://support.google.com/chrome/answer/6213033?hl=en) – nerdwaller Sep 01 '15 at 16:07
1

Update to this thread, if you are using chrome you may use Web Serial to communicate using web to serial port.

https://chromestatus.com/feature/6577673212002304
https://web.dev/serial/

espongha
  • 225
  • 1
  • 13