i have the following code to receive serial data from arduino and rotate the cube...
import bpy
from bpy import context
import serial
from time import sleep
from bpy.props import IntProperty, FloatProperty
value = 0
i=0
j=0
degree = 0
ser = serial.Serial("COM77", 9600)
class ModalOperator(bpy.types.Operator):
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
x = IntProperty()
def modal(self, context, event):
if ser.inWaiting()>0 :
value = ser.read(2)
print(value)
self.x = int(value)
print(self.x)
self.x += 1000
degree = self.x * 3.14/180
print(degree)
bpy.context.object.rotation_euler[0] = degree
if event.type == 'LEFTMOUSE':
return {'FINISHED'}
ser.close()
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.object:
print("hi")
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "No active object, could not finish")
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)
register()
# test call
bpy.ops.object.modal_operator('INVOKE_DEFAULT')
the code under invoke function executes immediately when i run the script..but the statements under modal function executes only if i move the mouse or press any key...
I think it doesn't consider incoming serial data as an event...
i want the serial data to be read as and wen it comes...not only wen the mouse is moved..
Is there any way to check serial event.... like 'MOUSE_MOVE' or 'LEFTMOUSE'....