def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ import time # in this example we will have a small delay in the while loop initOSCClient() # takes args : ip, port initOSCServer() # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server # bind addresses to functions setOSCHandler('/check', checkcheckcheck) startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...' try: while 1: sendOSCMsg("/test", [444]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # create and send a bundle bundle = createOSCBundle("/test/bndlprt1") bundle.append(666) # 1st message appent to bundle bundle.append("the number of the beast") # 2nd message appent to bundle sendOSCBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible. except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # finally close the connection before exiting or program.
def LaserLoop(): initOSCClient('127.0.0.1', 8000) # takes args : ip, port initOSCServer('127.0.0.1', 8001) # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking # bind addresses to functions setOSCHandler('/laser', laser) startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...'
def run(): try: initOSCServer(ip, port) setOSCHandler('/collision', col) startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) except KeyboardInterrupt: closeOSC()
def LaserLoop(): initOSCClient('127.0.0.1', 8000) # takes args : ip, port initOSCServer( '127.0.0.1', 8001 ) # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking # bind addresses to functions setOSCHandler('/laser', laser) startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...'
def run(): # SETUP # resetCanvas() import time out.FADERATE = 8 # fade rate, currently broken? out.start() # OSC SERVER/HANDLERS # initOSCServer(ip, port) # setup OSC server setOSCHandler('/reset', reset) # resets the visualization setOSCHandler('/asteroid', orb) # when an orb moves on the screen setOSCHandler('/set_max_brightness', setMax) setOSCHandler('/set_min_brightness', setMin) # SERVER START # startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) # SERVER LOOP# try: clock = 1 while(1): out.write(canvas) # write to canvas time.sleep(0.1) # tick every 0.1 seconds if ((clock%1000) == 0): # every 1000 ticks plasmaCanvas() clock = (clock+1)%10000 # increment clock, reseting every 10000 ticks except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def run(): # SETUP # resetCanvas() import time out.FADERATE = 8 # fade rate, currently broken? out.start() # OSC SERVER/HANDLERS # initOSCServer(ip, port) # setup OSC server setOSCHandler('/reset', reset) # resets the visualization setOSCHandler('/asteroid', orb) # when an orb moves on the screen setOSCHandler('/set_max_brightness', setMax) setOSCHandler('/set_min_brightness', setMin) # SERVER START # startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) # SERVER LOOP# try: clock = 1 while (1): out.write(canvas) # write to canvas time.sleep(0.1) # tick every 0.1 seconds if ((clock % 1000) == 0): # every 1000 ticks plasmaCanvas() clock = (clock + 1) % 10000 # increment clock, reseting every 10000 ticks except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
def app(): # Init Dynamixel connection global dxlIO, foundIds ports = pypot.dynamixel.get_available_ports() if not ports: raise IOError('No port available.') port = ports[0] dxlIO = pypot.dynamixel.DxlIO(port) print 'Connected' # Setup motors dxlIO.enable_torque([leftWheelMotorId, rightWheelMotorId, dremelMotorId]) dxlIO.set_moving_speed({dremelMotorId: dremelJointSpeedMin}) # Init OSC server simpleOSC.initOSCServer(receiveAddress, receivePort) simpleOSC.setOSCHandler('/wheelspeed', wheelSpeedHandler) simpleOSC.setOSCHandler('/wheelslowdown', wheelSlowdownHandler) simpleOSC.setOSCHandler('/dremeljointpos', dremelJointPosHandler) simpleOSC.setOSCHandler('/dremeljointspeed', dremelJointSpeedHandler) simpleOSC.startOSCServer() # Enter infinite loop to be able to catch KeyboardInterrupt try: while True: time.sleep(0) except KeyboardInterrupt: simpleOSC.closeOSC()
def run(): try: initOSCClient(ip, client_port) # initOSCClient(ip, client_port) initOSCServer(ip, server_boids_port) setOSCHandler('/collision', col) startOSCServer() initOSCServer(ip, server_sound_port) setOSCHandler('/request', request) startOSCServer() except KeyboardInterrupt: closeOSC()
def myTest(): """ a simple function that creates the necesary sockets and enters an enless loop sending and receiving OSC """ import time # in this example we will have a small delay in the while loop initOSCClient() # takes args : ip, port print 'client' initOSCServer( ) # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server print 'server' # bind addresses to functions setOSCHandler('/check', checkcheckcheck) print 'check' startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...' try: while 1: print 'sending...' sendOSCMsg( "/test", [444] ) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 # create and send a bundle bundle = createOSCBundle("/test/bndlprt1") bundle.append(666) # 1st message appent to bundle bundle.append( "the number of the beast") # 2nd message appent to bundle sendOSCBundle( bundle ) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 time.sleep( 0.5 ) # you don't need this, but otherwise we're sending as fast as possible. except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # finally close the connection before exiting or program.
def stuff(): import time a = [] a.len initOSCServer(ip, port) setOSCHandler('/collision', collision) startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) try: while(1): time.sleep(1000) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # finally close the connection before exiting or program.
def myTest(): initOSCClient("192.168.0.2", 9000) # takes args : ip, port initOSCServer( "192.168.0.7", 9001, 0) # takes args : ip, port, mode => 0 basic, 1 threading, 2 forking setOSCHandler('/test', test) startOSCServer() print 'ready to receive and send osc messages...' try: while 1: sendOSCMsg("/sup", [444, 4.4, 'yomama is a baby']) time.sleep(1) except KeyboardInterrupt: print "closing all OSC connections and exiting" closeOSC()
def run_server(self): # OSC SERVER/HANDLERS # initOSCServer(self.ip, self.rport) # setup OSC server setOSCHandler('/async/hue', hue_handler) # SERVER START # startOSCServer() print "server is running, listening at " + str(self.ip) + ":" + str(self.rport) print "use Ctrl-C to quit." # SERVER LOOP # try: clock = 1 while(1): time.sleep(5) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
self.send("*" * i) def closed(self, code, reason=None): print "Closed down", code, reason def received_message(self, m): print m if len(m) == 175: self.close(reason='Bye bye') if __name__ == '__main__': # try: try: initOSCServer(ip, port) setOSCHandler('/collision', col) startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) ws = DummyClient('ws://localhost:9000/', protocols=['nlcp']) ws.connect() ws.run_forever() except KeyboardInterrupt: ws.close() closeOSC() def col(addr, tags, data, source): print "got collision" print data
def __init__(self, **kwargs): super(BrokerControlMain, self).__init__(**kwargs) # create and bind every slider and buttons for x in xrange(1, 11): btn = BrokerControlButton(index=x, text=str(x)) btn.bind(state=self.on_button_state) self.grid.add_widget(btn) # led handler for monome prefix = self.app.config.get('monome', 'prefix') setOSCHandler('/%s/led' % prefix, self.on_led) setOSCHandler('/%s/led_col' % prefix, self.on_led_col) setOSCHandler('/%s/led_row' % prefix, self.on_led_row) setOSCHandler('/%s/led_frame' % prefix, self.on_led_frame) setOSCHandler('/%s/led_clear' % prefix, self.on_led_clear) # empty handlers setOSCHandler('/sys/prefix', self.empty_handler) setOSCHandler('/sys/cable', self.empty_handler) setOSCHandler('/sys/offset', self.empty_handler) setOSCHandler('/sys/intensity', self.empty_handler) setOSCHandler('/sys/test', self.empty_handler) setOSCHandler('/sys/report', self.empty_handler)
def __init__(self, **kwargs): super(TouchLiveMain, self).__init__(**kwargs) # create and bind every slider and buttons for x in xrange(64): btn = TouchLiveButton(index=x) btn.bind(state=self.on_button_state) self.grid.add_widget(btn) for x in xrange(16): slider = TouchLiveSlider(index=x, min=0, max=127) slider.bind(value=self.on_right_slider_value) self.grid_right.add_widget(slider) for x in xrange(8): slider = TouchLiveSlider(index=x, min=0, max=127, orientation='vertical') slider.bind(value=self.on_bottom_slider_value) self.grid_bottom.add_widget(slider) # led handler for monome prefix = self.app.config.get('monome', 'prefix') setOSCHandler('/%s/led' % prefix, self.on_led) setOSCHandler('/%s/led_col' % prefix, self.on_led_col) setOSCHandler('/%s/led_row' % prefix, self.on_led_row) setOSCHandler('/%s/led_frame' % prefix, self.on_led_frame) setOSCHandler('/%s/led_clear' % prefix, self.on_led_clear) # empty handlers setOSCHandler('/sys/prefix', self.empty_handler) setOSCHandler('/sys/cable', self.empty_handler) setOSCHandler('/sys/offset', self.empty_handler) setOSCHandler('/sys/intensity', self.empty_handler) setOSCHandler('/sys/test', self.empty_handler) setOSCHandler('/sys/report', self.empty_handler)
def run_server(self): # OSC SERVER/HANDLERS # initOSCServer(self.ip, self.rport) # setup OSC server setOSCHandler('/shape', shape_handler) setOSCHandler('/boundary', boundary_handler) setOSCHandler('/contact', contact_handler) setOSCHandler('/hand', hand_handler) setOSCHandler('/finger', finger_handler) setOSCHandler('/background', background_handler) setOSCHandler('/bgrgb/red', bgred_handler) setOSCHandler('/bgrgb/green', bggreen_handler) setOSCHandler('/bgrgb/blue',bgblue_handler) # SERVER START # startOSCServer() print "server is running, listening at " + str(self.ip) + ":" + str(self.rport) print "use Ctrl-C to quit." # SERVER LOOP # try: clock = 1 while(1): time.sleep(5) except KeyboardInterrupt: print "closing all OSC connections... and exit" closeOSC() # close the osc connection before exiting
print "New face with ID %s detected" % data def deleteface(addr, tags, data, source): print "Face with ID %s escaped" % data def facelist(addr, tags, data, source): print "Face %s position: x:%s y:%s, motion: x:%sy:%s, distance:%s" % (data[0], data[1], data[2], data[3], data[4], data[5]) def end(addr, tags, data, source): closeOSC() print "Bye" sys.exit() if __name__ == '__main__': initOSCServer('127.0.0.1', 7000) setOSCHandler('/newface', newface) setOSCHandler('/deleteface', deleteface) setOSCHandler('/facelist', facelist) setOSCHandler('/end', end) startOSCServer() while True: try: pass except KeyboardInterrupt: closeOSC() print "Bye" sys.exit()
closeOSC() pl.terminate() if __name__ == '__main__': b = nxt.locator.find_one_brick() controls = MotorControl(b) # takes args : ip, port initOSCClient() # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server initOSCServer(ip='127.0.0.1', port=20002, mode=1) # bind addresses to functions setOSCHandler('/motors', controls.motor_osc_handler) # and now set it into action startOSCServer() # starting the sensor broadcast in parallel pool = mp.Pool() #pool.apply_async(shutdown(pool)) pool.apply_async(sensor_broadcast(controls)) pool.close() pool.join() # server = sensor_broadcast(controls) # procOSC = mp.Process(server) # procOSC.start() # input("Press any key to close OSC server")
help="The port to listen on") parser.add_argument("--port_send", type=int, default=9002, help="The port to send messages to") args = parser.parse_args() # Configure connection to/from Push2 MIDI try: push2_midi_out = mido.open_output( 'Ableton Push 2:Ableton Push 2 MIDI 1 16:0') push2_midi_in = mido.open_input( 'Ableton Push 2:Ableton Push 2 MIDI 1 16:0') push2_midi_in.callback = midi_from_push_handler print("Listening for MIDI messages comming from push...") except OSError: print("Could not connect to Push2 MIDI ports") sys.exit(0) except IOError: print("Could not connect to Push2 MIDI ports") sys.exit(0) # Configure OSC client for sending messages to initOSCClient(ip=args.ip, port=args.port_send) # Configure OSC server to receive messages from OCTOPUSH initOSCServer(ip=args.ip, port=args.port_listen) setOSCHandler('/topush', midi_to_push_handler) startOSCServer() print("Listening OSC on {}".format(args.port_listen))
print m if len(m) == 175: self.close(reason='Bye bye') def bkgrnd(addr, tags, data, source): print "got collision" print data[0] ws.send("010101"); if __name__ == '__main__': # try: try: initOSCServer(ip, port) setOSCHandler('/background', bkgrnd) startOSCServer() print "server is running, listening at " + str(ip) + ":" + str(port) ws = DummyClient('ws://localhost:9000/', protocols=['nlcp']) ws.connect() ws.run_forever() except KeyboardInterrupt: ws.close() closeOSC()
sendOSCMsg("/error", ["No more recorded data to playback!"]) def set_head(addr, tags, data, source): global control control.set_head(data[0]) def set_displacement(addr, tags, data, source): global control control.displace(data[0]) def playback_displaced(addr, tags, data, source): global control d = control.get_data_displaced() sendOSCMsg("/ga", d) setOSCHandler('/kinect', receive_kinect_data) setOSCHandler('/ping', ping) setOSCHandler('/playback', playback_data_point) setOSCHandler('/set_head', set_head) setOSCHandler('/displace', set_displacement) setOSCHandler('/playback_displace', playback_displaced) startOSCServer() try: n = 0 while 1: n = n + 1 print "Server is alive! Message # ", n time.sleep(1) except:
def server(): initOSCServer("0.0.0.0", 9000, 0) setOSCHandler('/drink', drink) startOSCServer()
num_scale_step = 4 num_dist_step = 4 num_rotation_bool = 2 action_size = num_objects * num_angle_step * num_scale_step * num_dist_step * num_rotation_bool agent = DQNAgent(state_size, action_size) my_file = Path("./save/weights.h5") if my_file.is_file(): agent.load("./save/weights.h5") else: agent.save("./save/weights.h5") done = False batch_size = 32 # setup OSC parts initOSCClient() # takes args : ip, port print 'client' initOSCServer( ) # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server print 'server' # bind addresses to functions setOSCHandler('/inputs_current', currentHandler) setOSCHandler('/inputs_next', nextHandler) print 'address binding check' startOSCServer() # and now set it into action print 'ready to receive and send osc messages ...'
def setup(): """ initializes everything """ # start serial comm global port port = serial.Serial("/dev/ttyUSB0", baudrate=19200, timeout=3.0) # start OSC comm and attach handlers global haveClient haveClient = False initOSCServer("192.168.0.160", 9001, 0) # last arg: 0 basic, 1 threading, 2 forking setOSCHandler("/client", client) setOSCHandler("/initialize", initialize) setOSCHandler("/calibrate", calibrate) setOSCHandler("/toollength", toollength) setOSCHandler("/speed", speed) setOSCHandler("/home", home) setOSCHandler("/where", where) setOSCHandler("/cartesian", cartesian) setOSCHandler("/joint", joint) setOSCHandler("/move", move) setOSCHandler("/off", off) startOSCServer() global busy busy = False print "roboforthOSC started..."
def start(self): initOSCServer(self.ip, self.port) # setup OSC server setOSCHandler('/send_next_song', self.buffer_handler) startOSCServer() self.main_method() sendOSCMsg("/startprogram", [1])