对于高级设计,我让labview将编码器位置发送到另一个python脚本,该脚本接收这些位置并执行正向运动学并实现触觉边界。我需要获取这些数据并制作一个GUI。但我得到了这个错误。有什么想法吗?在
在-GUIserver.py在
# Echo server program
import socket
import pickle
import Tkinter
HOST = 'localhost' # Symbolic name meaning all available interfaces
PORT = 5000 # Arbitrary non-privileged port
addr = (HOST,PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
data = conn.recv(1024)
print(data)
conn.sendall("Welcome Haptic Client: Please send bounrary array via encoded pickle")
data = conn.recv(1024)
boundaryarray = pickle.loads(data)
print repr(boundaryarray)
conn.sendall("GUI loading")
root = Tkinter.Tk()
root.title("Haptic GUI")
w = Tkinter.Canvas(root, width=640, height=480)
w.pack()
#For loops to write all boundary data
for x,y in boundaryarray:
print x
previousx = x
print y
previousy = y
firstx = x
firsty = y
del boundaryarray[0]
break
for x,y in boundaryarray:
print x
print y
print str(previousx) + "x previous"
print str(previousy) + " y previous"
w.create_line(previousx, previousy, x, y, fill="red")
previousx = x
previousy = y
w.create_line(boundaryarray[-1], boundaryarray[-1], firstx, firsty, fill="red")
conn.sendall("The boundary has been plotted, read to take pen data. Send me the current point and the point before that only if the pen array is longer then 2 element")
conn.sendall("To shut down the GUI and socket, send GUI SERVER OFF")
while True:
data = conn.recv(1024)
if data == "GUI SERVER OFF":
break
penarray = pickle.loads(str(data))
for x,y in boundaryarray:
firstx = x
firsty = y
del boundaryarray[0]
break
for x,y in boundaryarray:
secondx = x
secondy = y
w.create_line(firstx, firsty, secondy, secondx, fill="red")
w.canvas.draw()
conn.sendall("plotted")
root.mainloop()
在-hapticlient.py在
^{pr2}$
如果不将整个字符串传递给pickle,而只传递其中的一部分,则会发生EOFError。 当使用
conn.recv(1024)
从套接字读取不完整的字符串时,可能会发生这种情况。在我会改变的
因为
^{pr2}$conn.recv(1024)
接收0到1024个字节。我会把它换成因为它能读到泡菜想要的一切,而不是更多而不是更少。在
如果你把东西扔了
带着文件。在
我也会重新考虑这个:Python implementing simple web data storage
相关问题 更多 >
编程相关推荐