3

I assumed this would not be possible, but after reading this post thought that perhaps it might be:

How can I send data from a web page to a serial port?

So I added my code for serial as below and just hoped some sort of magic would occur:

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

As expected though, I got an error:

[Mon Aug 01 07:01:44.513340 2016] [wsgi:error] [pid 16:tid 140515737831488]     raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))
[Mon Aug 01 07:01:44.513367 2016] [wsgi:error] [pid 16:tid 140515737831488] SerialException: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'

The code is working fine locally and the online environment mimics the modules available locally through requirements.txt.

Community
  • 1
  • 1
user1063287
  • 10,265
  • 25
  • 122
  • 218
  • 1
    It sounds like you are trying to open port from server side. To achieve your goal I'd suggest to look for client side tools. There is a bunch of js solutions i.e http://stackoverflow.com/questions/5640953/serial-communication-from-javascript – vsminkov Aug 08 '16 at 06:38

1 Answers1

0

Not directly what you want to hear. But the answer is no. You cannot use pySerial remotely unless you your webservice running locally on target computer.

But anyway you can still achieve your goal by using one of following approaches (in order of complexity for client):

  1. Java applet or Java Web Start application (for example there is a good cross-platform library RXTX)
  2. Browser plugins such as jUART, browser-serialport or serial for google chrome or even ActiveX component
  3. Serial port to network proxy (like ser2net).

The only problem is that your clients will still need to do additional steps in order to your site could properly work (install java/native library/allow applet/browser plugin or additional software). The reason for that is because browsers are very restrictive and by default all filesystem operations are sandboxed by default for security reasons.

vsminkov
  • 10,912
  • 2
  • 38
  • 50
  • If possible, can you please provide a detailed solution that answers bounty's request and is cross platform/browser? jUART is no longer maintained as a cross platform solution due to changes in chrome extension requirements. Not sure if general reference to Java applet is a good match for a 200 point bounty? – user1063287 Aug 13 '16 at 07:25
  • 1
    @user1063287 there is a lot examples on how you can make an java applet with serial port access. For example there is an [howto](https://blog.mornati.net/javaapplet-used-to-print-over-serial-port/) of [rxtx](https://github.com/rxtx/rxtx) library usage. However you still have to ensure your clients have proper environment in order to make things work. If you are making service for some kind of pos terminals where you can contol software then your goal is achievable. Could you tell a bit more about your project? – vsminkov Aug 13 '16 at 09:28
  • It is just a standard website, running on Python (with HTML, CSS and jQuery). When running the site locally, I can send an RGB value from the jQuery frontend to a route in Python which passes the values to pyserial which sends them to an Arduino. You can see specific details in this question which explores the jUART option (which is no longer maintained or working correctly): http://stackoverflow.com/questions/38841959/how-to-replicate-pyserial-sending-rgb-values-to-arduino-in-juart – user1063287 Aug 13 '16 at 09:40
  • @user1063287 aha. got it. well... there is still not so many options :( the problem is browser security. java applet is still requre native libraries to be loaded. other solution is to build browser plugin (which I guess not what you want). there is also a javaws solution which a bit easier but still requires additioal steps from user – vsminkov Aug 13 '16 at 11:23
  • @user1063287 I've added a couple of alternatives to my answer. But I think that most reliable way is still javaws – vsminkov Aug 13 '16 at 18:14