int main(
int argc,
char **
const argv)
{
int rc, i;
UINT32 slotMin = 0, slotMax = 0;
int tcChannelAmount = 8;
int tcTypeAmount = 11;
float fTemper = 0.0f;
float fEngVal = 0.0f;
char ch = 0;
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");
printf("MX_RTU_Module_TC_Type_Set(%d, %d, %d), return code = %d.\n",
tcSlot, tcChannel, 1, rc);
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);
printf("MX_RTU_Module_TC_Calibration_Set(%d, %d, %d), return code = %d.\n",
tcSlot, tcChannel, 1, rc);
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;
}