#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 di_slot = 1;
uint8_t di_channel = 0;
uint16_t di_filter = 2;
uint32_t di_values = 0;
char ch;
while (-1 != (rc = getopt(argc, argv, "c:f:hs:")))
{
switch (rc)
{
case 'c':
di_channel = atoi(optarg);
break;
case 'f':
di_filter = atoi(optarg);
break;
case 's':
di_slot = atoi(optarg);
break;
case 'h':
default:
printf("DI sample program.\n\n");
printf("Usage: ./di [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of DI module. Default slot = %d\n", "-s", di_slot);
printf("\t%-8s DI channel. Default channel = %d\n", "-c", di_channel);
printf("\t%-8s Filter of DI module. Default filter = %d\n", "-f", di_filter);
printf("\t%-8s (One unit = 500us)\n", "");
printf("\n");
return 0;
}
}
printf("DI slot = %lu\n", di_slot);
printf("DI channel = %u\n", di_channel);
printf("DI filter = %u\n", di_filter);
{
printf("ioThinx_IO_Client_Init() = %d\n", rc);
return -1;
}
{
printf("ioThinx_DI_Config_SetFilters() = %d\n", rc);
}
{
printf("ioThinx_IO_Config_Reload() = %d\n", rc);
}
do
{
{
printf("ioThinx_DI_GetValues() = %d\n", rc);
break;
}
printf("[%lu] di_values = 0x%x\n", di_slot, di_values);
printf("[%lu:%u] di_val = %x\n", di_slot, di_channel, (di_values >> di_channel) & 0x1);
ch = getchar();
}
while (ch != 'q');
return 0;
}
57 uint8_t di_channel = 0;
58 uint16_t di_filter = 2;
59 uint32_t di_values = 0;
62 while (-1 != (rc = getopt(argc, argv,
"c:f:hs:")))
67 di_channel = atoi(optarg);
70 di_filter = atoi(optarg);
73 di_slot = atoi(optarg);
77 printf(
"DI sample program.\n\n");
78 printf(
"Usage: ./di [OPTIONS]\n\n");
80 printf(
"\t%-8s Slot of DI module. Default slot = %d\n",
"-s", di_slot);
81 printf(
"\t%-8s DI channel. Default channel = %d\n",
"-c", di_channel);
82 printf(
"\t%-8s Filter of DI module. Default filter = %d\n",
"-f", di_filter);
83 printf(
"\t%-8s (One unit = 500us)\n",
"");
89 printf(
"DI slot = %lu\n", di_slot);
90 printf(
"DI channel = %u\n", di_channel);
91 printf(
"DI filter = %u\n", di_filter);
97 printf(
"ioThinx_IO_Client_Init() = %d\n", rc);
105 printf(
"ioThinx_DI_Config_SetFilters() = %d\n", rc);
112 printf(
"ioThinx_IO_Config_Reload() = %d\n", rc);
120 printf(
"ioThinx_DI_GetValues() = %d\n", rc);
123 printf(
"[%lu] di_values = 0x%x\n", di_slot, di_values);
124 printf(
"[%lu:%u] di_val = %x\n", di_slot, di_channel, (di_values >> di_channel) & 0x1);
IOTHINX_ERR ioThinx_DI_Config_SetFilters(uint32_t slot, uint8_t start, uint8_t count, uint16_t buf[])
IOTHINX_ERR ioThinx_IO_Config_Reload(void)
IOTHINX_ERR ioThinx_DI_GetValues(uint32_t slot, uint32_t *p_values)
IOTHINX_ERR ioThinx_IO_Client_Init(void)