0

我已经成功创建/改编了一个可以工作的 OSC python 脚本,它可以接受外部硬件的 OSC 数据并将其打印到我的计算机上。

我目前正在尝试将此数据发送到另一个程序。该脚本正在工作,只是它只会发送第一条 UDP 消息。在控制台中,我可以看到脚本正在运行,因为它在收到 osc 数据时打印出代码的各个方面。

当我将其他消息发送到外部程序时,UDP 接收器正在另一端工作。

包括可能有助于识别问题的代码部分。任何帮助表示赞赏,奇怪的是函数的其余部分被再次调用并正常工作,而不是发送数据的最后一行......

我确实尝试了一个单独的函数并在 osc 处理程序函数的末尾调用该函数,但仍然存在仅发送第一条 UDP 消息的相同问题。

提前致谢!

ip = socket.gethostbyname(socket.gethostname()) #Gets IP of MacBook Pro

receive_address = ip, 4567 # MacBook Pro Adress, Outgoing Port
send_address = '192.168.#.##', 9112 # iPhone Adress, Incoming Port
 
# ------------------ UDP to send  IP/ Port Settings ----------------- #


UDP_IP = "127.0.0.1" # Local machine to send data internally
UDP_PORT = 1234 # Local UDP Port

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((UDP_IP, UDP_PORT))


# --------------------- OSC Server and client start -------------------------------- #
 
# Initialize the OSC server and the client.
s = OSC.OSCServer(receive_address)
c = OSC.OSCClient()
c.connect(send_address)
 
s.addDefaultHandlers()

def multixy1(add, tags, stuff, source): #osc handler
	
	print "Message received:"
	msg = OSC.OSCMessage()
	print msg
	msg.setAddress(addr)
	msg.append(stuff)
	c.send(msg)
	
        # Testing osc is working/updating with each message input #
        print "Raw OSC Mesagge = ", msg
	print "X Value: ", stuff[0]

	UDP_to_Send = str(msg)
	
        print "UDP Send message = ", UDP_Send
	print sock
	print datetime.now()
	
        tm = str(datetime.now())
	print "size = ", sys.getsizeof(tm), "bytes"
	
        sock.send(tm) # this line does not appear to be called again despite the rest of the function being called

s.addMsgHandler("/1/fader1",  multixy1)

# ----------- Starting OSC server ----------- #

print "\nStarting OSCServer."

st = threading.Thread( target = s.serve_forever )
st.start()

# Loop while threads are running.
try :
    while 1 :
	time.sleep(0.1)
	
except KeyboardInterrupt :
    print "\nClosing OSCServer."
    s.close()
    print "Waiting for Server-thread to finish"
    st.join()
    print "Done"

4

0 回答 0