Example #1
0
def update_temp():
    global ser, connected
    if connected == 0:
        top.after(
            5000,
            FindPort)  # Not connected, try to reconnect again in 5 seconds
        return
    try:
        strin = ser.readline(
        )  # Read the requested value, for example "+0.234E-3 VDC"
        ser.readline()  # Read and discard the prompt "=>"
        if len(strin) > 1:
            if strin[1] == '>':  # Out of sync?
                strin = ser.readline()  # Read the value again
        ser.write("MEAS1?\r\n")  # Request next value from multimeter
    except:
        connected = 0
        DMMout.set("----")
        Temp.set("----")
        portstatus.set("Communication Lost")
        DMM_Name.set("--------")
        top.after(5000, FindPort)  # Try to reconnect again in 5 seconds
        return
    strin_clean = strin.replace(
        "VDC",
        "")  # get rid of the units as the 'float()' function doesn't like it
    if len(strin_clean) > 0:
        DMMout.set(strin.replace("\r", "").replace(
            "\n", ""))  # display the information received from the multimeter

        try:
            val = float(
                strin_clean) * 1000.0  # Convert from volts to millivolts
            valid_val = 1
        except:
            valid_val = 0

        try:
            cj = float(CJTemp.get(
            ))  # Read the cold junction temperature in degrees centigrade
        except:
            cj = 0.0  # If the input is blank, assume cold junction temperature is zero degrees centigrade

        if valid_val == 1:
            ktemp = round(kconvert.mV_to_C(val, cj), 1)
            if ktemp < -200:
                Temp.set("UNDER")
            elif ktemp > 1372:
                Temp.set("OVER")
            else:
                Temp.set(ktemp)
        else:
            Temp.set("----")
    else:
        Temp.set("----")
        connected = 0
    top.after(
        500, update_temp
    )  # The multimeter is slow and the baud rate is slow: two measurement per second tops!
def data_gen():
    t = data_gen.t
    while True:

        strin = ser.readline()
        t += 1
        val = float(strin)
        #  val/=1000
        val *= 150
        val /= 33000
        val *= 3.3
        cj = 0
        val /= 255
        val *= 1000
        val = round(kconvert.mV_to_C(val, cj), 1)
        val = int(val)

        temp = str(val).zfill(4) + '\n'

        ser.write(temp.encode('ascii'))
        print(strin)
        print(val)
        val += 25
        yield t, val
Example #3
0
import kconvert
print("For 1 mV with cold junction at 24 C, temperature is:",
      round(kconvert.mV_to_C(1, 24.0), 2), "C")
Example #4
0
import kconvert

print("For 8.15 mV with cold junction at 22 C, temperature is:",
      round(kconvert.mV_to_C(1, 22.0), 1), "C")