C Language Development Kit/Functions/XModemTransmit

From OptiWiki

Jump to: navigation, search
Description This function uses the Xmodem protocol to transmit data through the serial communications port last opened with comopen(). xmodemtransmit() first polls with Xmodem/CRC and if there is no response it tries to poll with Xmodem/Checksum. The block size can be set to 128 or 1024 bytes with the systemsetting() function. The default block size is 128 bytes. If the data in the last block does not fill the block completely, EOF (0x1A) characters are appended up to make the block complete.
Syntax
int xmodemtransmit(char * filename);
Arguments
char * filename
Points to a string with the name of the file that is to be transmitted.
Returns An error code that can have one of the following values:
XMT_OK Successful transmission.
XMT_OPEN_ERR Could not open requested file.
XMT_RESPONSE_ERR No response from host.
XMT_POLL_ERR Wrong poll character.
XMT_READ_ERR Could not read from file.
XMT_ACK_ERR1 No acknowledgement received after a block.
XMT_ACK_ERR2 No acknowledgement after checksum.
XMT_MEM_ERR Could not allocate enough memory for temp. buffers.
Remarks The name of the file is not transmitted to the receiving side, 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 xmodemtransmit().
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