ioPAC RTU Controllers
C/C++ Sample Code Programming Guide
Macros | Functions
system_info.c File Reference

System Info More...

#include <libmoxa_rtu.h>

Macros

#define LOGGING_FILE_NAME   "system_info.csv"
 

Functions

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

Detailed Description

System Info

Date
04-10-2013
Author
Eddy Kao
Version
V1.0
Introduction:
Logging all system information into system_info.csv.
Example:
1. Using default: ./system_info
2. Setting Module Info Slot: ./system_info -s2
Default:
Module Info Slot = 1
Logging File Name = system_info.csv
Help:
root@Moxa:/tmp#./system_info -h
System Info program.

Usage: ./system_info [OPTIONS]

Options:
        -s       Module Info slot [0-9]. Default Module Info slot = 1
                 (slot 0: Built-in IO, slot 1 ~ 9: IO Module)
        -f       Logging File Name. Default file name = system_info.csv

Library:
SystemInfo APIs

Macro Definition Documentation

#define LOGGING_FILE_NAME   "system_info.csv"

Function Documentation

int main ( int  argc,
char *  argv[] 
)
/*******************************************************************************
* Copyright Moxa Inc.
*
* System Info
*
* Date Author Comment
* 04-10-2013 Eddy Kao Created.
******************************************************************************/
#include <libmoxa_rtu.h>
#define LOGGING_FILE_NAME "system_info.csv"
int main(int argc, char *argv[])
{
int i = 0;
int retval = 0;
UINT32 rc = 0;
UINT8 moduleInfoSlot = 1;
UINT32 totalSlot = 0;
UINT32 slotInserted = 0;
UINT32 etherType = 0;
char ethernetAdapterType[8];
UINT32 hotPlugConnectState = 0;
UINT32 hotPlugDisconnectState = 0;
UINT32 apiVersion = 0;
UINT32 apiBuildDate = 0;
UINT32 systemVersion = 0;
UINT32 systemBuildDate = 0;
char sLine[64];
char sOutFlieName[64];
struct Module_Info moduleInfo;
FILE *pOutFile;
memset(sOutFlieName, 0, sizeof(sOutFlieName));
strncpy(sOutFlieName, LOGGING_FILE_NAME, strlen(LOGGING_FILE_NAME));
while((rc = getopt(argc, argv, "hs:f:")) != -1)
{
switch(rc)
{
case 's':
moduleInfoSlot = atoi(optarg);
if(moduleInfoSlot > MAX_SLOT)
{
printf("Error Module Info slot = %d\r\n", moduleInfoSlot);
exit(1);
}
break;
case 'f':
memset(sOutFlieName, 0, sizeof(sOutFlieName));
strcpy(sOutFlieName, optarg);
break;
case '?':
case 'h':
default:
printf("System Info program.\n\n");
printf("Usage: ./system_info [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Module Info slot [%d-%d]. Default Module Info slot = %d\n", "-s", 0, MAX_SLOT, moduleInfoSlot);
printf("\t%-8s (slot 0: Built-in IO, slot 1 ~ 9: IO Module)\n", "");
printf("\t%-8s Logging File Name. Default file name = %s\n", "-f", LOGGING_FILE_NAME);
printf("\n");
return 0;
}
}
memset(&moduleInfo, 0, sizeof(moduleInfo));
rc = MX_RTU_Module_Info_Get(moduleInfoSlot, &moduleInfo);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_Module_Info_Get(%d, &moduleInfo), return code = %d\r\n", moduleInfoSlot, rc);
exit(1);
}
rc = MX_RTU_Total_Slots_Get(&totalSlot);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_Total_Slots_Get(&totalSlot), return code = %d\r\n", rc);
exit(1);
}
rc = MX_RTU_Slot_Inserted_Get(&slotInserted);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_Slot_Inserted_Get(&slotInserted), return code = %d\r\n", rc);
exit(1);
}
if(rc != IO_ERR_OK)
{
printf("MX_RTU_Ethernet_Adapter_Type_Get(&etherType), return code = %d\r\n", rc);
exit(1);
}
else
{
memset(ethernetAdapterType, 0, sizeof(ethernetAdapterType));
if(etherType == ETHERNET_ADAPTER_RJ45) strcpy(ethernetAdapterType, "RJ45");
else if(etherType == ETHERNET_ADAPTER_M12) strcpy(ethernetAdapterType, "M12");
}
rc = MX_RTU_System_Hot_Plug_Connect_Get(&hotPlugConnectState);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_System_Hot_Plug_Connect_Get(&hotPlugConnectState), return code = %d\r\n", rc);
hotPlugConnectState = 0;
}
rc = MX_RTU_System_Hot_Plug_Disconnect_Get(&hotPlugDisconnectState);
if(rc != IO_ERR_OK)
{
printf("MX_RTU_System_Hot_Plug_Disconnect_Get(&hotPlugDisconnectState), return code = %d\r\n", rc);
hotPlugDisconnectState = 0;
}
apiVersion = MX_RTU_API_Version_Get();
apiBuildDate = MX_RTU_API_BuildDate_Get();
systemVersion = MX_RTU_System_Version_Get();
systemBuildDate = MX_RTU_System_BuildDate_Get();
//Logging
pOutFile = fopen(sOutFlieName, "w+");
if(pOutFile == NULL)
{
fprintf(stderr, "Error open file: %s\r\n", sOutFlieName);
}
else
{
sprintf(sLine, "Module Info,slot,%d\n", moduleInfo.slot);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,vendor id,0x%x\n", moduleInfo.vendor_id);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,product id,0x%x\n", moduleInfo.product_id);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,serial number,%x\n", moduleInfo.serial_number);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,hardware version,0x%x\n", moduleInfo.hw_version);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,firmware version,0x%x\n", moduleInfo.fw_version);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: DI channels,%d\n", moduleInfo.io_info.di_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: DO channels,%d\n", moduleInfo.io_info.do_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: DIO channels,%d\n", moduleInfo.io_info.dio_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: AI channels,%d\n", moduleInfo.io_info.ai_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: Fast AI channels,%d\n", moduleInfo.io_info.fast_ai_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: AO channels,%d\n", moduleInfo.io_info.ao_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: TC channels,%d\n", moduleInfo.io_info.tc_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Module Info,IO Info: RTD channels,%d\n", moduleInfo.io_info.rtd_channels);
fprintf(pOutFile, sLine);
sprintf(sLine, "Total Slot,%d\n", totalSlot);
fprintf(pOutFile, sLine);
sprintf(sLine, "Ethernet Adapter Type,%s\n", ethernetAdapterType);
fprintf(pOutFile, sLine);
for(i = 1; i <= MAX_SLOT; i++)
{
if(slotInserted & (1 << i))
{
sprintf(sLine, "Slot %d is inserted\n", i);
fprintf(pOutFile, sLine);
}
}
for(i = 1; i <= MAX_SLOT; i++)
{
if(hotPlugConnectState & (1 << i))
{
sprintf(sLine, "Hot-Plug Connect,slot %d\n", i);
fprintf(pOutFile, sLine);
}
}
for(i = 1; i <= MAX_SLOT; i++)
{
if(hotPlugDisconnectState & (1 << i))
{
sprintf(sLine, "Hot-Plug Disconnect,slot %d\n", i);
fprintf(pOutFile, sLine);
}
}
sprintf(sLine, "API Version,0x%x\n", apiVersion);
fprintf(pOutFile, sLine);
sprintf(sLine, "API Build Date,0x%x\n", apiBuildDate); //Example: 0x0d03010e -> 2013.03.01-14:00:00
fprintf(pOutFile, sLine);
sprintf(sLine, "System Version,0x%x\n", systemVersion);
fprintf(pOutFile, sLine);
sprintf(sLine, "System Build Date,0x%x\n", systemBuildDate); //Example: 0x0d03010e -> 2013.03.01-14:00:00
fprintf(pOutFile, sLine);
fclose(pOutFile);
}
return 0;
}