| ioPAC RTU Controllers C/C++ Sample Code Programming Guide

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
tc_calibration.c File Reference

TC Calibration Sample More...

`#include <libmoxa_rtu.h>`

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

## Detailed Description

TC Calibration Sample

Copyright
  Moxa Inc.

Date
  06-11-2014

Author
  Wanhan Hsieh

Version
  V1.0
  TC Calibration Sample

    Introduction:
    This is an TC calibration sample code.
    Example:
    1. Using default: ./tc_calibration
    2. Setting TC slot and channel only: ./tc -i5 -c3
    Default:
    Slot of TC module = 1
    Channel on TC module = 0
    Help:

    root@Moxa:/tmp#./tc_calibration -h
    TC calibration sample program.

    Usage: ./tc_calibration [OPTIONS]

    Options:
        -c       Channel on TC module [0-7]. Default channel = 0
        -e       Temperature in degrees Celsius. Default value = 0.000
        -i       Slot of TC module [0-9]. Default slot = 1
        -t       TC type [0-10]. Default type = 5

Library:
TC APIs

## Function Documentation

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

/*******************************************************************************
* Copyright Moxa Inc.
*
* TC Ice Point Calibration Sample Application
*
* Date Author Comment
* 06-11-2014 Wanhan Hsieh Created.
******************************************************************************/
#include <libmoxa_rtu.h>
int main(int argc, char **const argv)
{
int rc, i;
UINT32 tcSlot = 1;
UINT32 slotMin = 0, slotMax = 0;
UINT32 tcChannel = 0;
int tcChannelAmount = 8;
UINT8 tcType = TC_TYPE_J;
int tcTypeAmount = 11;
float fTemper = 0.0f;
float fEngVal = 0.0f;
char ch = 0;
MX_RTU_Total_Slots_Get(&slotMax);
while(-1 != (rc = getopt(argc, argv, "c:e:hi:t:")))
{
switch(rc)
{
case 'c':
tcChannel = atoi(optarg);
if(tcChannel < 0 || tcChannel >= tcChannelAmount)
{
printf("Error parameter: channel: %d\n", tcChannel);
return -1;
}
break;
case 'e':
fTemper = atof(optarg);
break;
case 'i':
tcSlot = atoi(optarg);
if(tcSlot < slotMin || tcSlot > slotMax)
{
printf("Error parameter: slot: %d\n", tcSlot);
return -1;
}
break;
case 't':
tcType = atoi(optarg);
if(tcType < 0 || tcType >= tcTypeAmount)
{
printf("Error parameter: type: %d\n", tcType);
return -1;
}
break;
case '?':
case 'h':
default:
printf("TC calibration sample program.\n\n");
printf("Usage: ./tc_calibration [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Channel on TC module [%d-%d]. Default channel = %d\n",
"-c", 0, tcChannelAmount - 1, tcChannel);
printf("\t%-8s Temperature in degrees Celsius. Default value = %.3f\n",
"-e", fTemper);
printf("\t%-8s Slot of TC module [%d-%d]. Default slot = %d\n",
"-i", slotMin, slotMax, tcSlot);
printf("\t%-8s TC type [%d-%d]. Default type = %d\n",
"-t", 0, tcTypeAmount - 1, tcType);
printf("\n");
return 0;
}
}
printf("%-10s: %d\n", "TC slot", tcSlot);
printf("%-10s: %d\n", "TC channel", tcChannel);
printf("%-10s: %d\n", "TC type", tcType);
printf("%-10s: %.3f\n", "Temperature", fTemper);
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')
{
printf("Calibrating...\n");
// Config TC module
rc = MX_RTU_Module_TC_Type_Set(tcSlot, tcChannel, 1, &tcType);
if(rc != MODULE_RW_ERR_OK)
printf("MX_RTU_Module_TC_Type_Set(%d, %d, %d), return code = %d.\n",
tcSlot, tcChannel, 1, rc);
// get TC value
rc = MX_RTU_Module_TC_Eng_Value_Get(tcSlot, tcChannel, 1, &fEngVal, NULL);
if(rc != MODULE_RW_ERR_OK)
printf("MX_RTU_Module_TC_Eng_Value_Get(%d, %d, %d), return code = %d.\n",
tcSlot, tcChannel, 1, rc);
else
printf("TC value before calibration: %.3f\n", fEngVal);
// Excute the API with zero degrees Celsius as input parameter
rc = MX_RTU_Module_TC_Calibration_Set(tcSlot, tcChannel, 1, &fTemper);
if(rc != MODULE_RW_ERR_OK)
printf("MX_RTU_Module_TC_Calibration_Set(%d, %d, %d), return code = %d.\n",
tcSlot, tcChannel, 1, rc);
// get TC value
rc = MX_RTU_Module_TC_Eng_Value_Get(tcSlot, tcChannel, 1, &fEngVal, NULL);
if(rc != MODULE_RW_ERR_OK)
printf("MX_RTU_Module_TC_Eng_Value_Get(%d, %d, %d), return code = %d.\n",
tcSlot, tcChannel, 1, rc);
else
printf("TC value after calibration : %.3f\n", fEngVal);
printf("Finish.\n");
}
else
{
printf("Abort.\n");
}
return 0;
}