- Main
- Tutorials
- Library
- Samples

- File List
- Globals

tc.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2019 Moxa Inc. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * TC Sample Application
6 *
7 * Date Author Comment
8 * 2018-12-27 Eddy Chiu Created it.
9 ******************************************************************************/
10
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <unistd.h>
48 #include <iothinx/iothinxio.h>
49
51 int main(int argc, char **const argv)
52 {
53 int32_t rc;
54 uint32_t tc_slot = 6;
55 uint8_t tc_channel_start = 0;
56 uint8_t tc_channel_count = 2;
57 uint8_t tc_types[8];
58 float tc_values[8];
59 uint8_t tc_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 tc_slot = atoi(optarg);
69 break;
70 case 'c':
71 tc_channel_start = atoi(optarg);
72 break;
73 case 'n':
74 tc_channel_count = atoi(optarg);
75 break;
76 case 'h':
77 default:
78 printf("TC sample program.\n\n");
79 printf("Usage: ./tc [OPTIONS]\n\n");
80 printf("Options:\n");
81 printf("\t%-8s Slot of TC module. Default slot = %d\n", "-s", tc_slot);
82 printf("\t%-8s TC start channel. Default channel = %d\n", "-c", tc_channel_start);
83 printf("\t%-8s TC channel count. Default count = %d\n", "-n", tc_channel_count);
84 printf("\n");
85 return 0;
86 }
87 }
88
89 printf("TC slot = %lu\n", tc_slot);
90 printf("TC start channel = %u\n", tc_channel_start);
91 printf("TC channel count = %u\n", tc_channel_count);
92
93 // initialize ioThinx I/O
94 rc = ioThinx_IO_Client_Init();
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 < tc_channel_count; i++)
103 {
104 tc_types[i] = TC_SENSOR_TYPE_K;
105 }
106 rc = ioThinx_TC_Config_SetSensorTypes(tc_slot, tc_channel_start, tc_channel_count, tc_types);
107 if (rc != IOTHINX_ERR_OK)
108 {
109 printf("ioThinx_TC_Config_SetSensorTypes() = %d\n", rc);
110 }
111
112 // reload config
113 rc = ioThinx_IO_Config_Reload();
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_TC_GetValues(tc_slot, tc_channel_start, tc_channel_count, tc_values);
123 if (rc != IOTHINX_ERR_OK)
124 {
125 printf("ioThinx_TC_GetValues() = %d\n", rc);
126 break;
127 }
128 rc = ioThinx_TC_GetStatuss(tc_slot, tc_channel_start, tc_channel_count, tc_statuss);
129 if (rc != IOTHINX_ERR_OK)
130 {
131 printf("ioThinx_TC_GetStatuss() = %d\n", rc);
132 break;
133 }
134 for (i = 0; i < tc_channel_count; i++)
135 {
136 printf("[%lu:%u] value = %.2f, status = %d\n", tc_slot, tc_channel_start+i, tc_values[i], tc_statuss[i]);
137 }
138 ch = getchar();
139 }
140 while (ch != 'q');
141
142 return 0;
143 }
TC_SENSOR_TYPE_K
#define TC_SENSOR_TYPE_K
Definition: iothinxio.h:706
main
int main(int argc, char **const argv)
Definition: tc.c:51
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_GetStatuss
IOTHINX_ERR ioThinx_TC_GetStatuss(uint32_t slot, uint8_t start, uint8_t count, uint8_t buf[])
ioThinx_IO_Config_Reload
IOTHINX_ERR ioThinx_IO_Config_Reload(void)
ioThinx_IO_Client_Init
IOTHINX_ERR ioThinx_IO_Client_Init(void)