Hi Marcus, Sorry it has taken me a while to reply. I have tested it your suggestion and of course it works fine. It all seemed so obvious when I read your reply:)
Another question, I can't get it to stop cacheing. Even following the example on your web page, I get - >>> connection = Connection ("/dev/ttyD0") >>> for s in root.find () : print s ... <Sensor /10.2054A9010800/ - DS18S20> <Sensor /10.522FA9010800/ - DS18S20> <Sensor /28.C0617A020000/ - DS18B20> <Sensor /28.F26D7A020000/ - DS18B20> <Sensor /09.2179B9050000/ - DS2502> >>> s.use_cache (0) >>> for s in root.find () : print s ... <Sensor /10.2054A9010800/ - DS18S20> <Sensor /10.522FA9010800/ - DS18S20> <Sensor /28.C0617A020000/ - DS18B20> <Sensor /28.F26D7A020000/ - DS18B20> <Sensor /09.2179B9050000/ - DS2502> >>> So I don't see the /uncached/ entries that I was expecting. It is not a major problem for me, but I would like to force it to do a real read every time. Again, thank you so much for all your help, I have learned a lot about 1-wire and Python over the past few months, still a lot more to learn though I fear. Cheers Mick On Mon, 2010-05-31 at 23:50 +0200, Marcus Priesch wrote: > Hi mick, > > i am really sorry, but obviously your post scrolled out of my inbox > view ... and i just forgot it ;) > > well, KeyError is the desired behaviour when you do a "get" on a > "dictionary" like object ... so your code should be prepared for it ;) > > as i see aou alread catch the IOError - however i am very unsure why you > do this ... ?!?! pyowfs shouldnt raise an IOError at all ... > > but instead you should watch ot for KeyError whenever accessing an > attribute from a Sensor ... > > e.g.: > > @property > def present (self) : > try: > return self.sensor.get ("present") > except IOError, KeyError: > return -777 > > or > > @property > def present (self) : > try: > return self.sensor.get ("present") > except IOError: > return -777 > except KeyError : > print "key not found" > return -888 > > or simply in your main loop : > > s1 = Sens1 (connection) > s2 = Sens2 (connection) > while True : # repeat forever > for s in [s1,s2] : > try : > print "reading %r" % s > print 'temp = ', s.temp > print 'id = ', s.id > print 'present = ', s.present > print 'power = ', s.power > except KeyError : > print "something wrong with sensor %r" % s > > hope this helps you out ;) > > regards, > marcus. > > Am Mittwoch, den 19.05.2010, 23:27 +0100 schrieb Mick Sulley: > > Hi Marcus, > > > > Thanks for your fast response. I just tested version 0.1.3, I now get > > > > Start of loop 21530 > > S1 reading > > temp = 26.5 > > id = 522FA9010800 > > present = 1 > > power = 0 > > S2 reading > > temp = something wrong with temp > > None > > id = 2054A9010800 > > present = > > Traceback (most recent call last): > > File "./pyowfs_test1.py", line 72, in <module> > > print 'present = ', s2.present > > File "./pyowfs_test1.py", line 36, in present > > return self.sensor.get ("present") > > File "/usr/local/lib/python2.6/dist-packages/pyowfs/owfs.py", line 95, > > in get > > raise KeyError (key) > > KeyError: 'present' > > m...@mick-desktop:~/Documents/Controls$ > > > > > > What I am trying to do is to read the data from all the sensor and if > > one goes missing flag it up somehow, maybe setting the 'present' > > attribute to zero, but it needs to continue reading the others and if > > the missing one come back it needs to start reading that one as well. > > > > Here is the code that I am using to test, maybe there is a better way to > > achieve this? > > > > > > #! /usr/bin/env python > > # Filename pyowfs_test1.py > > # based up the code from Marcus Priesch > > > > > > from pyowfs import Connection > > import sys > > > > class Sensor (object) : > > id = None > > def __init__ (self, connection): > > self.conn = connection > > self.sensor = connection.find (id = self.id)[0] > > self.cache = 0 > > > > """class TempSensor (Sensor) : > > def temp (self) : > > return float (self.sensor.get ("temperature")) > > """ > > class TempSensor (Sensor) : > > @property > > def temp (self) : > > try: > > return float (self.sensor.get ("temperature")) > > except TypeError: > > print 'something wrong with temp' > > @property > > def power (self) : > > try: > > return self.sensor.get ("power") > > except IOError: > > return -888 > > @property > > def present (self) : > > try: > > return self.sensor.get ("present") > > except IOError: > > return -777 > > @property > > def id (self) : > > try: > > return self.sensor.get ("id") > > except IOError: > > return "Cant find the id" > > > > class Sens1 (TempSensor) : > > id = "522FA9010800" > > > > class Sens2 (TempSensor) : > > id = "2054A9010800" > > > > """ Start of the main program """ > > connection = Connection("/dev/ttyD1") > > for s in connection.find () : > > print s > > > > loop = 0 > > """ Need to read the sensor list and match the sensors found to the > > names on the list, mark each one as present or not """ > > > > s1 = Sens1 (connection) > > s2 = Sens2 (connection) > > while loop > -1: > > print 'Start of loop ', loop > > print 'S1 reading ' > > print 'temp = ', s1.temp > > print 'id = ', s1.id > > print 'present = ', s1.present > > print 'power = ', s1.power > > print 'S2 reading ' > > print 'temp = ', s2.temp > > print 'id = ', s2.id > > print 'present = ', s2.present > > print 'power = ', s2.power > > loop = loop + 1 > > > > > > ------------------------------------------------------------------------------ > > > > _______________________________________________ > > Owfs-developers mailing list > > Owfs-developers@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/owfs-developers > > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Owfs-developers mailing list > Owfs-developers@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/owfs-developers ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Owfs-developers mailing list Owfs-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/owfs-developers