Reading data from the Arexx TL-500 on Linux

Some days ago I was looking for a temperature monitoring solution for some rooms and 19"-racks at the university. The Arexx TL-500 looked promising and I bought it. Unfortunately there are only Windows drivers available. But some people already analyzed the communication protocol and hacked a simple version of a linux driver:

http://www.algorithm-forge.com/techblog/2010/01/linux-usb-driver-for-the-arexx-tl-500-–-part-ii/

There's even a small logger hardware (ARM-based) using this device:

http://rndhax.blogspot.com/2010/03/friendlyarm-mini2440-arexx-tl-500.html

As a python fan I couldn't resist porting this to python to get a small and flexible script. It can be easily extended to save the data, create charts (maybe using matplotlib) or present a web interface.

By looking at the raw data I noticed that bytes 6 and 7 (maybe more?) contain a time value. Maybe it counts the seconds since the initialization of the device?

The first version of my script is mainly a port of the C program. The script uses pyusb 1.0, a python wrapper for libusb 1.0. You may have to install it manually, most linux distributions come with older versions.

Download
  1. #!/usr/bin/env python
  2. import usb.core, array, time
  3.  
  4. def getData(rawData):
  5. sensor = rawData[3] * 256 + rawData[2]
  6. tempRaw = rawData[4] * 256 + rawData[5]
  7. clock = rawData[7] * 256 + rawData[6]
  8. temp = 0.0078 * tempRaw
  9. return clock, sensor, tempRaw, temp
  10.  
  11. def collect(dev):
  12. dataDown = array.array('B', [0]*64)
  13. dataDown[0] = 4
  14. dev.write(0x1, dataDown, 0)
  15. dataDown[0] = 3
  16. while True:
  17. dev.write(0x1, dataDown, 0)
  18. rd = dev.read(0x81, 64, 0)
  19. if rd[1] != 0:
  20. d = getData(rd)
  21. print d
  22. logData(d, rd)
  23. time.sleep(10)
  24.  
  25. def logData(d, rd):
  26. tmp = "\t".join([str(i) for i in rd])
  27. logfile.write("%s\t%d\t%d\t%d\t%g\t%s\n" % (time.time(),
  28. d[0], d[1], d[2], d[3], tmp))
  29.  
  30. if __name__ == "__main__":
  31. dev = usb.core.find(idVendor=0x0451, idProduct=0x3211)
  32. logfile = open("temp.txt", "a")
  33. collect(dev)
  34.  

I plan to extend this to a python package using OO, cleaner interfaces, better error handling and more.


All comments of post - "Reading data from the Arexx TL-500 on Linux":

:Haha! I'am the first! Yeh~

Thank you!

Add a Comment / Trackback url

Comment begin from here or jump up!