Hi mick,
congratulations at the first place !!!
Am Dienstag, den 06.04.2010, 21:15 +0100 schrieb Mick Sulley:
> Hi,
>
> Thanks to the help from Marcus and Pascal I am now able to read sensors
> on my network. Now the next question -
>
> I can run
>
> >>> root = Connection ("/dev/ttyD1")
> >>> s = root.find (type="DS18S20")[0]
> >>> print s
> <Sensor /10.0D54A9010800/ - DS18S20>
> >>> s.get("temperature")
> ' 19.125'
>
> and I read the temperature, but how can I read the temperature of a
> specific sensor? I get an error if I use
>
> >>> s = root.find (id="OD54A9010800")
returns an array with sensors ...
> >>> s.get("temperature")
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'list' object has no attribute 'get'
you forgot to access the first element of the array [0] - as you did
above also ...
but instead of using the index and doing the find everytime you access
the sensor's temperature you could use some classes instead:
class Sensor (object) :
id = None
def __init__ (connection)
self.conn = connection
self.sensor = connection.find (id = self.id)[0]
class TempSensor (Sensor) :
def temp (self) :
return float (self.sensor.get ("temperature"))
class LivingRoom (TempSensor) :
id = "OD54A9010800"
connection = Connection ("/dev/ttyD1")
room = LivingRoom (connection)
print room.temp ()
you could furthermore use the @property decorator on "temp" so that
"TempSensor" becomes:
class TempSensor (Sensor) :
@property
def temp (self) :
return float (self.sensor.get ("temperature"))
then you can access the temp as any other attribute and it gets fetched
in the background automatically ... like:
print room.temp
well, hopefully i have no typo in here ... ;)
have fun,
marcus.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers