#define DEFAULT_OUT_NAME "ai_event.log"
int main(
int argc,
char **
const argv)
{
int rc, i;
UINT32 aiSlot = 1, slotMin = 0, slotMax = 0;
int aiChannelAmount = 8;
UINT8 aiChannel = 0;
char szOutFlieName[64];
FILE *pOutFile;
int handle = -1;
float aiLevel = 4.0;
float burnout = 0.0;
memset(szOutFlieName, 0, sizeof(szOutFlieName));
while(-1 != (rc = getopt(argc, argv, "hs:c:t:m:l:o:")))
{
switch(rc)
{
case 's':
aiSlot = atoi(optarg);
if(aiSlot < slotMin || aiSlot > slotMax)
{
printf("Error parameter: slot: %d\n", aiSlot);
return -1;
}
break;
case 'c':
aiChannel = atoi(optarg);
if(aiChannel < 0 || aiChannel >= aiChannelAmount)
{
printf("Error parameter: channel: %d\n", aiChannel);
return -1;
}
break;
case 'm':
aiCondition = atoi(optarg);
{
printf("Error parameter: condition: %d\n", aiCondition);
return -1;
}
break;
case 'l':
aiLevel = atoi(optarg);
break;
case 'o':
memset(szOutFlieName, 0, sizeof(szOutFlieName));
strncpy(szOutFlieName, optarg, strlen(optarg));
break;
case '?':
case 'h':
default:
printf("AI event sample program.\n\n");
printf("Usage: ./ai_event [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of AI module [%d-%d]. Default slot = %d\n",
"-s", slotMin, slotMax, aiSlot);
printf("\t%-8s Channel of AI module [%d-%d]. Default channel = %d\n",
"-c", 0, aiChannelAmount - 1, aiChannel);
printf("\t%-8s Conditionl of AI event[%d,%d,%d]. Default condition = %d\n",
printf("\t%-8s (%d: '%c', %d: '%c', %d: '%c')\n",
printf("\t%-8s Level of AI event. Default level = %.3f\n",
"-l", aiLevel);
printf("\t%-8s Output file name. Default name = %s\n",
"-o", szOutFlieName);
printf("\n");
return;
}
}
printf("%-10s: %d\n", "AI slot", aiSlot);
printf("%-10s: %d\n", "AI channel", aiChannel);
printf("%-10s: %d\n", "AI event condition", aiCondition);
printf("%-10s: %.3f\n", "AI event level", aiLevel);
printf("%-10s: %s\n", "output", szOutFlieName);
pOutFile = fopen(szOutFlieName, "w");
if(pOutFile == NULL)
{
fprintf(stderr, "Error open file: %s\n", szOutFlieName);
return -1;
}
printf("MX_RTU_Module_AI_Range_Get(%d, %d, %d), return code = %d.\n",
aiSlot, aiChannel, 1, rc);
printf("MX_RTU_Module_AI_Burnout_Value_Set(%d, %d, %d), return code = %d.\n",
aiSlot, aiChannel, 1, rc);
printf("MX_RTU_AI_Event_Reset(), return code = %d.\n", rc);
printf("MX_RTU_AI_Event_Register(%d, %d, %f, %d), return code = %d.\n",
aiSlot, aiChannel, aiLevel, aiCondition, rc);
while(1)
{
UINT32 count = 0;
{
printf("MX_RTU_AI_Event_Count(%d), return code = %d.\n", handle, rc);
break;
}
while(count--)
{
float fVal = 0;
char szLine[64];
{
printf("MX_RTU_AI_Event_Get(%d), return code = %d.\n", handle, rc);
break;
}
sprintf(szLine, "%d/%d/%d %02d:%02d:%02d.%d\t%.3f\n",
time.year, time.mon, time.day, time.hour, time.min, time.sec, time.msec, fVal);
printf(szLine);
fprintf(pOutFile, szLine);
fflush(pOutFile);
}
}
fclose(pOutFile);
printf("MX_RTU_AI_Event_Unregister(%d), return code = %d.\n", handle, rc);
return 0;
}