C Language Development Kit/Functions/XModemReceive

From OptiWiki

Jump to: navigation, search
Description This function uses the Xmodem protocol to receive blocks of data through the serial communications port last opened with comopen(). The xmodemreceive() function supports blocks with a block size of 128 or 1024 bytes (selected by the transmitting side). Xmodem/CRC and Xmodem/Checksum are also supported (selected by the transmitting side). If the data in the last block does not fill the block completely, EOF (0x1A) characters are appended to make the block complete.
Syntax
int xmodemreceive(char * filename);
Arguments
char * filename
Points to a string with the name of the file where the data is to be stored. The file is opened and closed by the xmodemreceive(), so the file is either overwritten, or created.
Returns An error code that can have one of the following values:
XMR_OK File received OK.
XMR_CREATE_ERR Could not open the requested file.
XMR_POLL_ERR No response to poll character.
XMR_ABORT_ERR Aborted from host side.
XMR_BLOCK_ERR Wrong block received.
XMR_CRC_ERR CRC error.
XMR_CHECKSUM_ERR Checksum error.
XMR_WRITE_ERR Could not write (probably disk full).
XMR_RESPONSE_ERR No response from host.
XMR_MEM_ERR Could not allocate enough memory for temp. buffers.
Remarks The name of the file is not received by xmodemreceive(), only the data is transferred. The COM port of the handheld terminal that is used for transmission must have been opened by comopen() before calling xmodemreceive().
Example
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    comopen( COM0 );   //direct cable, 9600,N,8,1
 
    while( 1 )
    {
        while( 1 )
        {
            resetkey();
            resetreceive();
            printf("\fReceiving..\n");
 
            if( xmodemreceive("test.dat") != XMR_OK)
            {
                printf("\fERROR:\nfile not received\npress any key");
                while( !kbhit() )
                    idle();
                continue;
            }
 
            printf("file Received OK\n\rPress key\n\r");
            while( !kbhit())
                idle();
            break;
        }
 
        while( 1 )
        {
            resetkey();
            resetreceive();
            printf("\fSending..\n");
 
            if( xmodemtransmit("test.dat") != XMT_OK )
            {
                printf("\fERROR:\nfile not send\npress any key");
                while( !kbhit())
                    idle();
                continue;
            }
 
            printf("file send OK\n\rPress key\n\r");
            while( !kbhit() )
                idle();
            break;
        }
    }
}


Views
Personal tools