- Main
- Tutorials
- Library
- Samples

- File List
- Globals

Functions
tc_calibration.c File Reference

TC Calibration Sample More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <unistd.h>`
`#include <iothinx/iothinxio.h>`

Go to the source code of this file.

## Functions
int | main (int argc, char **const argv)

## Detailed Description

TC Calibration Sample

Copyright
  2019 Moxa Inc. All rights reserved.

Date
  2019-01-04

Author
  Eddy Chiu

Version
  V1.0

    Introduction:
    This is TC calibration sample code.
    Example:
    1. Using default: ./tc_calibration
    2. Setting TC slot, channel, type and temperature: ./tc_calibration -s7 -c2 -t2 -e36.5
    Default:
    Slot of TC module = 6
    TC channel = 0
    TC type = K type
    Calibration temperature = 0 degrees Celsius
    Help:

    moxa@Moxa:~$ sudo ./tc_calibration -h
    TC Calibration sample program.

    Usage: ./tc_calibration [OPTIONS]

    Options:
        -s      Slot of TC module. Default slot = 6
        -c      Channel on TC module. Default channel = 0
        -t      TC type. Default type = 1
        -e      Temperature in degrees Celsius. Default value = 0.000

Library:
TC APIs

Definition in file tc_calibration.c.

## Function Documentation

int main | ( | int | argc,
|  | char **const | argv
| ) |  |

