The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP5 - Controling a python console from php?
Discuss Controling a python console from php? in the PHP Development forum on Dev Shed. Controling a python console from php? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 7th, 2013, 08:09 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
Time spent in forums: 43 m 51 sec
Reputation Power: 0
|
|
|
PHP5 - Controling a python console from php?
I am trying to write a single user, intranet only PHP control panel for my 3d printer using pronterface's pronsole.py interface - it is just a command line, takes commands from stdin, writes to stdout. I thought to use proc_open, but then if the user closes the page, I would have to terminate the process(not what the user wants) OR leave it running and loose the i/o streams(not desirable because then I cant allow the user to regain control). Sessions are not an option because this site will only allow one job at a time due to hardware limitations, and i would like it to be controllable from any computer. I don't know if PHP likes to read/write file pointers to databases or files, but I assume not. What is the best way to do this? Should i just give up on using pronsole and write my own logic that writes to /dev/ttyUSB0? Thanks for help with this vexing problem!
|

January 7th, 2013, 09:06 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Well it's just a Python script. Does it do anything unusual or cryptic or something that would be a hassle to rewrite in PHP?
And so what if the connection closes. Can't you just reconnect?
|

January 7th, 2013, 09:14 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
Time spent in forums: 43 m 51 sec
Reputation Power: 0
|
|
|
I don't think a rewrite in PHP would be that hard, and it might be required because now that I think about it,reconnecting resets the printer. I actually don't know much about linux device files, but I'm assuming it's possible to write to them discontinuously (if thats the right way to say it), so a rewrite in PHP is probably the way to go, especially for expandability. I was just wondering if there was was simple solution.
|

January 7th, 2013, 10:26 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
Depends on the device. If you don't need to adjust port information (baud and the like), or in other words don't need an ioctl() on it, then you can work on the device file just like it were a regular file.
Regardless it sounds like you'll need some kind of spooler: sits in the background waiting for stuff to do. You can't serialize file handles which means you can't put it in a database or save it in the session. And without being particularly careful you can't open it in one script and close it in another either.
|

January 7th, 2013, 11:09 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
Time spent in forums: 43 m 51 sec
Reputation Power: 0
|
|
|
Thanks!
Quote: | Originally Posted by requinix Depends on the device. If you don't need to adjust port information (baud and the like), or in other words don't need an ioctl() on it, then you can work on the device file just like it were a regular file.
Regardless it sounds like you'll need some kind of spooler: sits in the background waiting for stuff to do. You can't serialize file handles which means you can't put it in a database or save it in the session. And without being particularly careful you can't open it in one script and close it in another either. |
I will probably write a spooler, the thought of just how easy it could be(I could even integrate it into the python script) just crossed by mind and made this seem like a viable option. Thanks a ton!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|