About 4D Systems PTY LTD
4D Systems, Australia
Home Company Products 4DGL Developers Center Support forum Distributors News & Events Contact us App Notes
4DGL - Sharing our bytes to the world

Serial test - Sync mode


Codebase / GOLDELOX-GFX / Serial Port (COM0) Applications

Example showing the use of the sync character for the serial buffered service.
About this code
Author: 4D Systems
Uploaded on: 03/10/2008

Back to previous page

Source code:

#platform "uOLED-GOLDELOX"

/*    4DGL Demo Application
         - Test Sync Mode  -
     -- GOLDELOX Platform --
*/

#inherit "4DGL_16bitColours.fnc"


var combuf[24];    // 24 vars = 48 bytes

//-------------------------------------------------------------------------------------------//
func main()
    var chr, e;

    e := 0;

    // set outline colour, gfx_Cls() will draw outline
    gfx_Set(OUTLINE_COLOUR, DARKOLIVEGREEN); 
    gfx_Cls(); 

    txt_Set(FONT_SIZE, FONT_SMALL); 
    txt_MoveCursor(0,1);                // reset cursor to line 1, column 2
    putstr("Qualifier Test\n");
    putstr("Expect \":\" then 5 chars\n");

    //setbaud(BAUD_9600);                 

    print("Default 115200 baud\n");  // default baud rate

    repeat
        com_Init(combuf, 48, ':' );   // set up a comms buffer, requires ':' sync character
 
        // wait till we get a ':' then another 5 chars
        repeat
            txt_MoveCursor(3,1);                        // reset cursor to line 3, column 2
            print("Buffered ", ( com_Count() ));    // show count of chars in buffer
        until(com_Count() == 5);              // loop until sync char + 5 chars received

        print("\nReceived ", [STR] combuf );        // show what we got

        // we now have 5 chars
        // dump whatever we got to the terminal
        while ( (chr := serin()) >= 0)
            to(COM0); putch(chr);               // spit buffered chars to com port
        wend

        if (chr == -2) 
            print("\nError Count ", (++e) );      // print error count
        endif
    forever

endfunc
//-------------------------------------------------------------------------------------------//


Copyright © 2007 4D Systems Pty Ltd, Sydney, Australia - All Rights Reserved | Terms and Conditions