#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    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!
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    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?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep 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.
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Thanks!


    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!

IMN logo majestic logo threadwatch logo seochat tools logo