ioPAC RTU Controllers
C/C++ Sample Code Programming Guide
Functions
sram.c File Reference

SRAM More...

#include <libmoxa_rtu.h>

Functions

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

Detailed Description

SRAM

Date
04-10-2013
Author
Eddy Kao
Version
V1.0
Introduction:
Logging an AI value on SRAM with battery backup.
Example:
1. Using default: ./sram
2. Setting AI: ./sram -s2 -c1
Default:
AI Slot = 1
AI Channel = 0
SRAM Address = 0x0
 SRAM_START_ADDRESS 
 SRAM_END_ADDRESS 
Help:
root@Moxa:/tmp#./sram -h
SRAM RW program.

Usage: ./sram [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       SRAM Address [0x0-0x20000]. Default SRAM Address = 0x0

Library:
SRAM APIs

Function Documentation

int main ( int  argc,
char *  argv[] 
)
/*******************************************************************************
* Copyright Moxa Inc.
*
* SRAM
*
* 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 sramAddress = 0x0;
float sramData = 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':
sramAddress = atoi(optarg);
if(sramAddress >= SRAM_END_ADDRESS)
{
printf("Error SRAM Address = %d\r\n", sramAddress);
exit(1);
}
break;
case '?':
case 'h':
default:
printf("SRAM RW program.\n\n");
printf("Usage: ./sram [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 SRAM Address [0x%x-0x%x]. Default SRAM Address = 0x%x\n", "-a", SRAM_START_ADDRESS, SRAM_END_ADDRESS, sramAddress);
printf("\n");
return 0;
}
}
//Power Off Test
rc = MX_RTU_SRAM_Read(sramAddress, sizeof(sramData), (UINT8 *)&sramData);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_SRAM_Read(%d, %d, &sramData), return code = %d\r\n", sramAddress, sizeof(sramData), rc);
exit(1);
}
else
{
printf("AI Slot = %d, Channel = %d, Value = %f\r\n", aiSlot, aiChannel, sramData);
}
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_SRAM_Write(sramAddress, sizeof(aiValue), (UINT8 *)&aiValue);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_SRAM_Write(%d, %d, &aiValue), return code = %d\r\n", sramAddress, sizeof(aiValue), rc);
exit(1);
}
rc = MX_RTU_SRAM_Read(sramAddress, sizeof(sramData), (UINT8 *)&sramData);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_SRAM_Read(%d, %d, &sramData), return code = %d\r\n", sramAddress, sizeof(sramData), rc);
exit(1);
}
else
{
printf("AI Slot = %d, Channel = %d, Value = %f\r\n", aiSlot, aiChannel, sramData);
}
return 0;
}