Report this | Email | Print
1 import osc
2 import sys,socket
3 import string
4
5 # just importing the osc module creates under the hood an outbound socket and the callback manager
6 # (osc addressManager). But we dont have to worry about that.
7
8
9 def myTest():
10 """ a simple function that creates the necesary sockets and enters an enless
11 loop sending and receiving OSC
12 """
13 osc.init()
14
15 ## osc.createListener() # this defaults to port 9001 as well
16 #osc.listen('127.0.0.1', 10000)
17 #sys.stdout.write("I am listening
")
18 # bind addresses to functions -> printStuff() function will be triggered everytime a
19 # "/test" labeled message arrives
20 osc.bind(printStuff, "/system") #this did not matter
21 #sys.stdout.write("I just binded
")
22
23 import time # in this example we will have a small delay in the while loop
24
25 print 'ready to receive and send osc messages ...'
26 inSocket= 10000
27 for i in range(1,2,1):
28 ## osc.sendMsg("/test", [444], "127.0.0.1", 9000) # send normal msg to a specific ip and port
29 osc.sendMsg("/appled/1/state", [1], "192.168.100.28", 10000) # !! it sends by default to localhost ip "127.0.0.1" and port 9000
30 #sys.stdout.write("I just sendMsg
")
31 time.sleep(1.5) #
32
33 # create and send a bundle
34 bundle = osc.createBundle()
35 osc.appendToBundle(bundle, "/appled/3/state", [1]) # 1st message appent to bundle
36 ## osc.sendBundle(bundle, "", 9000) # send it to a specific ip and port
37
38 osc.sendBundle(bundle,"192.168.100.28",10000) # !! it sends by default to localhost ip "127.0.0.1" and port 9000
39
40 osc.sendMsg("/system/task-report", [], "192.168.100.28", 10000) # !! it sends by default to localhost ip "127.0.0.1" and port 9000
41 #bundle = osc.createBundle()
42 #osc.appendToBundle(bundle, "", []) # 1st message appent to bundle
43 #osc.sendBundle(bundle,"192.168.100.28",10000) # !! it sends by default to localhost ip "127.0.0.1" and port 9000
44
45 #osc.listen()
46 #osc.listen("192.168.100.221",10000)
47 osc.getOSC(inSocket) # listen to incomming OSC in this socket, nor did this matter
48 time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible.
49
50
51 osc.dontListen() # finally close the connection bfore exiting or program
52
53
54 """ Below some functions dealing with OSC messages RECEIVED to Python.
55
56 Here you can set all the responders you need to deal with the incoming
57 OSC messages. You need them to the callBackManager instance in the main
58 loop and associate them to the desired OSC addreses like this for example
59 addressManager.add(printStuff, "/print")
60 it would associate the /print tagged messages with the printStuff() function
61 defined in this module. You can have several callback functions in a separated module if you wish
62 """
63
64 def printStuff(*msg):
65 """deals with "print" tagged OSC addresses """
66
67 print "printing in the printStuff function ", msg
68 print "the oscaddress is ", msg[0][0]
69 print "the value is ", msg[0][2]
70
71
72
73
74 if __name__ == '__main__': myTest()
Views - Today : 315 Total : 315