Functions
rtd.c File Reference

RTD 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

RTD Sample

Date
2018-12-27
Author
Eddy Chiu
Version
V1.0
Introduction:
This is RTD sample code.
Example:
1. Using default: ./rtd
2. Setting RTD slot and channel: ./rtd -s6 -c2 -n3
Default:
Slot of RTD module = 1
RTD channel = 0
Help:
moxa@Moxa:~$ sudo ./rtd -h
RTD sample program.

Usage: ./rtd [OPTIONS]

Options:
    -s       Slot of RTD module. Default slot = 5
    -c       RTD start channel. Default channel = 0
    -n       RTD channel count. Default count = 2

Library:
RTD APIs

Definition in file rtd.c.

Function Documentation

◆ main()

int main ( int  argc,
char **const  argv 
)
/*******************************************************************************
* Copyright (C) 2019 Moxa Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* RTD Sample Application
*
* Date Author Comment
* 2018-12-27 Eddy Chiu Created it.
******************************************************************************/
#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 rtd_slot = 5;
uint8_t rtd_channel_start = 0;
uint8_t rtd_channel_count = 2;
uint8_t rtd_types[8];
float rtd_values[8];
uint8_t rtd_statuss[8];
int32_t i;
char ch;
while (-1 != (rc = getopt(argc, argv, "c:n:hs:")))
{
switch (rc)
{
case 's':
rtd_slot = atoi(optarg);
break;
case 'c':
rtd_channel_start = atoi(optarg);
break;
case 'n':
rtd_channel_count = atoi(optarg);
break;
case 'h':
default:
printf("RTD sample program.\n\n");
printf("Usage: ./rtd [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of RTD module. Default slot = %d\n", "-s", rtd_slot);
printf("\t%-8s RTD start channel. Default channel = %d\n", "-c", rtd_channel_start);
printf("\t%-8s RTD channel count. Default count = %d\n", "-n", rtd_channel_count);
printf("\n");
return 0;
}
}
printf("RTD slot = %lu\n", rtd_slot);
printf("RTD start channel = %u\n", rtd_channel_start);
printf("RTD channel count = %u\n", rtd_channel_count);
// initialize ioThinx I/O
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_IO_Client_Init() = %d\n", rc);
return -1;
}
// temporarily set config
for (i = 0; i < rtd_channel_count; i++)
{
rtd_types[i] = RTD_SENSOR_TYPE_PT100;
}
rc = ioThinx_RTD_Config_SetSensorTypes(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_types);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_RTD_Config_SetSensorTypes() = %d\n", rc);
}
// reload config
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_IO_Config_Reload() = %d\n", rc);
}
// get value
do
{
rc = ioThinx_RTD_GetValues(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_values);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_RTD_GetValues() = %d\n", rc);
break;
}
rc = ioThinx_RTD_GetStatuss(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_statuss);
if (rc != IOTHINX_ERR_OK)
{
printf("ioThinx_RTD_GetStatuss() = %d\n", rc);
break;
}
for (i = 0; i < rtd_channel_count; i++)
{
printf("[%lu:%u] value = %.2f, status = %d\n", rtd_slot, rtd_channel_start+i, rtd_values[i], rtd_statuss[i]);
}
ch = getchar();
}
while (ch != 'q');
return 0;
}

Definition at line 51 of file rtd.c.

52 {
53  int32_t rc;
54  uint32_t rtd_slot = 5;
55  uint8_t rtd_channel_start = 0;
56  uint8_t rtd_channel_count = 2;
57  uint8_t rtd_types[8];
58  float rtd_values[8];
59  uint8_t rtd_statuss[8];
60  int32_t i;
61  char ch;
62 
63  while (-1 != (rc = getopt(argc, argv, "c:n:hs:")))
64  {
65  switch (rc)
66  {
67  case 's':
68  rtd_slot = atoi(optarg);
69  break;
70  case 'c':
71  rtd_channel_start = atoi(optarg);
72  break;
73  case 'n':
74  rtd_channel_count = atoi(optarg);
75  break;
76  case 'h':
77  default:
78  printf("RTD sample program.\n\n");
79  printf("Usage: ./rtd [OPTIONS]\n\n");
80  printf("Options:\n");
81  printf("\t%-8s Slot of RTD module. Default slot = %d\n", "-s", rtd_slot);
82  printf("\t%-8s RTD start channel. Default channel = %d\n", "-c", rtd_channel_start);
83  printf("\t%-8s RTD channel count. Default count = %d\n", "-n", rtd_channel_count);
84  printf("\n");
85  return 0;
86  }
87  }
88 
89  printf("RTD slot = %lu\n", rtd_slot);
90  printf("RTD start channel = %u\n", rtd_channel_start);
91  printf("RTD channel count = %u\n", rtd_channel_count);
92 
93  // initialize ioThinx I/O
95  if (rc != IOTHINX_ERR_OK)
96  {
97  printf("ioThinx_IO_Client_Init() = %d\n", rc);
98  return -1;
99  }
100 
101  // temporarily set config
102  for (i = 0; i < rtd_channel_count; i++)
103  {
104  rtd_types[i] = RTD_SENSOR_TYPE_PT100;
105  }
106  rc = ioThinx_RTD_Config_SetSensorTypes(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_types);
107  if (rc != IOTHINX_ERR_OK)
108  {
109  printf("ioThinx_RTD_Config_SetSensorTypes() = %d\n", rc);
110  }
111 
112  // reload config
114  if (rc != IOTHINX_ERR_OK)
115  {
116  printf("ioThinx_IO_Config_Reload() = %d\n", rc);
117  }
118 
119  // get value
120  do
121  {
122  rc = ioThinx_RTD_GetValues(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_values);
123  if (rc != IOTHINX_ERR_OK)
124  {
125  printf("ioThinx_RTD_GetValues() = %d\n", rc);
126  break;
127  }
128  rc = ioThinx_RTD_GetStatuss(rtd_slot, rtd_channel_start, rtd_channel_count, rtd_statuss);
129  if (rc != IOTHINX_ERR_OK)
130  {
131  printf("ioThinx_RTD_GetStatuss() = %d\n", rc);
132  break;
133  }
134  for (i = 0; i < rtd_channel_count; i++)
135  {
136  printf("[%lu:%u] value = %.2f, status = %d\n", rtd_slot, rtd_channel_start+i, rtd_values[i], rtd_statuss[i]);
137  }
138  ch = getchar();
139  }
140  while (ch != 'q');
141 
142  return 0;
143 }
IOTHINX_ERR ioThinx_RTD_Config_SetSensorTypes(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
#define IOTHINX_ERR_OK
Definition: iothinxio.h:35
IOTHINX_ERR ioThinx_RTD_GetValues(uint32_t slot, uint8_t start, uint8_t count, float buf[])
IOTHINX_ERR ioThinx_RTD_GetStatuss(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
IOTHINX_ERR ioThinx_IO_Config_Reload(void)
#define RTD_SENSOR_TYPE_PT100
Definition: iothinxio.h:942
IOTHINX_ERR ioThinx_IO_Client_Init(void)