[Bf-python] Polling a device in Bpy?

Toni Alatalo antont at kyperjokki.fi
Wed Jun 17 09:36:38 CEST 2009


On Jun 17, 2009, at 10:30 AM, Florian Lier wrote:

>  I need to know if its possible to poll a device constantly in a  
> py-script like this

yes, polling works like it normally does. so you can e.g. use select()  
to read from a socket in a non-blocking manner, or use some python  
module that gives polling access to your device.

the question is how you need to execute the code. if it's ok for the  
script to stay running all the time, then you're fine. if you'd like it  
to have it like a scriptlink, i.e. just in the scene and not running  
otherwise, there is currently no 'always' scriptlink that would run  
periodically. 2.5 should solve this too with the new event internals.

~Toni


>
>  pseudo code
>  ----------------------------------------------
>  if button1 state = "down":
>       
> poll.mydevice(cube.setLocation(mydevice.valA,mydevice.valB,mydevice.val 
> C))
>      Blender.Redraw()
>  else
>      print "No data avail"
>  ----------------------------------------------
>
>  Is there another apporach? Like looping parts of the script?
>  The problem is, functions like while(true) or for x in  
> range(10000000): sleep(0.5)
>  freezing the script, thus Blender too.
>
>  Thank you, cheers Florian
>
>
>
>
>  _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python




More information about the Bf-python mailing list