Here is a sample program that starts a stream from the HDC1000EVM, reads 100 returns and stops the stream:
import serial
#sample program to read Texas Instruments HDC1000EVM
#initialization and open the port
#possible timeout values:
# 1. None: wait forever, block call
# 2. 0: non-blocking mode, return immediately
# 3. x, x is bigger than 0, float allowed, timeout block call
ser = serial.Serial()
#ser.port = "/dev/ttyUSB0"
#ser.port = "COM4:"
#ser.port = "/dev/ttyACM1"
ser.port = "/dev/serial/by-path/platform-bcm2708_usb-usb-0:1.2:1.0"
ser.baudrate = 115200
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
#ser.timeout = 1 #non-block read
ser.timeout = 2 #timeout block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2 #timeout for write
try:
ser.open()
except Exception as e:
print ("error open serial port: " + str(e))
exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput()#flush output buffer, aborting current output
#and discard all that is in buffer
#write data
#ser.write(bytes(43))
ser.write(serial.to_bytes([0x33]))
numOfLines = 0
while True:
response = ser.readline()
if (str(response).find(",") == -1):
print("start data: " + str(response))
else:
print(" Temperature: " + str(("{0:.2f}".format(((float(int((str(response).split(',')[0]),16))/float(65536)) * 165) -40)))+ u"\u00B0" + "C")
print(" Temperature: " + str(("{0:.2f}".format((((((float(int((str(response).split(',')[0]),16))/float(65536)) * 165) -40) * 9) / 5) + 32)))+ u"\u00B0" + "F")
print("Relative Humidity: " + str(("{0:.2f}".format((float(int((str(response).split(',')[1]),16))/float(65536)) * 100)))+ "%")
numOfLines = numOfLines + 1
if (numOfLines >= 100):
#ser.write(bytes(44))
ser.write(bytes(52))
response = ser.readline()
print("read data: " + str(response))
break
ser.close()
except Exception as e1:
print ("error " + str(e1))
ser.write(serial.to_bytes([0x34]))
response = ser.readline()
print("last data: " + str(response))
ser.close()
else:
print ("cannot open serial port ")