No Description

t3311.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/python
  2. # Author: Jon Trulson <jtrulson@ics.com>
  3. # Copyright (c) 2016 Intel Corporation.
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining
  6. # a copy of this software and associated documentation files (the
  7. # "Software"), to deal in the Software without restriction, including
  8. # without limitation the rights to use, copy, modify, merge, publish,
  9. # distribute, sublicense, and/or sell copies of the Software, and to
  10. # permit persons to whom the Software is furnished to do so, subject to
  11. # the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be
  14. # included in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. import time, sys, signal, atexit
  24. import pyupm_t3311 as sensorObj
  25. ## Exit handlers ##
  26. # This function stops python from printing a stacktrace when you hit control-C
  27. def SIGINTHandler(signum, frame):
  28. raise SystemExit
  29. # This function lets you run code on exit
  30. def exitHandler():
  31. print "Exiting"
  32. sys.exit(0)
  33. # Register exit handlers
  34. atexit.register(exitHandler)
  35. signal.signal(signal.SIGINT, SIGINTHandler)
  36. defaultDev = "/dev/ttyUSB0"
  37. # if an argument was specified, use it as the device instead
  38. if (len(sys.argv) > 1):
  39. defaultDev = sys.argv[1]
  40. print "Initializing..."
  41. # Instantiate an T3311 instance, using MODBUS slave address 1, and
  42. # default comm parameters (9600, 8, N, 2)
  43. sensor = sensorObj.T3311(defaultDev, 1)
  44. # output the serial number and firmware revision
  45. print "Serial Number:", sensor.getSerialNumber()
  46. print "Firmware Revision: {0}.{1}".format(sensor.getFirmwareMajor(),
  47. sensor.getFirmwareMinor())
  48. print
  49. # update and print available values every second
  50. while (1):
  51. # update our values from the sensor
  52. sensor.update()
  53. # we show both C and F for temperature
  54. print "Temperature:", sensor.getTemperature(), "C /",
  55. print sensor.getTemperature(True), "F"
  56. print "Humidity:", sensor.getHumidity(), "%"
  57. # this value depends on the sensor configuration -- by default
  58. # it is the dew point temperature
  59. print "Computed Value:", sensor.getComputedValue()
  60. # with FW revisions > 2.44, extended computed data is available
  61. if (sensor.extendedDataAvailable()):
  62. print "Dew Point Temperature:", sensor.getDewPointTemperature(),
  63. print "C /", sensor.getDewPointTemperature(True), "F"
  64. print "Absolute Humidity:", sensor.getAbsoluteHumidity(), "g/m3"
  65. print "Specific Humidity:", sensor.getSpecificHumidity(),
  66. print "g/kg"
  67. print "Mixing Ratio:", sensor.getMixingRatio(), "g/kg"
  68. print "Specific Enthalpy:", sensor.getSpecificEnthalpy(),
  69. print "kJ/kg"
  70. print
  71. time.sleep(1)