Include files (step 3), Configuring rocketport controllers (step 4), Using – Comtrol API (6508) for the MS-DOS User Manual
Page 12: Calls (step 5)

12
Developing Applications
Developing Applications
/* Initialize
API
*/
aaInstallCtrlCHandler();
if((InitReturn = aaInit()) !=
NO_ERR
)
Step 4
{
(2.7)
printf("Init fail: %x\n",InitReturn);
aaExit();
exit(1);
}
/* Get serial device and display terminal emulator screen */
printf("Serial Device Number (0-15): ");
gets(Buf); /* get serial device */
Step 5
sscanf(Buf,"%d",&Dev);
(2.8-
system("cls"); /* clear screen */
2.12)
printf("Serial Device Number %d\t\t\tHit F10 to Quit\n",Dev);
/* Open the device */
if((Err = aaOpen(Dev,
COM_TX | COM_RX,
COM_BAUD_9600,
COM_PAR_NONE,
COM_DATABIT_8,
COM_STOPBIT_1,
COM_FLOW_NONE,
COM_DEN_PARITY | COM_DEN_RXOVR | COM_DEN_FRAME,
COM_MDM_DTR)) != 0)
{
printf("Failure - Could not open device number %d, Error
%d\n",Dev,Err);
aaExit(); /* required
API
call before exiting */
Step 6
exit(1);
(2.13)
}
/* Infinite loop to handle console
I/O
and serial
I/O
*/
while(1)
{
/* Attempt to read char from serial device and write to screen */
if((Cnt = aaRead(Dev,80,(unsigned char *)Buf)) > 0)
{
for(i = 0;i < Cnt;i++)
putch(Buf[i]);
}
/* Attempt to read char from keyboard and write to serial device */
if((bdos(11,0,0) & 0xff) == 0xFF) /* if char waiting */
{
Buf[0] = bdos(8,0,0) & 0xff; /* read keybd char */
if((Buf[0] == '\0') && ((bdos(11,0,0)&0xff) == 0xff)) /* 2 char key */
{
Buf[1] = bdos(8,0,0) & 0xff; /* 2nd key */
if(Buf[1] == 0x44) /* F10 = quit */
break;
}
aaWrite(Dev,1,(unsigned char *)Buf); /* write char to serial device */
}
}
aaClose(Dev,
COM_MDM_RTS | COM_MDM_DTR
); /* close device */
aaExit(); /* required
API
call before exiting */
return(0);
}
2.6. Include Files (Step 3)
The
API.H
file must be included in the .C source code files.
2.7. Configuring RocketPort Controllers (Step 4)
Configuration of the RocketPort controllers and the
API
is done using aaInit(),
as shown in the previous example. The aaInit() function must be called once
before any other
API
function (except aaInstallCtrlCHandler()) can be called. It
performs the configuration using the information in the configuration file
given in the
ROCKETCFG
environment variable. See Subsection 2.3 for
information about the format and placement of the configuration file.from the
system configuration. See Subsection 2.3 for information about the system
configuration.
Many applications also require that the
DOS
default
CTRL+C
key handler be
replaced with a handler that calls aaExit() (see Subsection 2.10). This is done
using aaInstallCtrlCHandler(). Once installed, this handler calls aaExit() if the
user terminates the application by pressing the
CTRL+C
or
CTRL+BREAK
keys.
If the application prevents program termination with these keys, the
aaIntallCtrlCHandler() function does not need to be called.
2.8. Using
API
Calls (Step 5)
The following subsections provide details about Step 5 of the
API
sample. The
topics include:
•
Device numbers
•
Configuration parameters for opening, closing, and reconfiguring serial
devices
-
Open type
-
Baud
-
Parity
-
Data bits
-
Stop bits
-
Flow control
-
Detect enable
•
Modem Control (output only)