/*******************************************************************************
* Copyright (C) 2019 Moxa Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* TC Calibration Sample Application
*
* Date Author Comment
* 2019-01-04 Eddy Chiu Created.
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iothinx/iothinxio.h>
int main(int argc, char **const argv)
{
int32_t rc;
uint32_t tc_slot = 6;
uint8_t tc_channel = 0;
uint8_t tc_type = TC_SENSOR_TYPE_K;
float tc_value;
float tc_calibration_temperature = 0.0f;
char ch;
while (-1 != (rc = getopt(argc, argv, "c:e:hs:t:")))
{
switch (rc)
{
case 'c':
tc_channel = atoi(optarg);
break;
case 'e':
tc_calibration_temperature = atof(optarg);
break;
case 's':
tc_slot = atoi(optarg);
break;
case 't':
tc_type = atoi(optarg);
break;
case 'h':
default:
printf("TC calibration sample program.\n\n");
printf("Usage: ./tc_calibration [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of TC module. Default slot = %d\n", "-s", tc_slot);
printf("\t%-8s TC channel. Default channel = %d\n", "-c", tc_channel);
printf("\t%-8s TC type. Default type = %d\n", "-t", tc_type);
printf("\t%-8s Setting temperature. Default temperature = %.3f\n", "-e", tc_calibration_temperature);
printf("\n");
return 0;
}
}
printf("TC slot = %lu\n", tc_slot);
printf("TC channel = %u\n", tc_channel);
printf("TC type = %d\n", tc_type);
printf("calibration temperature = %.3f\n", tc_calibration_temperature);
// initialize ioThinx I/O
rc = ioThinx_IO_Client_Init();
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_IO_Client_Init() = %d\n", rc);
return -1;
}
// temporarily set config
rc = ioThinx_TC_Config_SetSensorTypes(tc_slot, tc_channel, 1, &tc_type);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_TC_Config_SetSensorTypes() = %d\n", rc);
return -1;
}
// reload config
rc = ioThinx_IO_Config_Reload();
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_IO_Config_Reload() = %d\n", rc);
}
printf("\nAfter executing this program, a non-volatile offset will be set for the selected channel.\n");
printf("1. Ensure the sensor is connected.\n");
printf("2. Ensure the channel and its sensor type is correctly selected.\n");
printf("3. Put the sensor into a glass that contains a mixture of ice and water.\n");
printf("4. Do not remove the sensor from the ice water during calibration...\n");
printf("Continue ? (y/n): ");
ch = getchar();
if (ch == 'y')
{
// get TC value
rc = ioThinx_TC_GetValues(tc_slot, tc_channel, 1, &tc_value);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_TC_GetValues() = %d\n", rc);
}
else
{
printf("TC value before calibration: %.3f\n", tc_value);
}
// execute the API with zero degrees Celsius as input parameter
rc = ioThinx_TC_SetCalibrations(tc_slot, tc_channel, 1, &tc_calibration_temperature);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_TC_SetCalibrations() = %d\n", rc);
}
// wait for calibration ok
printf("Calibrating...\n");
sleep(3);
// get TC value
rc = ioThinx_TC_GetValues(tc_slot, tc_channel, 1, &tc_value);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_TC_GetValues() = %d\n", rc);
}
else
{
printf("TC value after calibration: %.3f\n", tc_value);
}
printf("Finish.\n");
}
else
{
printf("Abort.\n");
}
return 0;
}

Definition at line 54 of file tc_calibration.c.

55 {
56 int32_t rc;
57 uint32_t tc_slot = 6;
58 uint8_t tc_channel = 0;
59 uint8_t tc_type = TC_SENSOR_TYPE_K;
60 float tc_value;
61 float tc_calibration_temperature = 0.0f;
62 char ch;
63
64 while (-1 != (rc = getopt(argc, argv, "c:e:hs:t:")))
65 {
66 switch (rc)
67 {
68 case 'c':
69 tc_channel = atoi(optarg);
70 break;
71 case 'e':
72 tc_calibration_temperature = atof(optarg);
73 break;
74 case 's':
75 tc_slot = atoi(optarg);
76 break;
77 case 't':
78 tc_type = atoi(optarg);
79 break;
80 case 'h':
81 default:
82 printf("TC calibration sample program.\n\n");
83 printf("Usage: ./tc_calibration [OPTIONS]\n\n");
84 printf("Options:\n");
85 printf("\t%-8s Slot of TC module. Default slot = %d\n", "-s", tc_slot);
86 printf("\t%-8s TC channel. Default channel = %d\n", "-c", tc_channel);
87 printf("\t%-8s TC type. Default type = %d\n", "-t", tc_type);
88 printf("\t%-8s Setting temperature. Default temperature = %.3f\n", "-e", tc_calibration_temperature);
89 printf("\n");
90 return 0;
91 }
92 }
93
94 printf("TC slot = %lu\n", tc_slot);
95 printf("TC channel = %u\n", tc_channel);
96 printf("TC type = %d\n", tc_type);
97 printf("calibration temperature = %.3f\n", tc_calibration_temperature);
98
99 // initialize ioThinx I/O
100 rc = ioThinx_IO_Client_Init();
101 if (rc != IOTHINX_ERR_OK)
102 {
103 printf("ioThinx_IO_Client_Init() = %d\n", rc);
104 return -1;
105 }
106
107 // temporarily set config
108 rc = ioThinx_TC_Config_SetSensorTypes(tc_slot, tc_channel, 1, &tc_type);
109 if (rc != IOTHINX_ERR_OK)
110 {
111 printf("ioThinx_TC_Config_SetSensorTypes() = %d\n", rc);
112 return -1;
113 }
114
115 // reload config
116 rc = ioThinx_IO_Config_Reload();
117 if (rc != IOTHINX_ERR_OK)
118 {
119 printf("ioThinx_IO_Config_Reload() = %d\n", rc);
120 }
121
122 printf("\nAfter executing this program, a non-volatile offset will be set for the selected channel.\n");
123 printf("1. Ensure the sensor is connected.\n");
124 printf("2. Ensure the channel and its sensor type is correctly selected.\n");
125 printf("3. Put the sensor into a glass that contains a mixture of ice and water.\n");
126 printf("4. Do not remove the sensor from the ice water during calibration...\n");
127 printf("Continue ? (y/n): ");
128 ch = getchar();
129 if (ch == 'y')
130 {
131 // get TC value
132 rc = ioThinx_TC_GetValues(tc_slot, tc_channel, 1, &tc_value);
133 if (rc != IOTHINX_ERR_OK)
134 {
135 printf("ioThinx_TC_GetValues() = %d\n", rc);
136 }
137 else
138 {
139 printf("TC value before calibration: %.3f\n", tc_value);
140 }
141
142 // execute the API with zero degrees Celsius as input parameter
143 rc = ioThinx_TC_SetCalibrations(tc_slot, tc_channel, 1, &tc_calibration_temperature);
144 if (rc != IOTHINX_ERR_OK)
145 {
146 printf("ioThinx_TC_SetCalibrations() = %d\n", rc);
147 }
148
149 // wait for calibration ok
150 printf("Calibrating...\n");
151 sleep(3);
152
153 // get TC value
154 rc = ioThinx_TC_GetValues(tc_slot, tc_channel, 1, &tc_value);
155 if (rc != IOTHINX_ERR_OK)
156 {
157 printf("ioThinx_TC_GetValues() = %d\n", rc);
158 }
159 else
160 {
161 printf("TC value after calibration: %.3f\n", tc_value);
162 }
163 printf("Finish.\n");
164 }
165 else
166 {
167 printf("Abort.\n");
168 }
169
170 return 0;
171 }
TC_SENSOR_TYPE_K
#define TC_SENSOR_TYPE_K
Definition: iothinxio.h:805
IOTHINX_ERR_OK
#define IOTHINX_ERR_OK
Definition: iothinxio.h:35
ioThinx_TC_GetValues
IOTHINX_ERR ioThinx_TC_GetValues(uint32_t slot, uint8_t start, uint8_t count, float buf[])
ioThinx_TC_Config_SetSensorTypes
IOTHINX_ERR ioThinx_TC_Config_SetSensorTypes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
ioThinx_TC_SetCalibrations
IOTHINX_ERR ioThinx_TC_SetCalibrations(uint32_t slot, uint8_t start, uint8_t count, float buf[])
ioThinx_IO_Config_Reload
IOTHINX_ERR ioThinx_IO_Config_Reload(void)
ioThinx_IO_Client_Init
IOTHINX_ERR ioThinx_IO_Client_Init(void)