#define AO_STATIC_MODE 1
#define AO_WAVEFORM_MODE 2
int main(
int argc,
char **
const argv)
{
int rc, i;
UINT32 aiSlot = 1, aoSlot = 2, slotMin = 0, slotMax = 9;
int aoChannelAmount = 6;
int aiChannelAmount = 8;
UINT32 aoMode[aoChannelAmount];
float u32AIVal = 0;
float u32AOVal = 0;
while(-1 != (rc = getopt(argc, argv, "hi:c:o:s:")))
{
switch(rc)
{
case 'i':
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: ai channel: %d\n", aiChannel);
return -1;
}
break;
case 'o':
aoSlot = atoi(optarg);
if(aoSlot < slotMin || aoSlot > slotMax)
{
printf("Error parameter: slot: %d\n", aoSlot);
return -1;
}
break;
case 's':
aoChannel = atoi(optarg);
if(aoChannel < 0 || aoChannel >= aoChannelAmount)
{
printf("Error parameter: ao channel: %d\n", aoChannel);
return -1;
}
break;
case '?':
case 'h':
default:
printf("AO sample program.\n\n");
printf("Usage: ./ao [OPTIONS]\n\n");
printf("Options:\n");
printf("\t%-8s Slot of AI module [%d-%d]. Default slot = %d\n",
"-i", slotMin, slotMax, aiSlot);
printf("\t%-8s Channel on AI module [%d-%d]. Default channel = %d\n",
"-c", 0, aiChannelAmount - 1, aiChannel);
printf("\t%-8s Slot of AO module [%d-%d]. Default slot = %d\n",
"-o", slotMin, slotMax, aoSlot);
printf("\t%-8s Channel on AO module [%d-%d]. Default channel = %d\n",
"-s", 0, aoChannelAmount - 1, aoChannel);
printf("\n");
return;
}
}
printf("%-10s: %d\n", "AI slot", aiSlot);
printf("%-10s: %d\n", "AI channel", aiChannel);
printf("%-10s: %d\n", "AO slot", aoSlot);
printf("%-10s: %d\n", "AO channel", aoChannel);
{
printf("MX_RTU_Tag_Init(), return code = %d.\n", retval);
return 0;
}
for(i = 0; i < aiChannelAmount; i++)
{
sprintf(aiEngTag[i], "S%d_AI%d_EngineeringValue", aiSlot, i);
}
for(i = 0; i < aoChannelAmount; i++)
{
sprintf(aoEngTag[i], "S%d_AO%d_EngineeringValue", aoSlot, i);
}
for(i = 0; i < aoChannelAmount; i++)
{
sprintf(aoWaveTag[i], "S%d_AO%d_WaveformStartStop", aoSlot, i);
}
retval =
MX_RTU_Tag_Read(aoEngTag[aoChannel], &u32AOVal,
sizeof(u32AOVal), NULL, NULL);
}
retval =
MX_RTU_Tag_Read(aoWaveTag[aoChannel], &u32AOVal,
sizeof(u32AOVal), NULL, NULL);
}
{
printf("AO mode setting error, please config correct through RTUxpress.\n");
return 0;
}
}
{
printf("MX_RTU_Tag_Read(%s) = %d\n", aoEngTag[aoChannel], retval);
return 0;
}
{
printf("MX_RTU_Tag_Get_Info(%s), return code = %d.\n", aoWaveTag[aoChannel], retval);
return 0;
}
{
printf("MX_RTU_Tag_Write(%s), return code = %d\r\n", aoWaveTag[aoChannel], retval);
return 0;
}
}
while(1)
{
retval =
MX_RTU_Tag_Read(aiEngTag[aiChannel], &u32AIVal,
sizeof(u32AIVal), NULL, NULL);
{
printf("MX_RTU_Tag_Read(%s) = %d\n", aiEngTag[aiChannel], retval);
break;
}
retval =
MX_RTU_Tag_Read(aoEngTag[aoChannel], &u32AOVal,
sizeof(u32AOVal), NULL, NULL);
{
printf("MX_RTU_Tag_Read(%s) = %d\n", aoEngTag[aoChannel], retval);
break;
}
printf("\rAO[%d] Engineering Value = %10f, AI[%d] Engineering Value = %10f", aoChannel, u32AOVal, aiChannel, u32AIVal);
fflush(0);
}
printf("\rAI[%d] Engineering Value = %10f", aiChannel, u32AIVal);
fflush(0);
}
}
{
printf("MX_RTU_Tag_Uninit(), return code = %d\n", retval);
}
return 0;
}