Modem Connections: 3 Sending Data

Up: GEOS SDK TechDocs | Up | Prev: 2 Connecting | Next: 4 Receiving Data

To send data, MTalk does the following:

Code Display 9-2 Sending Data Over A Serial Connection

    /*
     * textBlock - Handle of block containing text to send.
     * textPtr - Pointer to text to send.
     * textSize - Size of text to send.
     */
    MemHandle		textBlock;
    char *		textPtr;
    int		textSize;
    /*
     * Get text that user has typed and put it into a newly created memory block.
     * Lock the block down on the heap and obtain a pointer to it.
     */
    textBlock = @call MTalkSendText::MSG_VIS_TEXT_GET_ALL_BLOCK( NullHandle );
    textPtr = MemLock( textBlock );
    /*
     * Get the size of the text then send it.
     */
    textSize = LocalStringSize( textPtr );
    if ( ModemSend( textSize, (byte*)textPtr ) != STREAM_NO_ERROR )
    {
	/* handle the error */
    }
    /*
     * Once the text has been sent, free its block.
     */
    MemFree( textBlock );

ModemSend() calls the VirtualSerial Library routine, VirtualSerialWrite() , to send the passed data. VirtualSerialWrite() writes the passed data to stream and, if necessary, blocks until enough space in the stream becomes available. (If you don't want to block, pass STREAM_NO_BLOCK in VirtualSerialWrite() .)

ModemSend() takes two arguments:

dataLength
Length of the string (not counting the Null character).
data
Pointer to the data to be sent.

ModemSend() returns a StreamError value:

STREAM_NO_ERROR
if it successfully sends the data.
STREAM_CLOSED
if the stream is not open.
STREAM_SHORT_READ_WRITE
if the required amount of space was not available and STREAM_NO_BLOCK was specified.

Up: GEOS SDK TechDocs | Up | Prev: 2 Connecting | Next: 4 Receiving Data