Hi guys i am new to python and have written this function
def Probe(serial = None):
if not serial:
return "0"
if not os.path.isdir("/sys/bus/w1/devices/" + serial):
return "0"
tfile = open("/sys/bus/w1/devices/" + serial + "/w1_slave")
text = tfile.read()
> if text.find("YES") < 1:
> time.sleep(2)
> tfile.close()
> tfile = open("/sys/bus/w1/devices/" + serial + "/w1_slave")
> text = tfile.read()
> if text.find("YES") < 1:
> time.sleep(2)
> tfile.close()
> tfile = open("/sys/bus/w1/devices/" + serial + "/w1_slave")
> text = tfile.read()
tfile.close()
secondline = text.split("\n")[1]
temperaturedata = secondline.split(" ")[9]
temperature = float(temperaturedata[2:])
temperature = temperature / 1000
output = "%.1f" %temperature
return output
now the section in red as you can see if text DOES'NT have "YES" in it it will wait (sleep) 2 seconds then try again but i would like to change it to a loop so it wont just try twice then give up it will loop 5 times then give up
Thanks ALL
EDIT The red highlighter dont work so maked with >
Question
Craig Hopson
Hi guys i am new to python and have written this function
now the section in red as you can see if text DOES'NT have "YES" in it it will wait (sleep) 2 seconds then try again but i would like to change it to a loop so it wont just try twice then give up it will loop 5 times then give up
Thanks ALL
EDIT The red highlighter dont work so maked with >
Link to comment
Share on other sites
1 answer to this question
Recommended Posts