当前位置: 首页>>代码示例>>Python>>正文


Python OSCServer.serve_forever方法代码示例

本文整理汇总了Python中OSC.OSCServer.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python OSCServer.serve_forever方法的具体用法?Python OSCServer.serve_forever怎么用?Python OSCServer.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OSC.OSCServer的用法示例。


在下文中一共展示了OSCServer.serve_forever方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
def main():
    global bRun
    global inOSCport, outOSCport
    global myOSC_Server, myOSC_Client

    global cTrial, nTrials, breaksxTrial

    cTrial = 1 

    global debug_data
    global CS_US_1 

    CS_US_1['inputs']=[]

    cerebellumConfig['weights']=[]
    cerebellumConfig['config']=[]
    cerebellumConfig['constants']=[]


    debug_data['trials']=[]
    if save_bases:
        debug_data['basis']=[]
    debug_data['inputs']=[]

    inOSCport = 1234
    outOSCport = 1235
    
    # myOSC_Server = OSCServer( ('' , inOSCport) )
    # myOSC_Client = OSCClient()
    # myOSC_Client.connect( ('10.0.0.116' , outOSCport) )

    myOSC_Server = OSCServer( ('127.0.0.1' , inOSCport) )
    myOSC_Client = OSCClient()
    myOSC_Client.connect( ('127.0.0.1' , outOSCport) )
    
    print "Receiving messages /trial,/input in port", inOSCport
    print "Sending messages to port", outOSCport


    myOSC_Server.addMsgHandler("/config", receiveConfig)
    myOSC_Server.addMsgHandler("/trial", receiveTrial)
    myOSC_Server.addMsgHandler("/endtrial", receiveEndTrial)
    myOSC_Server.addMsgHandler("/input", receiveInput)
    myOSC_Server.addMsgHandler("/debug", receiveDebug)
    myOSC_Server.addMsgHandler("/update", receiveUpdate)
    myOSC_Server.addMsgHandler("/freeze", receiveFreeze)
    myOSC_Server.addMsgHandler("/saveConfig", receiveSaveConf)
    

    

    # if (cTrial==nTrials):
    #     pl.figure(figsize=(10,6))
    #     plot(breaksxTrial)

    
    print "Ready"

    myOSC_Server.serve_forever()
开发者ID:tcstewar,项目名称:telluride2014,代码行数:61,代码来源:cerebellarIROSExperimentRobotSaveConf.py

示例2: OSC_MPD

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
class OSC_MPD(object):
    def __init__(self, osc=('0.0.0.0', 8000), mpd=('127.0.0.1', 6600)):
        self.mpc = MPDClient()
        self.mpc.connect(mpd[0], mpd[1])
        self.server = OSCServer(osc)

        def musicManage(addr, tags, data, client_address):
            cmd = addr.strip('/').split('/')[-1]
            self.mpc.__getattr__(cmd)(*data)

        self.server.addMsgHandler('/bearstech/music/play', musicManage)
        self.server.addMsgHandler('/bearstech/music/pause', musicManage)
        self.server.addMsgHandler('/bearstech/music/next', musicManage)
        self.server.addMsgHandler('/bearstech/music/previous', musicManage)
        self.server.addMsgHandler('/bearstech/music/stop', musicManage)

    def serve_forever(self):
        self.server.serve_forever()
开发者ID:bearstech,项目名称:osc-mpd,代码行数:20,代码来源:__init__.py

示例3: OSCForwarder

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
class OSCForwarder(threading.Thread):
   def __init__(self, from_ip, from_port, to_ip, to_port):
      super(OSCForwarder, self).__init__()

      # create the server to listen to messages arriving at from_ip
      self.server = OSCServer( (from_ip, from_port) )
      self.server.addMsgHandler( 'default', self.callback )

      # create the clieent to forward those message to to_ip
      self.client = OSCClient()
      self.client.connect( (to_ip, to_port) )

      print '%s:%d --> %s:%d' % (from_ip, from_port, to_ip, to_port)

      self.done_running = False

      # start the server listening for messages
      self.start()

   # close must be called before app termination or the app might hang
   def close(self):
      # this is a workaround of a bug in the OSC server
      # we have to stop the thread first, make sure it is done,
      # and only then call server.close()
      self.server.running = False

      while not self.done_running:
         time.sleep(.01)
      self.server.close()

   def run(self):
      #print "Worker thread entry point"
      self.server.serve_forever()
      self.done_running = True


   def callback(self, path, tags, args, source):
      #print 'got:', path, args, 'from:', source
      self.client.send( OSCMessage(path, args ) )
