def send_osc(ip = default_IP, port = default_PORT, loop = default_LOOP, command = []): """Function, send a list of OSC commands.""" osc.init() bundle = osc.createBundle() for item in command: osc.appendToBundle(bundle, '/sl/%s/hit' % loop, ['%s' % item]) osc.sendBundle(bundle, '%s' % ip, int(port))
def myTest(): """ a simple function that creates the necesary sockets and enters an endless loop sending and receiving OSC """ osc.init() import time i = 0 while 1: i = i % 4 print i osc.sendMsg("/x0", [i], "127.0.0.1", 9005) osc.sendMsg("/y0", [i + 1], "127.0.0.1", 9005) osc.sendMsg("/x1", [i + 2], "127.0.0.1", 9005) osc.sendMsg("/y1", [i + 3], "127.0.0.1", 9005) osc.sendMsg("/update", [1], "127.0.0.1", 9005) bundle = osc.createBundle() time.sleep(1) i += 1 osc.dontListen()
def sendevent(self, event, down): bundle=osc.createBundle() osc.appendToBundle(bundle, "/keylogger/window/"+str(event.Window)+"/key", [event.Key, down]) osc.appendToBundle(bundle, "/keylogger/WindowName/"+str(event.WindowName)+"/key", [event.Key, down]) osc.sendBundle(bundle, self.host, self.port) if(self.callback): self.callback(str(event.Window), str(event.Key))
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ osc.init() ## osc.createListener() # this defaults to port 9001 as well osc.listen('127.0.0.1', 9001) # bind addresses to functions -> printStuff() function will be triggered everytime a # "/test" labeled message arrives osc.bind(printStuff, "/test") import time # in this example we will have a small delay in the while loop print 'ready to receive and send osc messages ...' while 1: ## osc.sendMsg("/test", [444], "127.0.0.1", 9000) # send normal msg to a specific ip and port osc.sendMsg("/test", [444]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # create and send a bundle bundle = osc.createBundle() osc.appendToBundle(bundle, "/test/bndlprt1", [1, 2, 3]) # 1st message appent to bundle osc.appendToBundle(bundle, "/test/bndlprt2", [4, 5, 6]) # 2nd message appent to bundle ## osc.sendBundle(bundle, "127.0.0.1", 9000) # send it to a specific ip and port osc.sendBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 #osc.getOSC(inSocket) # listen to incomming OSC in this socket time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible. osc.dontListen() # finally close the connection bfore exiting or program
def __init__(self): osc.init() bundle = osc.createBundle() self.set_laser(False) for servo in servos: servo['range'] = self._range(servo) osc.appendToBundle( bundle, "/digitalout/%i/speed" % servo['address'], [servo['speed']] ) osc.sendBundle(bundle, BOARD_ADDRESS, BOARD_PORT)
def update_servos(self, x, y): bundle = osc.createBundle() for servo in servos: p = x if servo['axis'] == 'x' else y osc.appendToBundle( bundle, "/servo/%i/position" % servo['address'], [servo['range'](1 - p if servo['direction'] else p)] ) osc.sendBundle(bundle, BOARD_ADDRESS, BOARD_PORT) return { 'x': x, 'y': y, }
def myTest(): """ a simple function that creates the necesary sockets and enters an endless loop sending and receiving OSC """ osc.init() import time i = 1 while 1: j = ((i + 1) % 2) * 100 print j osc.sendMsg("/gainSlider", [j], "127.0.0.1", 9001) bundle = osc.createBundle() time.sleep(1) i += 1 osc.dontListen()
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ osc.init() inSocket = osc.createListener('127.0.0.1', 9001) # in this case just using one socket ## inSocket = osc.createListener() # this defaults to port 9001 as well # bind addresses to functions -> printStuff() function will be triggered everytime a # "/test" labeled message arrives osc.bind(printStuff, "/test") import time # in this example we will have a small delay in the while loop print 'ready to receive and send osc messages ...' while 1: ## osc.sendMsg("/test", [444], "127.0.0.1", 9000) # send normal msg to a specific ip and port osc.sendMsg("/test", [ 444 ]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # create and send a bundle bundle = osc.createBundle() osc.appendToBundle(bundle, "/test/bndlprt1", [1, 2, 3]) # 1st message appent to bundle osc.appendToBundle(bundle, "/test/bndlprt2", [4, 5, 6]) # 2nd message appent to bundle ## osc.sendBundle(bundle, "127.0.0.1", 9000) # send it to a specific ip and port osc.sendBundle( bundle ) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 osc.getOSC(inSocket) # listen to incomming OSC in this socket time.sleep( 0.5 ) # you don't need this, but otherwise we're sending as fast as possible.
#!/usr/bin/env python # -*- coding: utf-8 -*- import osc import sys osc.init() #for line in sys.stdin : lua = "" print "enter command:" while lua != "quit\n" and lua != "exit\n": line = sys.stdin.readline() lua += line if line == "" or line == "\n" : bundle = osc.createBundle() # osc.appendToBundle(bundle, "/lua/execute", 'groups["swarm1"].pos.z = -30') osc.appendToBundle(bundle, "/lua/execute", lua) osc.sendBundle(bundle, "localhost", 9001) print "sent:\n >" + lua.replace('\n', '\n >') print "------------" print "enter command:" lua = ""
import osc osc.init() # create and send a bundle bundle = osc.createBundle() osc.appendToBundle(bundle, "/test/bndlprt1", [1, 2.2, "333"]) osc.appendToBundle(bundle, "/test/bndlprt2", [4, 5.5, 6]) osc.sendBundle(bundle, "127.0.0.1", 9999)