/*
THIS IS A PROGRAME TO READ A FILE BYTE BY BYTE AND SEND IT TO
SERIAL PORT.
HOWEVER IT ALSO RECEIVES THE SAME CHAR BACK AND WRITES IT TO A
SPECIFIED LOCATION.
***IT DOES NOT WAIT FOR THE CHAR SENT ... TO BE RECEIVED
*/
#include <conio.h>
#include <iostream.h>
#include <dos.h>
#include <process.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <bios.h>
#define COM1 0
#define DATA_READY 0X100
#define TRUE 1
#define FALSE 0
#define SETTINGS ( 0x80 | 0x03 | 0x00 | 0x00 )
void main(void)
{
clrscr();
FILE *file_r ;
FILE *file_w ;
char path_r[50];
char path_w[50];
long ctr_r = 0;
long filesize = 0;
int handle = 0;
int status = 0;
unsigned char ch_rx = 0;
unsigned char ch_tx = 0;
bioscom( 0 , SETTINGS , COM1 );
cout << "\n\nEnter the file path for Read : ";
gets ( path_r );
cout << "\n\nEnter the file path for Write : ";
gets ( path_w );
handle = open(path_r, O_RDONLY);
filesize = filelength( handle );
close( handle );
cout << "File Size : " << filesize << endl;
file_r = fopen ( path_r , "rb" ) ;//"rb" for read only in BINARY
if ( !file_r )
{
perror ( "Read FILE ERROR" ) ;
getch();
exit( 0 );
}
file_w = fopen ( path_w , "wb" );//"wb" for write only in BINARY
if ( !file_w )
{
perror ( "Write FILE ERROR" ) ;
getch();
exit( 0 );
}
//loop till end of file for read
while ( ctr_r < filesize )
{
ch_tx = fgetc(file_r);
bioscom ( 1 , ch_tx , COM1 );
cout << endl << "Ch_Tx: " << ch_tx;
status = bioscom( 3 , 0 , COM1 );
if(status & DATA_READY)
{
ch_rx = bioscom( 2 , 0 , COM1 );
fputc( ch_rx , file_w);
cout << endl << "Ch_Rx: " << ch_rx << " " << ctr_r;
// wait = 0;
// getch();
}
ctr_r++;
}
fclose ( file_r ) ;
fclose ( file_w ) ;
cout << "\n\n\WAV file Created ! " << endl;
getch();
}//end of main