开发者ID:Vervious,项目名称:critters,代码行数:41,代码来源:oscbridge.py

示例4: OSCServer

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
from OSC import OSCServer
import sys
from time import sleep

server = OSCServer( ("localhost", 7110) )
server.timeout = 0
run = True

def user_callback(path, tags, args, source):
    # which user will be determined by path:
    # we just throw away all slashes and join together what's left
    user = ''.join(path.split("/"))
    # tags will contain 'fff'
    # args is a OSCMessage with data
    # source is where the message came from (in case you need to reply)
    print user, args, source 
    
for i in range(2):
    for c in range(1,5):
        server.addMsgHandler( "/EEG_%d/channel_%d/notch_50/lpf_75"%(i,c), user_callback )
    server.addMsgHandler( "/markers" , user_callback )    
server.serve_forever()
开发者ID:baltanlaboratories,项目名称:EEG-Kiss,代码行数:24,代码来源:rcv.py

示例5: got_trigger

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
from OSC import OSCServer

"""Called whenever we get a trigger message from an interface box"""
def got_trigger(path, tags, args, source):
    board = path.split("/")[3]
    pad = path.split("/")[4]
    
    status_string = "board %s pad %s" % (board, pad)
    if args[0] == 1:
        status_string = "Touch " + status_string
    else:
        status_string = "Release " + status_string

    print(status_string)
    Popen(['say', "%s %s" % (board, pad)])

listen_port = 12346

print("Attempting to listen on port %d" % listen_port)
listener = OSCServer(("0.0.0.0", 12346))
for i in range(20):
    for j in range(24):
        listener.addMsgHandler("/tactus/trigger/%d/%d" % (i, j), got_trigger)

print("Listening...")
listener.serve_forever()
print("Exiting")


开发者ID:artistsandengineers,项目名称:tactus,代码行数:29,代码来源:speaker.py

