Announcement

Collapse
No announcement yet.

Problems with serial coms to screen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with serial coms to screen

    Hi everyone I hope you guys can help.
    I have a oled 160-G2 that I am working with to display media player information. I can write to the display successfully at slow speeds where I update the screen ever 1/2 -1 second.
    Once I write to the screen faster than that screen does not display all the information sent to it, then after a while the screen no longer displays any updated information.
    I was wondering if there are any obviouse errors in my code, or whether there are ways I can do things better.
    Thanks fr any help you can provided.
    Steve

    Code:
    #platform "GOLDELOX"
    
    // Program Skeleton 1.0 generated 19/11/2018 14:48:01
    
    #inherit "4DGL_16bitColours.fnc"
    
    #inherit "VisualConst.inc"
    
    #inherit "PrintDiskGoldelox.inc"
    
    #inherit "HypersyncV0.9_1Const.inc"
    
    // Declare Global Variables
        var Status1;
        var Status2;
        var Status3;
        var LEDstate;
        var NUMplayers;
    
    func main()
    //  Uncomment the following if uSD images, fonts or strings used.
    
        print("Starting\n") ;
        while(!media_Init())
            putstr("Drive not mounted...");
            pause(200);
            gfx_Cls();
            pause(200);
        wend
    
    //  SETUP LEDs
    
        var LED1;
        var LED2;
        var LED3;
        var LED4;
        var LED5;
        var LED6;
        var LED7;
        var LED8;
        var LED9;
        var LED10;
        var LED11;
        var LED12;
        var LED13;
        var LED14;
        var LED15;
        LED1 := 0;
        LED2 := 0;
        LED3 := 0;
        LED4 := 0;
        LED5 := 0;
        LED6 := 0;
        LED7 := 0;
        LED8 := 0;
        LED9 := 0;
        LED10 := 0;
        LED11 := 0;
        LED12 := 0;
        LED13 := 0;
        LED14 := 0;
        LED15 := 0;
    
    // END OF LED SETUP
    
    // SETUP TIMECODE DISPLAY
    
        var TC;
        var TCh;
        var TCm;
        var TCs;
        TCh := "00";
        TCm := "00";
        TCs := "00";
        TC := "00:00:00";
    
    // End of TC Setup
    
        NUMplayers := 1;
        gfx_Cls();
        pause(200);
        LEDinit(NUMplayers);       //send the number of players
        LINESinit();
        TCinit();
        var i;
    
    // Put some test values in
    
    
        STATUSupdate("Initialised");
        PSTATEupdate(0, "WAITING");
        MENUupdate("   MENU>>>");
    
    
    
    
    // TEST SERIAL INPUT AND OUTPUT TO DISPLAY
    
    //gfx_Cls();
    //txt_FontID(0);
    //txt_Width(1);
    //txt_Height(1);
    
    var combuf[13];    // alter this length as required
    var LEDbin[8];          //  8 word
    var c,x;
    var cmd;
    var count;
    var msgType;
    //putstr("Default 115.2kb");
    repeat
        com_Reset();
        //gfx_Cls();
        for (c:=0; c<26; c++)  // clear the array
            combuf[c] := ' ';
        next
        repeat
        cmd := serin();
                if (cmd == '*')
                    com_Init(combuf,7,0);  //reset the buffer - ready to receive PLAYSTATE (7 CHARS)
                    msgType := '*';
                    serout('*');
                    break;
                endif
                if (cmd == '$')
                    com_Init(combuf,7,0);  //reset the buffer - ready to receive MENU (7 CHARS)
                    msgType := '$';
                    serout('$');
                    break;
                endif
                if (cmd == '#')
                    com_Init(combuf,8,0);  //reset the buffer - ready to receive TIMECODE (8 CHARS)
                    msgType := '#';
                    serout('#');                                  
                    break;
                endif
                if (cmd == '^')
                    com_Init(combuf,25,0);  //reset the buffer - ready to receive STATUS (18 CHARS)
                    msgType := '^';
                    serout('^');
                    break;
                endif
                if (cmd == '@')
                    com_Init(combuf,2,0);  //reset the buffer - ready to receive LEDSTATE (18 CHARS)
                    msgType := '@';
                    serout('@');
                    break;
                endif
                if (cmd == '£')
                    com_Init(combuf,1,0);  //reset the buffer - ready to receive number of players (1 CHARS)
                    msgType := '£';
                    serout('£');
                    break;
                endif
    
        forever
        repeat
    
        until(com_Full()); // just loop until buffer is full
    
    switch // switch has no expression
        case (msgType == '*')
             PSTATEupdate(0, combuf);
        break; // optional – skip rest of evaluations
        case (msgType == '#')
            TCupdateFull(combuf);
        break;
        case (msgType == '^')
            STATUSupdate(combuf);
        break; // optional – skip rest of evaluations
        case (msgType == '$')
            MENUupdate(combuf);
        break; // optional – skip rest of evaluations
        case (msgType == '~')
            NUMplayers := (combuf);
            LEDinit(NUMplayers);
        break; // optional – skip rest of evaluations
        case (msgType == '@')
            var LED;
            to(COM0); putnum(BIN16ZB, combuf[0]);
       //     to(APPEND); putstr("\n");
       //      STATUSupdate(LEDbin);
            LEDinit(NUMplayers);
            for (x:=0; x<NUMplayers; x++)
            LED := BITcheck(combuf[0], x);
                if (LED == TRUE)
                    LEDupdate(x+1, 1);
                else
                    LEDupdate(x+1, 0);
                endif
                //LEDupdate(x+1,0);
            next
        break; // optional – skip rest of evaluations
    endswitch
    
    
    forever // do it all again
    
    endfunc
    
    
    
    
    
    
    
    
    func LEDupdate(var LEDid, var state)
        switch // switch has no expression
        case (LEDid == 1)
            media_SetAdd(iUserled1H, iUserled1L) ;      // point to the Userled1 image
            media_VideoFrame(6, 114, state) ;      // where numx is 0 (Off) or 1 (On)
            break; // optional – skip rest of evaluations
        ///this has been cut to 
        endswitchfit the forum
    endfunc
    
    func LEDinit(var NUMplayers)
        var i;
        var size;
        media_SetAdd(iLEDoffH, iLEDoffL) ;      // point to the LEDoff image - an empty, unlit LED
        i := 6;
        size := (NUMplayers * 10)-4;
        while(i <= size)
            media_VideoFrame(i, 114, 0) ;      // where numx is 0 (Off) or 1 (On)
         i := i + 10;
        wend
    
    
    endfunc
    
    func STATUSupdate(var msg)
    
            Status3 := Status2;
            Status2 := Status1;
            Status1 := msg;
    
            media_SetSector(0, Status1FontStartL) ;    // must come b4 setting fontID
            txt_FontID(MEDIA) ; // Font index correct at time of code generation
            txt_FGcolour(WHITE) ;
            txt_BGcolour(BLACK) ;
            gfx_MoveTo(12 , 60) ;
            putstr("                          ");
            gfx_MoveTo(12 , 60) ;
            putstr(Status1);
    
            media_SetSector(0, Status2FontStartL) ;    // must come b4 setting fontID
            txt_FontID(MEDIA) ; // Font index correct at time of code generation
            txt_FGcolour(WHITE) ;
            txt_BGcolour(BLACK) ;
            gfx_MoveTo(12 , 74) ;
            putstr("                          ");
            gfx_MoveTo(12 , 74) ;
            putstr(Status2);
    
            media_SetSector(0, Status3FontStartL) ;    // must come b4 setting fontID
            txt_FontID(MEDIA) ; // Font index correct at time of code generation
            txt_FGcolour(WHITE) ;
            txt_BGcolour(BLACK) ;
            gfx_MoveTo(12 , 88) ;
            putstr("                          ");
            gfx_MoveTo(12 , 88) ;
            putstr(Status3);
    
    endfunc
    
    func LINESinit()
        gfx_Line(0, 20, 160, 20, 0x10A2) ;
        gfx_Line(0, 58, 160, 58, 0x10A2) ;
        gfx_Line(0, 107, 160, 107, 0x10A2) ;
        gfx_Line(80, 0, 80, 20, 0x10A2) ;
    endfunc
    
    func PSTATEupdate(var type, var state)              //************** COLOUR ISNT WORKING *******************
        var colour;
        if (type == 1)
            colour := RED;
        else
            colour := WHITE;
        endif
        gfx_OutlineColour(0x0000);
        gfx_RectangleFilled(0,0,78,19, 0x0000);
        media_SetSector(0, StateStringFontStartL) ;    // must come b4 setting fontID
        txt_FontID(MEDIA) ; // Font index correct at time of code generation
        txt_FGcolour(colour) ;
        txt_BGcolour(BLACK) ;
        gfx_MoveTo(7 , 1) ;
        putstr(state);
    endfunc
    
    func MENUupdate(var msg)
        gfx_OutlineColour(0x0000);
        gfx_RectangleFilled(82,0,160,19, 0x0000);
        media_SetSector(0, MenuStringFontStartL) ;    // must come b4 setting fontID
        txt_FontID(MEDIA) ; // Font index correct at time of code generation
        txt_FGcolour(WHITE) ;
        txt_BGcolour(BLACK) ;
        gfx_MoveTo(94 , 1) ;
        putstr(msg);
    endfunc
    
    
    func TCupdate(var HH,var MM,var SS)
        var TC[4];
        if(strlen(HH) != 2)
            HH:="er";
        endif   //test for valid number
        if(strlen(MM) != 2)
            MM:="er";
        endif   //test for valid number
        if(strlen(SS) != 2)
            SS:="er";
        endif   //test for valid number
    
        media_SetSector(0, TCstringFontStartL) ;    // must come b4 setting fontID
        txt_FontID(MEDIA) ; // Font index correct at time of code generation
        txt_FGcolour(WHITE) ;
        txt_BGcolour(BLACK) ;
        gfx_MoveTo(8 , 24) ;
        putstr(HH);
        gfx_MoveTo(44 , 24) ;
        putstr(":");
        gfx_MoveTo(62 , 24) ;
        putstr(MM);
        gfx_MoveTo(98 , 24) ;
        putstr(":");
        gfx_MoveTo(116 , 24) ;
        putstr(SS);
    endfunc
    
    func TCinit()
    
        media_SetSector(0, TCstringFontStartL) ;    // must come b4 setting fontID
        txt_FontID(MEDIA) ; // Font index correct at time of code generation
        txt_FGcolour(WHITE) ;
        txt_BGcolour(BLACK) ;
        gfx_MoveTo(8 , 24) ;
        putstr("00:00:00");
    endfunc
    
    //===================================================================================
    // convert a hex digit to a number 0-15
    // Returns -1 if failed
    //===================================================================================
    func hex2dec(var h)
        return ( lookup8( h & 0xff , "0123456789ABCDEF" ) - 1 );      // hex lookup, returns 0-15 or -1 if not ascii number
    endfunc
    
    
    // extract a character from a packed string
    // the first character# is 0
    func str_getch(var *array, var idx)
    var x ;
    if ((idx % 2) == 0)
    x := array[idx / 2] && 0xff ;
    else
    x := array[idx / 2] >> 8 ;
    endif
    return x ;
    endfunc
    
    
    func BITcheck (var N, var i)       //check if bit location 'i' is set in data N
    
        if( N & (1 << i) )
            return TRUE;
        else
            return FALSE;
        endif
    
    endfunc
    Starts
    4th June 2019
    Ends
    4th June 2019

  • #2
    Hi,


    I suppose that the messages are sent individually followed by their respective identifier.
    Have you tried to add a small delay on the other device when sending data?

    I also create a simple serial communication using your program and unfortunately, I do also experience
    some stuck ups. I will try to conduct further testing to see if I can provide a solution to your issues.

    Best Regards,
    Kevin

    Comment


    • #3
      There is a slight delay between the identifier and the message and that works fine. The issue I have is I can not update the screen as fast as I would like with timecode and system messages.

      Comment


      • #4
        I was wondering if there was any progress on solving this issue?
        Thanks
        Steve

        Comment


        • #5
          Hi steve,

          Sorry for the delayed response.

          I am trying to figure out what may be the reason for this issue, and I think
          the freezing occurs when you are not handling properly the buffered service.

          If the comms is full you must re-initialize the buffer, and upon checking again the code, there is no condition to handle this on your program.
          Code:
          if(com_Full())  com_Init(combuf, 60, 0);  // initialize the buffer if full
          I tried to modify the code above, can you please check if there are no issues at your end.


          Best Regards,
          Kevin
          Attached Files

          Comment

          Working...
          X