Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- import time
- import datetime
- import serial
- from decimal import *
- import thread
- import os, sys
- import struct
- TTY_IR = '/dev/ttyUSB0'
- # Voltcraft IR thermometer serial communication initialization
- ser = serial.Serial()
- ser.baudrate = 9600
- ser.port = TTY_IR
- try:
- ser.open()
- except:
- print "Thermometer is not connected, can't open /dev/ttyUSB0"
- sys.exit()
- # ### INITIALIZATION ###
- # read line to overcome possible corrupted data
- def detect_frame():
- print "> Detecting frame"
- while True:
- data = ser.read(1)
- if data[0].encode('hex') == "aa":
- print "> Frame Detected"
- break
- detect_frame()
- # Voltcraft IR 2200-50D USB data stream decoding (should be compatible with other Voltcraft IR USB thermometers)
- def temp_get_ir():
- data = ""
- # read data from the serial port - 17 bytes
- try:
- data = ser.read(17)
- #for character in data:
- # print character.encode('hex'),
- if data[16].encode('hex') != "aa":
- print "> Frame Lost"
- detect_frame()
- return temp
- except:
- print "> IR Data stream failed?"
- return (float (struct.unpack("<L", data[4]+""+data[3]+"\x00\x00")[0]) / 10, float (struct.unpack("<L", data[6]+""+data[5]+"\x00\x00")[0]) / 10)
- # get data from IR and TC
- data = temp_get_ir()
- temp_ir = data[0]
- temp_tc = data[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement