JavaScript/JQuery communicate with SerialPort/COM1

后端 未结 4 1505
情书的邮戳
情书的邮戳 2020-12-28 23:11

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 po

4条回答
  •  情书的邮戳
    2020-12-28 23:53

    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.

提交回复
热议问题