How can I work with pyserial and django form?

1,868 views
Skip to first unread message

José Jesús Palacios

unread,
Apr 5, 2015, 5:48:49 PM4/5/15
to django...@googlegroups.com
How can I work with pyserial and django form to read from serial to <input> field?
Is it possible?

Thanks to everyone.

Vijay Khemlani

unread,
Apr 5, 2015, 5:55:02 PM4/5/15
to django...@googlegroups.com
What are you trying to do exactly?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa063945-c98d-488f-ba0f-16d66809395e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Jesús Palacios

unread,
Apr 6, 2015, 8:42:56 PM4/6/15
to django...@googlegroups.com
I'm trying read serial to put in a field on a form and submit to database. Data can be a weight of weighbridge, number of  car plate or reading a barcode.
Outside the browser, It's not problem, but I want to use it as user interface.

Vijay Khemlani

unread,
Apr 7, 2015, 12:36:54 AM4/7/15
to django...@googlegroups.com
I'm still not sure whether you are trying to load the value in the form input from the server or from the browser of the client.

Bill Freeman

unread,
Apr 7, 2015, 2:56:59 PM4/7/15
to django-users
It sounds as though you have a set of sensors (scales, license readers, barcode readers) which provide their readings over asynchronous serial (that's what pyserial can connect with).  You have some computer or set of computers that collectively provide a sufficient number of serial ports to interface to your set of sensors.

And I believe you are wondering how to use a browser (Firefox, Chrome, Safari, IE) to read from the serial ports and post the data to Django.  You might be able to write a Firefox extension that does this, but it would be a lot of work, and sensitive to updates to the browser.

If I had the task of reading the sensors and sending the data to Django, I would write a small python program using pyserial and requests (or if you are a glutton for punishment, use urllib2 directly) to POST to your Django instance, using rest or an ad hoc protocol.  You can POST to a form page, but the fact that forms are designed to appear to humans will just make things a bit harder.

If you need a GUI to control the program you could add one with wxPython (or other alternatives) or you could run a simple web server (python comes with on) in a separate thread.

If the serial ports are run on the same box as Django or on a box that can access the same database as Django is using, you could do the process as a custom Django management command that uses pyserial to talk to the ports and stores the results in the database directly.  GUI based control could be via an extra table in the database controlled by an extra Django page.

There are other possibilities.  But trying to get a browser involved sounds like a recipe for frustration.

Or maybe I misunderstand your needs?

José Jesús Palacios

unread,
Apr 8, 2015, 10:05:32 AM4/8/15
to django...@googlegroups.com
Ok, thanks guys. I'll answer myself.
At the moment I am more focused on the problem. I think it's an off-topic here. In short, the problem should be solved at the client side, not on the server side. Node.js can handle this with node-serialport and Garrows has a development one step further: https://github.com/garrows/browser-serialport, "... works in Chrome App Packaged as this is the only way to get access to the serial ports API in the browser ".
A Few years ago, Nicholas Zambetti developed seriallity as a browser-plugin, http://www.zambetti.com/projects/seriality/

So I will learn a little more, try and maybe I will move the question to another forum more involved.

Many thanks to everyone, once more.
Reply all
Reply to author
Forward
0 new messages