librelist archives

« back to archive

Flask + hid module conflict

Flask + hid module conflict

From:
Jon Christopher
Date:
2015-02-24 @ 20:01
I'm running into an odd situation where I have a script which uses the hid
module https://pypi.python.org/pypi/hidapi/0.7.99-5, which is a wrapper
around the hidapi library from https://github.com/signal11/hidapi.

If I import flask and hid, everything works fine, and I can open hid
devices until/unless app.run is called.  If I do that, I get an IOError
trying to open the HID device.

The most likely explanation seems to be a permissions issue.  Does running
flask do something to the permissions level of the script?  Where could I
find documentation about that.

My script is below.  As written, it'll connect to the hid device and print
the value of the distance sensor.  If instead I uncomment out the app.run
line (enabling flask), then I get an IOException trying to initialize the
HID device.

Any hints would be appreciated.

Thanks,
Jon

---



from flask import Flask,request
import wedo  # uses the hid library
app = Flask(__name__)

def sendReject():
    while w.distance<12.5:
        print w.distance
        w.motor_a=100

@app.route('/reject')
def hello():
    sendReject()

if __name__ == '__main__':
    w=wedo.WeDo()
    sendReject()
    #app.run(host='0.0.0.0',port=20000,debug=True)

Flask + hid module conflict

From:
Jon Christopher
Date:
2015-02-26 @ 18:51
I'm running into an odd situation where I have a script which uses the hid
module https://pypi.python.org/pypi/hidapi/0.7.99-5, which is a wrapper 
around the hidapi library from https://github.com/signal11/hidapi.

If I import flask and hid, everything works fine, and I can open hid 
devices until/unless app.run is called.  If I do that, I get an IOError 
trying to open the HID device.

The most likely explanation seems to be a permissions issue.  Does running
flask do something to the permissions level of the script?  Where could I 
find documentation about that.

My script is below.  As written, it'll connect to the hid device and print
the value of the distance sensor.  If instead I uncomment out the app.run 
line (enabling flask), then I get an IOException trying to initialize the 
HID device.

Any hints would be appreciated.

Thanks,
Jon

---



from flask import Flask,request
import wedo  # uses the hid library
app = Flask(__name__)

def sendReject():
    while w.distance<12.5:
        print w.distance
        w.motor_a=100

@app.route('/reject')
def hello():
    sendReject()

if __name__ == '__main__':
    w=wedo.WeDo()
    sendReject()
    #app.run(host='0.0.0.0',port=20000,debug=True) 

Re: [flask] Flask + hid module conflict

From:
Dorian Hoxha
Date:
2015-02-27 @ 10:46
Try running the hid-thing in another thread ?

On Thu, Feb 26, 2015 at 7:51 PM, Jon Christopher <jon.christopher@gmail.com>
wrote:

>
> I'm running into an odd situation where I have a script which uses the hid
> module https://pypi.python.org/pypi/hidapi/0.7.99-5, which is a wrapper
> around the hidapi library from https://github.com/signal11/hidapi.
>
> If I import flask and hid, everything works fine, and I can open hid
> devices until/unless app.run is called.  If I do that, I get an IOError
> trying to open the HID device.
>
> The most likely explanation seems to be a permissions issue.  Does running
> flask do something to the permissions level of the script?  Where could I
> find documentation about that.
>
> My script is below.  As written, it'll connect to the hid device and print
> the value of the distance sensor.  If instead I uncomment out the app.run
> line (enabling flask), then I get an IOException trying to initialize the
> HID device.
>
> Any hints would be appreciated.
>
> Thanks,
> Jon
>
> ---
>
>
>
> from flask import Flask,request
> import wedo  # uses the hid library
> app = Flask(__name__)
>
> def sendReject():
>     while w.distance<12.5:
>         print w.dista nce
>         w.motor_a=100
>
> @app.route('/reject')
> def hello():
>     sendReject()
>
> if __name__ == '__main__':
>     w=wedo.WeDo()
>     sendReject()
>     #app.run(host='0.0.0.0',port=20000,debug=True)
>