Hi Testing,

I'm not familiar with callbacks, and can't tell quite what your code
is trying to do, but I successfully got Maya reading arduino input
using the code I posted here:

http://zoomy.net/2009/08/01/arduino-to-maya-mocap-ii/

It looks like you're trying to connect arduino output to a node input?
Sounds chancy. I'd be very interested to see if you get this working
though.

Hope this helps,
Peter

On Mar 21, 6:31 pm, testing123 <[email protected]> wrote:
> Ok so I know its been asked a few times on here, but I could find
> anyone that came to a conclusion.   I was also trying to get external
> device input, this time over an Arduino, which means that it simply
> reads the value over the serial port.  In my test example below its
> only sending one value.
>
> things work up to a point, but I can't get my TimerCallback message to
> work- I keep getting an error when i try to load it.  If someone could
> take a look and give me an idea where I've gone wrong I would
> appreciate it.
>
> ......heres the code
>
> import maya.OpenMaya as om
> import maya.OpenMayaMPx as omMPx
> import serial
>
> #Set name and id
> nodeName = "ardServer"
> nodeId = om.MTypeId(0x998112)
>
> #set the serial port / baudrate
> ser1 = serial.Serial('/dev/tty.usbserial-A600ahtY',9600)
>
> class ardNode(omMPx.MPxNode):
>     # input and output variables
>
>     OUTPUT = om.MObject()
>
>     def __init__(self):
>         omMPx.MPxNode.__init__(self)
>
> def nodeCreator():
>
>     return omMPx.asMPxPtr( ardNode() )
>
> def nodeInit():
>
> #create the attribute
>     numAttr = om.MFnNumericAttribute()
>     ardNode.OUTPUT =
> numAttr.create("sensor0","s0",om.MFnNumericData.kInt,0)
>     numAttr.setStorable(1)
>     numAttr.setWritable(1)
>
>     ardNode.addAttribute(ardNode.OUTPUT)
>
> #create the callback
>     nodeHdl = om.MObjectHandle(ardNode)
>     cb = om.MTimerMessage.addTimerCallback(0.05, requestSample,
> nodeHdl)
>
> #callback procedure
> def requestSample(elapsed, last, node):
>     if node.isValid():
>
>         nodeFn = om.MFnDependencyNode(node.objectRef())
>         plug = om.MPlug(node, ardNode.OUTPUT)
>
> #open the serial port and read it
>         try:
>             if ser1.isOpen()==0 :
>                 ser1.open()
>
>             s0val = int(ser1.readline())
>             ser1.close()
>
>             plug.setInt(s0val)
>         except:
>
>             sys.stderr.write("not Connected")
>             raise
>
> def initializePlugin(mobject):
>     mplugin = omMPx.MFnPlugin(mobject)
>     try:
>         mplugin.registerNode(nodeName, nodeId, nodeCreator, nodeInit)
>     except:
>         sys.stderr.write("Error loading")
>         raise
>
> def uninitializePlugin(mobject):
>     mplugin = omMPx.MFnPlugin(mobject)
>     try:
>         mplugin.deregisterNode( nodeId )
>     except:
>         sys.stderr.write("Error removing")
>         raise

-- 
http://groups.google.com/group/python_inside_maya

To unsubscribe from this group, send email to 
python_inside_maya+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to