示例6: verwenden

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
    # RPi.GPIO Layout verwenden (wie Pin-Nummern)
    GPIO.setmode(GPIO.BOARD)

    for _button in button_map:
      GPIO.setup(_button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # PUD_DOWN, because we use a pull down resistor, use RISING in next line then!
      GPIO.add_event_detect(_button, GPIO.RISING, callback=button_press, bouncetime=args.bouncetime)

    client.connect( (args.ip, args.port) )
    notifications.addMsgHandler( "/stopped", remote_stopped_callback )
    notifications.addMsgHandler( "/playing", remote_started_callback )
    notifications.addMsgHandler( "/files", remote_files_callback )

    print "StaalPiPlayer Button Client ready!"
    print "\tListening for player with:",notifications
    print "\tSending commands to player with:",client

    while True:
      try:
        notifications.serve_forever()
      except Exception, e:
        time.sleep(5)
        pass

  except Exception, e:
    pass
  finally:
    GPIO.cleanup()
    client.send( OSCMessage("/stop" ) )
    notifications.close()
    pass
开发者ID:jens-a-e,项目名称:staalpiplayer,代码行数:32,代码来源:button_player.py

示例7: __init__

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
class SSI_interface_Receiver:

	def __init__(self, board_id, measure):

		try:
			self.ports_config = json.loads(open("ssi_ports.json").read())
			print "ports config loaded"
		except:
			print "couldn't load ports file"
		self.measure = measure
		self.port= self.ports_config[board_id][self.measure]
		self.myOSC_Server = OSCServer( ("" , self.port ))
		
		self.myOSC_Server.addMsgHandler("/strm", self.receiveStream)
		self.myOSC_Server.addMsgHandler("/evnt", self.receiveEvent)
		self.myOSC_Server.addMsgHandler("/text", self.receiveText)

		self.datapack = {

				"receive_ecg":0,
				"receive_ecg-hr":0,
				"receive_ecg-rspike":0,
				"receive_ecg-pulse":0,
				"receive_ecg-tdf":0,
				"receive_ecg-sdf":0,

				"receive_gsr":0,
				"receive_gsr_pre":0,
				"receive_gsr_arousal":0,
				"receive_gsr_peak":0,
				"receive_gsr_slope":0,
				"receive_gsr_drop":0,

				"air":0,
				"air_pre":0,
				"air_pulse":0,
				"air_exhale":0

			}

		self.osc_thread = th.Thread(target=self.main)
		self.osc_thread.start()

		
	def receiveStream(self, addr, tags, data, source):

		data[7] = self.readBlob(data[7])
		self.datapack[self.measure] = data

	def receiveEvent(self, addr, tags, data, source):

		data[7] = self.readBlob(data[7])
		self.datapack[self.measure] = data

	def receiveText(self, addr, tags, data, source):

		data[7] = self.readBlob(data[7])
		self.datapack[self.measure] = data

	def readBlob(self, binary):
		decoded = []
		for i in range(len(binary)):
			if i%4 == 0 and i != 0:
				decoded.append(struct.unpack('f', binary[i-4:i])[0])
		
		return decoded


	def main(self):
		print "osc is listening"
		self.myOSC_Server.serve_forever()
开发者ID:0m15,项目名称:MHD2013,代码行数:73,代码来源:ssi_interface.py

示例8: Kinect

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import serve_forever [as 别名]
class Kinect(threading.Thread):
   def __init__(self, remote_ip = None):
      super(Kinect, self).__init__()

      core.register_terminate_func(self.close)

      # Synapse is running on a remote machine:
      if remote_ip:
         listen_ip = socket.gethostbyname(socket.gethostname())
         listen_port = 12345

         send_ip = remote_ip
         send_port = 12321

      # Synapse is running locally on this machine, using localhost
      else:
         listen_ip = 'localhost'
         listen_port = 12345

         send_ip = 'localhost'
         send_port = 12346

      self.server = OSCServer( (listen_ip, listen_port) )
      self.server.addMsgHandler( '/tracking_skeleton', self.callback_tracking_skeleton )
      self.server.addMsgHandler( 'default', self.callback_ignore )

      # create the client, which sends control messages to Synapse
      self.client = OSCClient()
      self.client.connect( (send_ip, send_port) )

      # member vars
      self.active_joints = {}
      self.last_heartbeat_time = 0
      self.done_running = False

      # start the server listening for messages
      self.start()

   # close must be called before app termination or the app might hang
   def close(self):
      # this is a workaround of a bug in the OSC server
      # we have to stop the thread first, make sure it is done,
      # and only then class server.close()
      self.server.running = False
      while not self.done_running:
         time.sleep(.01)
      self.server.close()

   def run(self):
      print "Worker thread entry point"
      self.server.serve_forever()
      self.done_running = True

   def add_joint(self, joint):
      self.server.addMsgHandler(joint + '_pos_body', self.callback)
      self.active_joints[joint] = np.array([0.0, 0.0, 0.0])

   def remove_joint(self, joint):
      self.server.delMsgHandler(joint + '_pos_body')
      del self.active_joints[joint]

   def on_update(self):
      now = time.time()
      send_heartbeat = now - self.last_heartbeat_time > 3.0
      if send_heartbeat:
         self.last_heartbeat_time = now

      try:
         for j in self.active_joints:
            if send_heartbeat:
               #print 'heartbeat:', j
               self.client.send( OSCMessage(j + "_trackjointpos", 1) )
      except Exception as x:
         print x, 'sending to', self.client.client_address

   def get_joint(self, joint) :
      return np.copy(self.active_joints[joint])

   def callback_ignore(self, path, tags, args, source):
      pass

   def callback(self, path, tags, args, source):
      #print path, args
      joint_name = path.replace("_pos_body", "")
      self.active_joints[joint_name] = np.array(args)

   def callback_tracking_skeleton(self, path, tags, args, source):
      pass
开发者ID:Vervious,项目名称:critters,代码行数:90,代码来源:kinect.py


注:本文中的OSC.OSCServer.serve_forever方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。