'''
Copyright (C) 2019 Moxa Inc. All rights reserved.
SPDX-License-Identifier: Apache-2.0
RTD Calibration Python Sample Application
Date Author Comment
2019-02-11 William Chang Created it.
'''
from ioThinx_4530 import ioThinx_4530_API
import argparse
from time import sleep
RTD_SENSOR_TYPE_PT100 = 1
parser = argparse.ArgumentParser(description="RTD calibration sample program.")
parser.add_argument("-s", "--slot", dest="rtd_slot", type=int, default=8)
parser.add_argument("-c", "--channel", dest="rtd_channel", type=int, default=0)
parser.add_argument("-e", "--calibration_temperature", dest="rtd_calibration_temperature", type=int, default=0)
parser.add_argument("-t", "--type", dest="rtd_type", type=int, default=RTD_SENSOR_TYPE_PT100)
args = parser.parse_args()
rtd_slot = args.rtd_slot
rtd_channel = args.rtd_channel
rtd_calibration_temperature = args.rtd_calibration_temperature
rtd_type = args.rtd_type
print("RTD slot = {}".format(rtd_slot))
print("RTD channel = {}".format(rtd_channel))
print("RTD type = {}".format(rtd_type))
print("calibration temperature = {}".format(rtd_calibration_temperature))
device = ioThinx_4530_API.ioThinx_4530_API()
device.ioThinx_RTD_Config_SetSensorTypes(rtd_slot, rtd_channel, 1, [rtd_type])
device.ioThinx_IO_Config_Reload()
print("After executing this program, a non-volatile offset will be set for the selected channel.")
print("1. Ensure the sensor is connected.")
print("2. Ensure the channel and its sensor type is correctly selected.")
print("3. Put the sensor into a glass that contains a mixture of ice and water.")
print("4. Do not remove the sensor from the ice water during calibration...")
ch = input("Continue ? (y/n): ")
if ch == 'y':
rtd_value = device.ioThinx_RTD_GetValues(rtd_slot, rtd_channel, 1)
print("RTD value before calibration: {}".format(rtd_value))
device.ioThinx_RTD_SetCalibrations(rtd_slot, rtd_channel, 1, [rtd_calibration_temperature])
print("Calibrating...")
sleep(3)
rtd_value = device.ioThinx_RTD_GetValues(rtd_slot, rtd_channel, 1)
print("RTD value after calibration: {}".format(rtd_value))
print("Finish.")
else:
print("Abort.")
if __name__ == '__main__':