Skip to content
Snippets Groups Projects
Select Git revision
  • 07925fded16d2d3bd0d22dff57c9b511a846ee2d
  • main default protected
  • feat/RigolDP1308A
  • devel protected
  • feat/CAENHVPS_DT803x
  • feat/CAENHVPS
  • fdti-bugfix
  • testbeam
  • tmp_swint
  • addKeithley2230G
  • revert-9dfbb40f
  • xray_devel
  • add_NGP804
  • monitoring_watch_dog
  • kk_spift232h
  • add_CAEN_R803x_PS
  • kk_DS10CP154A
  • 2022-slac-testing
  • add_generator
  • kk_betsee
  • kk_pcf8591
  • 4.1.0
  • tag.4.devel
  • v4.0
  • v3.0
  • v2.0
  • v1.0
  • v0.2
  • v0.1
  • RALIrradNov2018
30 results

ntc_example.py

Blame
  • Daniel Joseph Antrim's avatar
    Daniel Joseph Antrim authored and Elisabetta Pianori committed
    ebe389a3
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ntc_example.py 2.33 KiB
    import labRemote
    from labRemote import devcom, com
    
    import time
    from argparse import ArgumentParser
    import sys
    
    import logging
    logging.basicConfig()
    logger = logging.getLogger("ntc_example")
    
    # Voltage powering the NTC
    NTC_VOLTAGE = 5.0
    # Resistance of resistor in voltage divider
    R_VOLTAGE_DIVIDER = 10000.0 # ohms
    # The total voltage across the voltage divider
    VOLTAGE_DIVIDER_REF = 5.0 # volts
    
    # Information specific to the NTC
    # Part number: 103KT1608
    # See https://www.datasheets360.com/pdf/6686957959228959166
    # ---------------------------------------------------------
    # Reference temperature in Kelvin
    NTC_REF_TEMP = 298.15
    # Resistance at reference temperature in ohms
    NTC_R_REF = 10000.0 # ohms
    # B value for NTC in Kelvin
    NTC_BETA = 3435
    
    def ntc_example(device, pin) :
    
        ##
        ## initialize the communication line
        ##
        try :
            serial = com.TextSerialCom(device, 9600)
        except :
            logger.error(f"Unable to initialize serial communication with device at port \"{device}\"")
            sys.exit(1)
        if serial is None :
            logger.error(f"Returned communication device is None")
            sys.exit(1)
        serial.setTermination("\r\n")
        serial.setTimeout(5)
        serial.init()
    
        ##
        ## initialize the NTCSensor object
        ##
        sensor = devcom.NTCSensor(pin, serial, NTC_REF_TEMP, NTC_R_REF, NTC_BETA, R_VOLTAGE_DIVIDER, VOLTAGE_DIVIDER_REF)
        sensor.init()
    
        ##
        ## perform measurements continuously
        ##
        while True:
            time.sleep(1)
            try:
                sensor.read();
            except RuntimeError as err:
                logger.error(f"Sensor read error: {err}, continuing...")
                continue
            temp = sensor.temperature()
            logger.info(f"Temperature measurement: {temp} C")
    
    if __name__ == "__main__":
    
        parser = ArgumentParser(description = "Example for how to use the NTCSensor class")
        parser.add_argument("device-port", type = str,
            help = "Port at which the device is connected (e.g. /dev/ttyAMC0)"
        )
        parser.add_argument("pin", type = str,
            help = "Pin on the sensor to sample from"
        )
        parser.add_argument("-d", "--debug", action = "count", default = 0,
            help = "Enable more verbose printout from labRemote"
        )
    
        args = parser.parse_args()
    
        for _ in range(args.debug) :
            labRemote.incrDebug()
    
        ntc_example(args.device_port, args.pin)