KEPCO BIT 232F User Manual
Page 66

F-2
BIT 232 022800
F.4
SEND, WAIT FOR ECHO
This function sends a character to the serial port specified by (n), allows a small delay (about 50
msec) for the character to be received by the BIT card, analyzed, put in a buffer and echoed
back. If the BIT Card did not receive the character, or if the time-out expires, the BIT card
returns the EOF character.
This command could be modified so that if the time-out expires, the last character is sent to the
BIT Card again.
int SendWecho(int n, int c)
{
int j;
/* send to the serial port */
put_serc(n, c);
/* timeout delay = 1000 - biger for faster computers */
for(j=1;j<1000;j++)
if (in_ready(PORT)) {
/* get character from serial port*/
c = get_serc(PORT);
return c;
}
/* if timeout - no character returned */
c = EOF;
return c;
}
F.5
GET CHARACTER FROM SERIAL PORT
This function accepts a character from the serial port specified by n using the ROM BIOS rou-
tine; if the computer is not IBM-PC-compatible the ROM BIOS routine must be replaced by an
equivalent.
/* get character from serial port */
int get_serc(int n)
{
union REGS regs;
/* AH has the function code */
regs.h.ah = 0x02;
/* DX has the port number */
if (n == 1)
regs.x.dx = 0;
else
regs.x.dx = 1;
/* call the ROM BIOS routine */
int86(0x14, ®s, ®s);
/* return EOF if timed out */
if (regs.h.ah & 0x80)
return EOF;
return regs.h.al;
}