/***************************************************
* PMACterminal.c
*
* This program will create a terminal to allow
* users to send commands to the PMAC board.
***************************************************/
#include
#include "Pmacu.h" //Include file for PMAC
int main(void)
{
DWORD DwDevice=0; //Variable to store the device number
char inputbuf[16384];
char outputbuf[256];
//Ask the user to input a PMAC device number and store
////it in the device number variable.
printf( "\nInput PMAC device number (DwDevice): " );
fgets(inputbuf, 10, _stdin);
DwDevice = atoi(inputbuf);
//If the user inputted.
if(DwDevice <= 0 )
DwDevice = 0;
//Open the PMAC device.
if ( !OpenPmacDevice( DwDevice ) )
{
printf( "ERROR: PMAC device %d not found.\n", DwDevice );
exit( -1 );
}
else
{
printf( "PMAC Opened Successfully!\n\n" );
printf( "A terminal is active for your use.\n");
printf( "Type 'quit' or 'QUIT' to quit the terminal.\n\n");
}
//Loop for terminal operation.
while (1)
{
printf("> "); //print a prompt
fgets(inputbuf, 500, _stdin); //get input
//Check if user wants to quit the terminal.
if (strcmp(inputbuf,"quit\n")==0 || strcmp(inputbuf,"QUIT\n")==0)
{
printf("Exiting...\n\n" );
break;
}
// Send the command to PMAC and get any response.
PmacGetResponse(DwDevice,outputbuf,250,inputbuf);
printf("%s\n", outputbuf);
outputbuf[0]='\0';
// Check the PMAC for errors.
if(PmacGetErrorStr(DwDevice,outputbuf,250))
{
printf("%s\n", outputbuf);
outputbuf[0]='\0';
}
printf("\n");
}
//Close the PMAC device
if ( ClosePmacDevice( DwDevice ) )
printf( "\nPMAC Closed Successfully!\n");
else
{
printf( "ERROR: PMAC device %d could not be closed.\n", DwDevice );
exit( -1 );
}
return 0;
}
/* End of Program */
|