ok,
so I now have a bit of time so I'm going back to writing my first python plugin. What I'm wanting to do is make a node which reads/writes values to/from the Make Controller. ( www.makingthings.com ) which communicates over OpenSoundControl
I managed a super simple test which uses simpleOSC http://pypi.python.org/pypi/SimpleOSC/0.2.3
that simply reads the value from the analogin 0 pin.
Here:
import osc
import time
localAddress = "192.168.0.210"
makeControllerAddress = "192.168.0.200"
port = 10000
sampleRate = 0.2
sensor0 = "/analogin/0/value"
def myTest():
osc.init()
inSocket = osc.createListener(localAddress, port)
osc.bind(anaIn, sensor0)
print 'ready to receive and send osc messages ...'
while 1:
osc.sendMsg("/analogin/0/value", [], makeControllerAddress, port)
osc.getOSC(inSocket)
time.sleep(sampleRate)
print outputValue.sensor0
""" Below some functions dealing with OSC messages RECEIVED to Python.
Here you can set all the responders you need to deal with the incoming
OSC messages. You need them to the callBackManager instance in the main
loop and associate them to the desired OSC addreses like this for example
addressManager.add(printStuff, "/print")
it would associate the /print tagged messages with the printStuff() function
defined in this module. You can have several callback functions in a separated module if you wish
"""
def anaIn(*msg):
sensorVal0 = msg[0][2]
outputValue.sensor0 = sensorVal0
class outputValue():
sensor0 = 0
if __name__ == '__main__': myTest()
##########################################################
Now fresh out of watching the Digital tutor's DVD I'm trying to get this value to output to the node and surprise surprise I can't get it to work. I'm not getting errors, but nothing is happening. I was hoping that someone might just point me in the right direction and just give me some hints to the logic of what I need to do (and not do). I'm familiar with MEL and maya, but just now learning this route.
Thanks for the help,
Nick
#####below is the code I have so far for the plugin
import osc
import time
import maya.OpenMaya as om
import maya.OpenMayaMPx as omMPx
localAddress = "192.168.0.210"
makeControllerAddress = "192.168.0.200"
port = 10000
sampleRate = 0.2
sensor0 = "/analogin/0/value"
nodeName = "makeInOut"
nodeId = om.MTypeId(0x101122)
def sensorData():
print "started"
osc.init()
inSocket = osc.createListener(localAddress, port)
osc.bind(tellSens0, sensor0)
print 'ready to receive and send osc messages ...'
while 1:
osc.sendMsg("/analogin/0/value", [], makeControllerAddress, port)
osc.getOSC(inSocket)
time.sleep(sampleRate)
""" Below some functions dealing with OSC messages RECEIVED to Python.
Here you can set all the responders you need to deal with the incoming
OSC messages. You need them to the callBackManager instance in the main
loop and associate them to the desired OSC addreses like this for example
addressManager.add(printStuff, "/print")
it would associate the /print tagged messages with the printStuff() function
defined in this module. You can have several callback functions in a separated module if you wish
"""
def anaIn(*msg):
sensorVal0 = msg[0][2]
makeInput.involt = sensorVal0
##################################################################################################
class makeInput(omMPx.MPxNode):
# input and output variables
involt = 0
sampleRate = om.MObject()
voltage0 = om.MObject()
def \_\_init\_\_(self):
omMPx.MPxNode.\_\_init\_\_(self)
def compute(self, plug, dataBlock):
if (plug == makeInput.voltage0):
in0 = makeInput.involt
outputHandle = dataBlock.outputValue(makeInput.voltage0)
outputHandle.setFloat(in0)
dataBlock.setClean(plug)
def nodeCreator():
return omMPx.asMPxPtr( makeInput() )
def nodeInit():
# Init me
numAttr = om.MFnNumericAttribute()
makeInput.voltage0 = numAttr.create("sensor0","s0",om.MFnNumericData.kFloat,0.0)
numAttr.setStorable(1)
numAttr.setWritable(1)
makeInput.addAttribute(makeInput.voltage0)
# This is used for loading plugins
def initializePlugin(mobject):
mplugin = omMPx.MFnPlugin(mobject)
try:
mplugin.registerNode(nodeName, nodeId, nodeCreator, nodeInit)
except:
sys.stderr.write("Error loading")
raise
# This is used for removing plugins
def uninitializePlugin(mobject):
mplugin = omMPx.MFnPlugin(mobject)
try:
mplugin.deregisterNode( nodeId )
except:
sys.stderr.write("Error removing")
raise
if __name__ == '__main__': sensorData()