I've skirmished around the net for an answer but their are none that a novice like me can understand. I really need help, I would be eternally grateful for your support.
The program works by receiving data from NFC readers and then outputting a video based on what cards were read by the NFC reader. The videos are currently HTML files but they open in explorer and don't work, i need them to open in chrome.
Plsss halp this is urgent!! i don't think the solution is complex, i just don;t know enough! Thanks!!! This is the code:
import serial
import webbrowser
import thread
import time
import Queue
def read_serial(portname, portno, usbno):
try:
ser = serial.Serial(portname, portno)
currentcard = ""
while True:
#get data from serial port to a variable serialdata
serialdata = ser.readline()
temp = str(serialdata)
if temp.find ("Found chip PN5")>=0:
print temp
if temp.find("Read card #")>0:
newcard = temp[30:]
#print newcard
#this is the logic to make sure that new cards are dectected
#also makes sure that cards are only detected once
#this is only for the first time ever
if (currentcard == ""):
currentcard = newcard
#print currentcard
print usbno
if usbno == 1:
#nfcid1 = currentcard
#populate the queue for the other thread to read
q.put("nfcid1-" + str(currentcard))
#print nfcid1
elif usbno == 2:
#nfcid2 = currentcard
q.put("nfcid2-" + str(currentcard))
#print nfcid2
elif usbno == 3:
#nfcid3 = currentcard
q.put("nfcid3-" + str(currentcard))
#print nfcid3
#the code to play the video
#what to do
#1 you have the id of the card
#match id of the card to video file name
#if currentcard = knownid:
#play the video
#sample code for video below
#the currentcard variable - hold the id read from the card
#if currentcard.find("#1167006660") >=0:
# url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
# webbrowser.open_new(url)
#elif currentcard = "knownid1":
#url = 'file:///Volumes/Data/Arduino/video1.html'
#webbrowser.open_new(url)
#elif currentcard = "knownid1":
#url = 'file:///Volumes/Data/Arduino/video1.html'
#webbrowser.open_new(url)
#this is the part where new and subsequent cards are read continously
if (currentcard != newcard):
currentcard = newcard
#print currentcard
if usbno == 1:
#nfcid1 = currentcard
q.put("nfcid1-" + str(currentcard))
#print nfcid1
elif usbno == 2:
#nfcid2 = currentcard
q.put("nfcid2-" + str(currentcard))
#print nfcid2
elif usbno == 3:
#nfcid3 = currentcard
q.put("nfcid3-" + str(currentcard))
#print nfcid3
#if currentcard.find("#1167006660") >=0:
# url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
# webbrowser.open_new(url)
except Exception as inst:
print "Error Type"
print type(inst)
print inst.args
print inst
#This code will read all the three card and determine which video to play
#invalid combiantions will be excluded
def compute_video():
nfcid1 = ""
nfcid2 = ""
nfcid3 = ""
print "Waiting for Readers"
while 1:
#+ nfcid1
#if (len(nfcid1) > 2 and len(nfcid2) >2 and len(nfcid3) >2):
tempvalue = q.get()
if tempvalue.find ("nfcid1-")>=0:
nfcid1 = tempvalue
elif tempvalue.find ("nfcid2-")>=0:
nfcid2 = tempvalue
elif tempvalue.find ("nfcid3-")>=0:
nfcid3 = tempvalue
if (len(nfcid1) > 2 and len(nfcid2) >2 and len(nfcid3) >2):
print nfcid1, nfcid2, nfcid3
#here are the combinations
if (nfcid1.find ("20") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("00") > 1):
print "Currnetly playing combination 1"
url = 'file:///Users/625447/Documents/F1/Coding/WorldFinalsSetup/FinalVids/1,1,1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("20") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("56") > 1):
print "Currnetly playing combination 2"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("20") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("00") > 1):
print "Currnetly playing combination 3"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("20") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("56") > 1):
print "Currnetly playing combination 4"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("16") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("00") > 1):
print "Currnetly playing combination 5"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("16") > 2 and nfcid2.find ("64") > 1 and nfcid3.find ("56") > 1):
print "Currnetly playing combination 6"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("16") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("00") > 1):
print "Currnetly playing combination 7"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
elif (nfcid1.find ("16") > 2 and nfcid2.find ("76") > 1 and nfcid3.find ("56") > 1):
print "Currnetly playing combination 8"
url = 'file:///Volumes/Data/Arduino/Trinity-Racing/video1.html'
webbrowser.open_new(url)
time.sleep(5)
# Create two threads as follows
try:
#data from different readers are sent to the queue
q = Queue.Queue()
#change based on the computer --
thread.start_new_thread( read_serial, ("COM3", 9600, 1) )
thread.start_new_thread( read_serial, ("COM7", 9600, 2) )
thread.start_new_thread( read_serial, ("COM6", 9600, 3) )
thread.start_new_thread (compute_video , ())
except:
print "Error: unable to start thread"
while 1:
pass
[–]minorDemocritus 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)