49 | 8 4
{ char c;
int m,n;
while( check_stat(PORT) & 256 ) read_port( PORT );/* read data until null */
for( ;*ps; )
{ c = 0;
for( m = 100;m;m-- )
{ send_port( PORT,*ps );
for( n = 1000;n;n-- )
{ delay( 2 ); /* wait about 2ms, use dos.h libray funtion */
if( kbhit() && ( getch() == 27 ) ) /* if escape key keypress */
{ printf( "\nE20:Write Canceled!" );
exit(1);
}
if( check_stat(PORT) & 256 )
{ c = read_port( PORT );
break;
}
}
if( n ) break;
}
if( c == *ps ) ps++;
else
{ printf( "\nE10:Write Echo Error!" );
exit(1);
}
}
send_port( PORT,'\n' );/* send command end symbol */
delay( 2 );
while( !(check_stat(PORT) & 256) );
read_port( PORT );
}
/* read string from serial port */
void string_rd( char *ps )
{ unsigned char c,i;
for( i = 0;i < 255;i++ ) /* max read 256 characters */
{while( ! (check_stat(PORT) & 256) ) /* wait serial recieve ready */
if( kbhit() && (getch() == 27) ) /* if escape key keypress */
{ printf( "\nE21:Read Canceled!" );
exit(1);
}
c = read_port( PORT );
if( c == '\n' ) break;