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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Functions
fram.c File Reference

FRAM More...

`#include <libmoxa_rtu.h>`

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

## Detailed Description

FRAM

Copyright
  Moxa Inc.

Date
  04-10-2013

Author
  Eddy Kao

Version
  V1.0

    Introduction:
    Logging an AI value on FRAM with battery backup.
    Example:
    1. Using default: ./fram
    2. Setting AI: ./fram -s2 -c1
    Default:
    AI Slot = 1
    AI Channel = 0
    FRAM Address = 0x0
     FRAM_START_ADDRESS
     FRAM_END_ADDRESS
    Help:

    root@Moxa:/tmp#./fram -h
    FRAM RW program.

    Usage: ./fram [OPTIONS]

    Options:
            -s       AI slot [0-9]. Default AI slot = 1
                     (slot 0: Built-in IO, slot 1 ~ 9: IO Module)
            -c       AI channel [0-24]. Default AI channel = 0
            -a       FRAM Address [0x0-0x20000]. Default FRAM Address = 0x0

Library:
FRAM APIs

## Function Documentation

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

/*******************************************************************************
* Copyright Moxa Inc.
*
* FRAM
*
* Date Author Comment
* 04-10-2013 Eddy Kao Created.
******************************************************************************/
#include <libmoxa_rtu.h>
int main(int argc, char *argv[])
{
int retval = 0;
UINT32 rc = 0;
UINT8 aiSlot = 1;
UINT8 aiChannel = 0;
float aiValue = 0.0;
UINT32 framAddress = 0x0;
float framData = 0.0;
struct Timestamp time;
while((retval = getopt(argc, argv, "hs:c:a:")) != -1)
{
switch(retval)
{
case 's':
aiSlot = atoi(optarg);
if(aiSlot > MAX_SLOT)
{
printf("Error AI slot = %d\r\n", aiSlot);
exit(1);
}
break;
case 'c':
aiChannel = atoi(optarg);
if(aiChannel > MAX_SLOT)
{
printf("Error AI channel = %d\r\n", aiChannel);
exit(1);
}
break;
case 'a':
framAddress = atoi(optarg);
if(framAddress >= FRAM_END_ADDRESS)
{
printf("Error FRAM Address = %d\r\n", framAddress);
exit(1);
}
break;
case '?':
case 'h':
default:
printf("FRAM RW program.\n\n");
printf("Usage: ./fram [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s AI slot [%d-%d]. Default AI slot = %d\n", "-s", 0, MAX_SLOT, aiSlot);
printf("\t%-8s (slot 0: Built-in IO, slot 1 ~ 9: IO Module)\n", "");
printf("\t%-8s AI channel [%d-%d]. Default AI channel = %d\n", "-c", 0, MAX_CHANNEL, aiChannel);
printf("\t%-8s FRAM Address [0x%x-0x%x]. Default FRAM Address = 0x%x\n", "-a", FRAM_START_ADDRESS, FRAM_END_ADDRESS, framAddress);
printf("\n");
return 0;
}
}
//Power Off Test
rc = MX_RTU_FRAM_Read(framAddress, sizeof(framData), (UINT8 *)&framData);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_FRAM_Read(%d, %d, &framData), return code = %d\r\n", framAddress, sizeof(framData), rc);
exit(1);
}
else
{
printf("AI Slot = %d, Channel = %d, Value = %f\r\n", aiSlot, aiChannel, framData);
}
rc = MX_RTU_Module_AI_Eng_Value_Get(aiSlot, aiChannel, 1, &aiValue, &time);
if(rc != MODULE_RW_ERR_OK)
{
printf("MX_RTU_Module_AI_Eng_Value_Get(%d, %d, %d, &aiValue, &time), return code = %d\r\n", aiSlot, aiChannel, 1, rc);
exit(1);
}
rc = MX_RTU_FRAM_Write(framAddress, sizeof(aiValue), (UINT8 *)&aiValue);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_FRAM_Write(%d, %d, &aiValue), return code = %d\r\n", framAddress, sizeof(aiValue), rc);
exit(1);
}
rc = MX_RTU_FRAM_Read(framAddress, sizeof(framData), (UINT8 *)&framData);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_FRAM_Read(%d, %d, &framData), return code = %d\r\n", framAddress, sizeof(framData), rc);
exit(1);
}
else
{
printf("AI Slot = %d, Channel = %d, Value = %f\r\n", aiSlot, aiChannel, framData);
}
return 0;
}