Description-
Transmit or receive file(s) with specified protocol to completion. This function is used for transmitting and receiving files. It does not return to the caller until the file transfer completes. It does however call the function that the caller passed when the function was called in order to allow the caller to get a progress report on the file transfer. This function will not stop other Windows applications from running or prevent messages for the current application from being processed.
Syntax-
stat = cdrvxfer_files(port,direction,protocol,fspec,fnc);
On Entry-
int port;
Port previously opened with InitializePort() or OpenComPort().
int direction;
0 To send a file.
1 To receive a file.
int protocol;
0 XMODEM
1 XMODEM 1K
2 YMODEM
3 YMODEM Batch
4 YMODEM G
5 YMODEM G Batch
6 ZMODEM
7 XMODEM(Checksum)
8 ASCII File transfer
char *fspec;
Filename including path to file to transfer. Note that if receiving a file, the file is placed in the directory pertaining to the path portion of the filespec.
int (far *fnc)(int chgflg,char *fname,long bytcnt,int curblk, int errcnt, unsigned rate);
Pointer to routine that is called by this function anytime one of the passed parameters changes. This function may abort the transfer by returning a non-zero value. If this pointer is NULL, then no display function is called.
int chgflg;
Non zero if calling due to a new file being transferred.
char *fname;
Filename being processed.
long bytcnt;
Current file byte count.
int curblk;
Current block being worked on.
int errcnt;
rent error count for file.
unsigned rate;
Current transfer rate in bytes per second.
On Exit-
int stat;
CDRVXFER_ERR_OK If the file transfer was successful.
CDRVXFER_ERR_SERIAL A serial I/O error has occurred. This could be caused by a broken serial communication cable, a bad UART or some other serial error.
CDRVXFER_ERR_OS An MSDOS error occurred. This may be caused by an error opening, writing, reading, or closing a file.
CDRVXFER_ERR_PROTOCOL A protocol error. This happens when an incompatibility between the file transfer protocol between the two transferring machines occur.
CDRVXFER_ERR_BUSY File transfer is still in progress.
CDRVXFER_ERR_CANCEL The remote issued a cancel.
CDRVXFER_ERR_INVPORT An invalid serial port was selected.
CDRVXFER_ERR_FNAME An invalid filename was given.
CDRVXFER_ERR_MEMORY A memory allocation error has occurred. This error may be caused due to a lack of memory. Most compilers causes an executable to allocate all memory on startup. You may want to use the exehdr program or some other compiler utility to adjust the maximum amount of memory the executable may allocate.
See Also-
cdrvxfer_getfiles()
cdrvxfer_sendfiles()
cdrvxfer_sfiles()
TransferFiles()
XferFiles()
Example-
#include “comm.h”
main()
{
int port=0;
int direction=1;
int protocol=6;
char *fspec=”e:\\tmp\\*.*””;
int stat;
int (far *fnc)(int chgflg,char *fname,long bytcnt,int curblk, int errcnt, unsigned rate) = DisplayFunction;
stat = cdrvxfer_files(port,direction,protocol,fspec,fnc);
return;
}
//User specified callback function. This function is
//called with file transfer progress information.
DisplayFunction(int chgflg,char *fname,long bytcnt,int curblk, int errcnt, unsigned rate)
{
char fnam[12+1];
fstrcpy(fnam,fname); //Filename being transferred
if (fchg != 0) //Display on next line only
printf(“\n”); //if moving a new file.
//Display the current transfer statistics
printf(“\rNAM=>%-12.12s BLK=>% 5u BYT=>% 7lu ERR=>% 4u R=% 5u Byt/Sec”,
fnam,curblk,bytcnt,errcnt,rate);
}
return(0);
}