Python module for interfacing with D5000 series thermocouple
This is a python module for interfacing with a D5000 series data acquisition module. It was written to provide a python interface for the D5000 Series command set via the serial port. Included are a small suite of programs which provide usage examples and a simple tcp/ip client/server for remote readings.
In order to use this module you must have pySerial installed: it does all the heavy lifting. Pyserial is available here.
This module is largely based on an older project of mine: tsb (telnet to serial bridge). If you are looking for a more general purpose pySerial example, you might want to look there.
This is the module itself. It provides the classes 'sensor' and 'module'. In this vocabulary, a 'sensor' maps to the physical d5000 device that is attached to the serial port, and a 'module' refers to a specific query-able device attached to the 'sensor' at a specified address.
Usage: sensorname = d5000_sensor("OPTIONS") ... connects to a d5000 series sensor with the specified com port addressing: Serial Options: -p, --port : Specify the desired serial port. (0 for COM1, 1 for COM2 etc) -r, --baudrate : Specify baudrate -s, --bytesize : Specify bytesize -y, --parity : Specify parity options -b, --stopbits : Specify number of stopbits -t, --timeout : Specify timeout -f, --flow : Specify flow-control options ... once thats done, you can use: sensorname.sendcmd("command", "address", "prompt") to query the device. The raw response on the serial port is returned, you have to handle that yourself. Spec says its just a string, so that should be fine.
Example 1: stresstest
This script is essentially a timing run. It was used during testing to see what kinds of speed could be expected from the module. Optimizing for speed turned out to be largely fruitless: the largest slice of time was the delay when waiting for the response over the serial port.
C:\Documents and Settings\Eli\Desktop>c:\Python23\python.exe stress_sensor.py Stress Sensor -------------- Connect to the thermocouple over and over and display how long the readings take to complete. -------------- Starting... Initializing the com port... ...OK Setting up the individual module... ...OK Sending the command 'RD'... Output from the RD command is: *+00022.00 Now, sending the RD command 10 times... Done! We took: 0.259577683756 s, thats 0.0259577683756 s per reading Now, sending the RD command 10 times... Done! We took: 0.255531359433 s, thats 0.0255531359433 s per reading Now, sending the RD command 10 times... Done! We took: 0.256611105601 s, thats 0.0256611105601 s per reading Now, sending the RD command 100 times... Done! We took: 2.88553461404 s, thats 0.0288553461404 s per reading Now, sending the RD command 1000 times... Done! We took: 29.4128815254 s, thats 0.0294128815254 s per reading
Example 2: watch temperature
An example script for taking readings over time. It loops forever, printing a line to the console if it detects a change in temperature.
(while forcing a change in readings by holding and then releasing the lead)
C:\Documents and Settings\Eli\Desktop>c:\Python23\python.exe watch_temperature.py Watch Temperature ----------------- Connect to thermocouple on COM1 and take continuous readings, reporting any changes to the console. ----------------- Starting Example... press control-c to exit Temperature UP..... current - 22.0 min - 22.0 max - 22.0 Temperature UP..... current - 23.0 min - 22.0 max - 23.0 Temperature UP..... current - 24.0 min - 22.0 max - 24.0 Temperature UP..... current - 25.0 min - 22.0 max - 25.0 Temperature UP..... current - 26.0 min - 22.0 max - 26.0 Temperature UP..... current - 27.0 min - 22.0 max - 27.0 Temperature DOWN... current - 26.0 min - 22.0 max - 27.0 Temperature DOWN... current - 25.0 min - 22.0 max - 27.0 Temperature DOWN... current - 24.0 min - 22.0 max - 27.0 Temperature DOWN... current - 23.0 min - 22.0 max - 27.0 ... (KeyboardInterrupt)
Example 3: tcp/ip client/server
An example client/server pair for reading thermocouple readings remotely over the network. (thermoserver could also be used with e.g. telnet, its just spitting raw text through the socket when a connection is made). The server will run forever, spitting out the current reading when it is queried and then closing the connection.