theone_in_themoon
Junior Member level 3
- Joined
- Oct 20, 2003
- Messages
- 28
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Lahore Pakistan
- Activity points
- 323
Serial Code "HangUp"
Hello Everybody...
Ive seen quite a handsom no. of posts regarding serial communication through RS-232 port .... But my problem is a bit strange.
Im using a simple code to read a file character by character and transmitt it serially. Wat i want to do actually is to send a WAV file serially to a Micro controller which stores it in a CF Card.
Currently im testing it to send the file correctly. But even when i join together the traans and receive of the Serial Port(COM1) the program hangs up after sending approx. 250 bytes.
Ive tried sending a text file and that is sent correcly.... but when sending a WAV file .... the program just gets stuck after 251 bytes.
Ive played with a lot ... and ive noticed that if we put a delay after bioscom send character command line ...... then there is a change in the no. of byets after which it gets stuck. But the Max it has gone to is 340 byte approx.
Here is the code :
I have also uploaded the cpp file
Please see and help
Thanks a lot in advance
Hello Everybody...
Ive seen quite a handsom no. of posts regarding serial communication through RS-232 port .... But my problem is a bit strange.
Im using a simple code to read a file character by character and transmitt it serially. Wat i want to do actually is to send a WAV file serially to a Micro controller which stores it in a CF Card.
Currently im testing it to send the file correctly. But even when i join together the traans and receive of the Serial Port(COM1) the program hangs up after sending approx. 250 bytes.
Ive tried sending a text file and that is sent correcly.... but when sending a WAV file .... the program just gets stuck after 251 bytes.
Ive played with a lot ... and ive noticed that if we put a delay after bioscom send character command line ...... then there is a change in the no. of byets after which it gets stuck. But the Max it has gone to is 340 byte approx.
Here is the code :
Code:
/*
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
I have also uploaded the cpp file
Please see and help
Thanks a lot in advance