![]() |
![]() |
The following sections discuss the ez_console sample application included with the EZTapiAPI SDK. This is a Win32 console application designed to demonstrate the EZTapiAPI library interface. This program is actually two demo applications in one.
On startup of the ez_console application, the EZTapiAPI engine is initialized and a single EZLine device is opened. The EZLine device will be in the EZ_CALLSTATE_ONHOOK state after it has been successfully opened.
A menu is then presented to the user allowing the user to issue keyboard commands for placing or answering calls. Once a valid call has been established, the user can then issue keyboard commands to play, and record prompts, send and collect DTMF digits, and perform other call related tasks.
All EZTapiAPI function calls resulting from user input are made synchronously. EZTapiAPI functions are called synchronously by specifying an EZCallType value of EZ_SYNC.
As mentioned above, on startup of the ez_console application, the EZTapiAPI engine is initialized, and a single EZLine device is opened. The EZLine device will be in the EZ_CALLSTATE_ONHOOK state after it has been successfully opened.
Since a valid callback function pointer is specified in the call to EZTapiInitialize, the application is able to receive event notifications. If no user input in provided through the keyboard interface, this application will work as an answering machine after receiving four EZ_RING_EVENTS.
The application issues asynchronous EZTapiAPI function calls to answer the incoming call, play a voice prompt and then record a voice message. All functions are executed based on completion events received for the EZLine device. Completion events are posted for all functions called with an EZCallType value of EZ_ASYNC.
   
printf("\n\n\nERROR: Invalid menu selection.\n\n");
   
printf("Enter:\n\n");
   
printf(" 'M' or 'm' for TASK_MAKECALL.\n");
   
printf(" 'W' or 'w' for TASK_WAITFORCALL.\n");
   
printf(" 'H' or 'h' for TASK_HANGUPCALL.\n");
   
printf(" 'P' or 'p' for TASK_PLAYPROMPT.\n");
   
printf(" 'R' or 'r' for TASK_RECORDPROMPT.\n");
   
printf(" 'S' or 's' for TASK_SENDDIGITS.\n");
   
printf(" 'C' or 'c' for TASK_COLLECTDIGITS.\n");
   
printf(" 'U' or 'u' for TASK_UPDATEEZPARAM.\n");
   
printf(" 'Q' or 'q' for TASK_QUIT.\n\n");
   
CallTask = TASK_INVALIDENTRY;
   
break;
 
} // end switch()
 
// Remove trailing 'LF' character.
 
inputdata = getchar();
 
return(CallTask);
}
/******************************************************************************
Function: main()
Description: Entry point for the EZTapiAPI driver application. A simple
demo of EZTapiAPI functionality.
Parameters: <none>
Return Values: <none>
*******************************************************************************/
void main()
{
LONG rc;
DWORD dwNumEZLineDev;
EZModemType ModemType;
EZCallInfo callInfo;
char szFileName[EZ_MAXPATHSIZE], szDigits[EZ_DIGITBUFFERSIZE];
EZWaveFormat waveFmt;
EZLine aLine;
DWORD CurrCallTask;
LONG userInfo = -999;
DWORD i;
DWORD dwCallState;
printf("INFO: Calling EZInitializeTapi().\n");
/**************************************************************************
Initialize the EZTapiAPI Engine. This must be the first call by a client
application to the EZTapiAPI library.
***************************************************************************/
rc = EZTapiInitialize(EZ_CONSOLE_APP, &dwNumEZLineDev, (EZ_CALLBACK) &ez_callback, (void *) &userInfo);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZInitializeTapi(). EZTapiAPIError: %d.\n", rc);
exit(1);
}
else
{
printf("INFO: Calling EZOpenLine().\n");
/**********************************************************************
Open a EZLine device.
***********************************************************************/
rc = EZOpenLine(&aLine, EZ_OWNER, &ModemType);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZOpenLine().\n");
ProcessError(rc);
goto EZTAPI_FREE;
}
printf("INFO: Line %d, successfully opened.\n", aLine);
printf("Enter:\n\n");
printf(" 'M' or 'm' for TASK_MAKECALL.\n");
printf(" 'W' or 'w' for TASK_WAITFORCALL.\n");
printf(" 'H' or 'h' for TASK_HANGUPCALL.\n");
printf(" 'P' or 'p' for TASK_PLAYPROMPT.\n");
printf(" 'R' or 'r' for TASK_RECORDPROMPT.\n");
printf(" 'S' or 's' for TASK_SENDDIGITS.\n");
printf(" 'C' or 'c' for TASK_COLLECTDIGITS.\n");
printf(" 'U' or 'u' for TASK_UPDATEEZPARAM.\n");
printf(" 'Q' or 'q' for TASK_QUIT.\n\n");
while (true)
{
CurrCallTask = GetNextTask();
switch (CurrCallTask)
{
case TASK_MAKECALL:
printf("INFO: Calling EZMakeCall().\n");
rc = EZMakeCall(aLine, "103", EZ_SYNC);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZMakeCall().\n");
ProcessEZError(rc);
}
break;
case TASK_WAITFORCALL:
printf("INFO: Calling EZWaitForCall().\n");
rc = EZWaitForCall(aLine, 1, &callInfo);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZWaitForCall().\n");
ProcessError(rc);
}
break;
case TASK_ANSWERCALL:
printf("INFO: Calling EZAnswerCall().\n");
rc = EZAnswerCall(aLine, EZ_SYNC);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZAnswerCall.\n");
ProcessError(rc);
}
break;
case TASK_PLAYPROMPT:
printf("INFO: Calling EZPlayPrompt().\n");
rc = EZPlayPrompt(aLine, "thankyou.wav", EZ_SYNC);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZPlayPrompt().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZPlayPrompt() successful.\n");
}
break;
case TASK_RECORDPROMPT:
printf("INFO: Calling EZRecordPrompt().\n");
waveFmt.NumChannels = 1;
waveFmt.SampleRate = 8000;
waveFmt.BitsPerSample = 16;
memset(szFileName, '\0', EZ_MAXPATHSIZE);
rc = EZRecordPrompt(aLine, szFileName, sizeof(szFileName), &waveFmt, true, EZ_SYNC);
if (rc != EZ_SUCCESS)
 
