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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
led.c File Reference

LED More...

`#include <libmoxa_rtu.h>`

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

## Detailed Description

LED

Copyright
  Moxa Inc.

Date
  04-10-2013

Author
  Eddy Kao

Version
  V1.0

    Introduction:
    Test LEDs with different colors.
    Example:
    ./led
    Help:

    root@Moxa:/tmp#./led -h
    LED program.

    Usage: ./led

Library:
LED APIs

## Function Documentation

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

/*******************************************************************************
* Copyright Moxa Inc.
*
* LED
*
* Date Author Comment
* 04-10-2013 Eddy Kao Created.
******************************************************************************/
#include <libmoxa_rtu.h>
int main(int argc, char *argv[])
{
char ch = 0;
char chIgnore = 0;
int retval = 0;
UINT32 rc = 0;
UINT8 state = 0;
while((retval = getopt(argc, argv, "h")) != -1)
{
switch(retval)
{
case '?':
case 'h':
default:
printf("LED program.\n\n");
printf("Usage: ./led\n\n");
return 0;
}
}
rc = MX_RTU_LED1_Set(LED_RED);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED1_Set(%d), return code = %d\r\n", LED_RED, rc);
rc = MX_RTU_LED1_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED1_Get(&state), return code = %d\r\n", rc);
else
{
printf("LED1 state = %d\r\n", state);
printf("\r\nPlease check LED1 state, and keyin 'c' to continue.\r\n");
ch = getchar();
while(1)
{
chIgnore = getchar();
if(chIgnore == 0xa) break;
}
if(ch != 'c')
{
printf("Unknow characters...\r\n");
exit(1);
}
}
rc = MX_RTU_LED1_Set(LED_GREEN);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED1_Set(%d), return code = %d\r\n", LED_GREEN, rc);
rc = MX_RTU_LED1_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED1_Get(&state), return code = %d\r\n", rc);
else
{
printf("LED1 state = %d\r\n", state);
printf("\r\nPlease check LED1 state, and keyin 'c' to continue.\r\n");
ch = getchar();
while(1)
{
chIgnore = getchar();
if(chIgnore == 0xa) break;
}
if(ch != 'c')
{
printf("Unknow characters...\r\n");
exit(1);
}
}
rc = MX_RTU_LED1_Set(LED_DARK);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED1_Set(%d), return code = %d\r\n", LED_DARK, rc);
rc = MX_RTU_LED1_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED1_Get(&state), return code = %d\r\n", rc);
else
{
printf("LED1 state = %d\r\n", state);
printf("\r\nPlease check LED1 state, and keyin 'c' to continue.\r\n");
ch = getchar();
while(1)
{
chIgnore = getchar();
if(chIgnore == 0xa) break;
}
if(ch != 'c')
{
printf("Unknow characters...\r\n");
exit(1);
}
}
rc = MX_RTU_LED2_Set(LED_RED);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED2_Set(%d), return code = %d\r\n", LED_RED, rc);
rc = MX_RTU_LED2_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED2_Get(&state), return code = %d\r\n", rc);
else
{
printf("LED2 state = %d\r\n", state);
printf("\r\nPlease check LED2 state, and keyin 'c' to continue.\r\n");
ch = getchar();
while(1)
{
chIgnore = getchar();
if(chIgnore == 0xa) break;
}
if(ch != 'c')
{
printf("Unknow characters...\r\n");
exit(1);
}
}
rc = MX_RTU_LED2_Set(LED_GREEN);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED2_Set(%d), return code = %d\r\n", LED_GREEN, rc);
rc = MX_RTU_LED2_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED2_Get(&state), return code = %d\r\n", rc);
else
{
printf("LED2 state = %d\r\n", state);
printf("\r\nPlease check LED2 state, and keyin 'c' to continue.\r\n");
ch = getchar();
while(1)
{
chIgnore = getchar();
if(chIgnore == 0xa) break;
}
if(ch != 'c')
{
printf("Unknow characters...\r\n");
exit(1);
}
}
rc = MX_RTU_LED2_Set(LED_DARK);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED2_Set(%d), return code = %d\r\n", LED_DARK, rc);
rc = MX_RTU_LED2_Get(&state);
if(rc != MISC_ERR_OK) printf("MX_RTU_LED2_Get(&state), return code = %d\r\n", rc);
else
{
printf("LED2 state = %d\r\n", state);
printf("\r\nPlease check LED2 state, and keyin 'q' to exit.\r\n");
ch = getchar();
while(1)
{
chIgnore = getchar();
if(chIgnore == 0xa) break;
}
if(ch != 'q')
{
printf("Unknow characters...\r\n");
exit(1);
}
}
return 0;
}