EasyManua.ls Logo

Tonghui TH2816B - Page 48

Tonghui TH2816B
91 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
48
}
/* write string to serial port */
void string_wr( char *ps )
{ 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;
*ps = c;
ps++;
}
*ps = 0;
}
/* send a character to serial port */
void send_port( int port,char c )

Table of Contents

Related product manuals