1
Other Plugins / Re: Using RFID to detect proximity and run TTS using voxcommando
« on: November 24, 2013, 09:06:44 AM »
Hi all,
Sorry for my super busy in the past weeks no time update this thread! I took a whole day to dig into the coding (try and error) and finally identified the root cause then fix the issue. Yes, the data stream is sometime not consistent. It will even have NO data when all tags left out of home. If we assume no data then close the socket connection, the program will stop there and all tags will be departed after the timeout. Reader seems to use previous connected socket to keep the connection to send tag information. This is exactly my problem. I have changed the code especially for data stream handling below that can fix the problem eventually.
Of course, I have also added socketoption for timeout and created threading for each incoming socket connection for this infinite loop for recv(). Infinite looping for receving data stream is a key for Reader. If all tags not there, no data but we should wait there. Once any tags come back, the data should be continually received. It is different with so many traditional TCP server sample code whcih will close the socket then end when no data is received in buffer or specific key is treated as socket end. I attached the modified code for your reference. Enjoy!! Thanks all of your assitance and Happy VOXCOMMANDO :-)
Best regards,
Fai
Sorry for my super busy in the past weeks no time update this thread! I took a whole day to dig into the coding (try and error) and finally identified the root cause then fix the issue. Yes, the data stream is sometime not consistent. It will even have NO data when all tags left out of home. If we assume no data then close the socket connection, the program will stop there and all tags will be departed after the timeout. Reader seems to use previous connected socket to keep the connection to send tag information. This is exactly my problem. I have changed the code especially for data stream handling below that can fix the problem eventually.
Code: [Select]
def handler(clientsock,addr):
BUFFER_SIZE = 256
while 1:
try:
data = clientsock.recv(BUFFER_SIZE)
if not data: continue
if len(data)<8:continue
for i in range(0,int(len(data)/8)):
if data[i*8]!="\xFB" or data[i*8+1]!="\x10" or data[i*8+2]!="\x00" or data[i*8+3]!="\x00" or data[i*8+7]!="\x1F": continue
tagID =ord(data[i*8+4])
updateId(tagID)
except clientsocket,e:
vc.triggerEvent("python.tcp.error",None)
continue
clientsock.close()
vc.triggerEvent("python.socket.thread.exit",None)
Of course, I have also added socketoption for timeout and created threading for each incoming socket connection for this infinite loop for recv(). Infinite looping for receving data stream is a key for Reader. If all tags not there, no data but we should wait there. Once any tags come back, the data should be continually received. It is different with so many traditional TCP server sample code whcih will close the socket then end when no data is received in buffer or specific key is treated as socket end. I attached the modified code for your reference. Enjoy!! Thanks all of your assitance and Happy VOXCOMMANDO :-)
Best regards,
Fai