{
printf("ERROR: An error occurred calling EZRecordPrompt().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZRecordPrompt() successful.\n");
printf("INFO: New wave file recording: %s.\n", szFileName);
}
break;
case TASK_SENDDIGITS:
printf("INFO: Calling EZSendDigits().\n");
rc = EZSendDigits(aLine, "!,102", EZ_SYNC);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSendDigits().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZSendDigits() successful.\n");
}
break;
case TASK_COLLECTDIGITS:
memset(szDigits, '\0', EZ_DIGITBUFFERSIZE);
rc = EZCollectDigits(aLine, szDigits, 4, "#", EZ_SYNC);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZCollectDigits().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZCollectDigits() successful.\n");
printf("INFO: Digits collected: %s.\n", szDigits);
}
break;
case TASK_HANGUPCALL:
printf("INFO: Calling EZHangupCall().\n");
rc = EZHangupCall(aLine);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZHangupCall().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZHangupCall() successful.\n\n");
}
break;
case TASK_GETCALLSTATE:
printf("INFO: Calling EZGetCallState().\n");
printf("INFO: EZCallState: %d.\n", EZGetCallState(aLine));
break;
case TASK_UPDATEEZPARAM:
if (toggle)
{
toggle = false;
rc = EZSetParameter(EZ_DIGITWAVESTOP_PARAM, 0);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_DIGITSTOP_PARAM set to FALSE.\n");
}
rc = EZSetParameter(EZ_FIRSTDIGITTIMEOUT_PARAM, 20000);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_FIRSTDIGITTIMEOUT_PARAM set to 20000 (20 seconds).\n");
}
rc = EZSetParameter(EZ_INTERDIGITTIMEOUT_PARAM, 15000);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_INTERDIGITTIMEOUT_PARAM set to 15000 (15 seconds).\n");
}
rc = EZSetParameter(EZ_RECORDHANGUPTRIM_PARAM, 5500);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_RECORDHANGUPTRIM_PARAM, set to 5500 (5.5 seconds).\n");
}
rc = EZSetParameter(EZ_RECORDDIGITTRIM_PARAM, 1500);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_RECORDDIGITTRIM_PARAM, set to 1500 (1.5 seconds).\n");
}
}
else // Reset EZ_PARAMETERS back to their default values
{
toggle = true;
rc = EZSetParameter(EZ_DIGITWAVESTOP_PARAM, 1);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_DIGITSTOP_PARAM set to TRUE.\n");
}
rc = EZSetParameter(EZ_FIRSTDIGITTIMEOUT_PARAM, 10000);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_FIRSTDIGITTIMEOUT_PARAM set to 10000 (10 seconds).\n");
}
rc = EZSetParameter(EZ_INTERDIGITTIMEOUT_PARAM, 8000);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_INTERDIGITTIMEOUT_PARAM set to 8000 (8 seconds).\n");
}
rc = EZSetParameter(EZ_RECORDHANGUPTRIM_PARAM, 0);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_RECORDHANGUPTRIM_PARAM, set to 0 (0 seconds).\n");
}
rc = EZSetParameter(EZ_RECORDDIGITTRIM_PARAM, 0);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZSetEZTapiAPIParam().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZ_RECORDDIGITTRIM_PARAM, set to 0 (0 seconds).\n");
}
}
break;
case TASK_QUIT:
printf("INFO: Quitting Application.\n");
break;
default:
break;
} // end switch(CurrCallTask)
if (CurrCallTask == TASK_QUIT)
break;
} // end while (true)
} // end if (EZInitializeTapi())
printf("\n\n");
/**************************************************************************
Get the current callstate of this line to see if this phoneline is still
connected.
***************************************************************************/
dwCallState = EZGetCallState(aLine);
if (dwCallState == EZ_CALLSTATE_CONNECTED)
{
printf("INFO: Calling EZHangupCall().\n");
rc = EZHangupCall(aLine);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZHangupCall().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZHangupCall() successful.\n\n");
}
}
EZTAPI_FREE:
printf("INFO: Calling EZLineClose().\n");
rc = EZCloseLine(aLine);
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZLineClose().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZLineClose() successful.\n");
}
printf("INFO: Calling EZTapiFree().\n");
rc = EZTapiFree();
if (rc != EZ_SUCCESS)
{
printf("ERROR: An error occurred calling EZTapiFree().\n");
ProcessEZError(rc);
}
else
{
printf("INFO: EZTapiFree successful.\n");
}
printf("INFO: Exiting application....\n");
return;
} // end main()
Return to Top