FullDuplexSerial control codes

Is there a clear screen code in full duplex serial object?
Thx

Comments

  • Clock LoopClock Loop Posts: 1,940
    edited 2020-09-26 - 21:59:18
    What terminal are you using?



    In the PST (parallax serial terminal, 0 or 16 does the job)
    You can find this in the Preferences of the PST.
      term.tx(16)    'Clear Screen.
    
    AsciiControlCharactersParallaxSerialTerminal.jpg


    In the Putty terminal you can use ansi control codes.
        term.str(string(27))    'Set command mode                                                     
        term.str(string("[2J"))    'Clear telnet screen
    

    I prefer to use putty as my terminal because you can do colors and other fancy things.
    Escape codes: https://forums.parallax.com/discussion/comment/1434641/#Comment_1434641

    You can even do full "graphics" with ansi and putty. (ansi art)
    https://forums.parallax.com/discussion/comment/1434744/#Comment_1434744

    ....
  • JonnyMacJonnyMac Posts: 6,997
    edited 2020-09-26 - 22:08:17
    I have this CON block in my FDS objects:
    con { pst formatting }
    
    ' Control codes for Parallax Serial Terminal
    
      HOME    =  1
      CRSR_XY =  2         ' next two bytes in stream are x and y positions values
      CRSR_LF =  3
      CRSR_RT =  4
      CRSR_UP =  5
      CRSR_DN =  6
      BELL    =  7
      BKSP    =  8
      TAB     =  9
      LF      = 10
      CLR_EOL = 11         ' clear to end of line
      CLR_DN  = 12         ' clear everything after cursor
      F_FEED  = 12
      CR      = 13
      CRSR_X  = 14         ' next byte in stream is x position value
      CRSR_Y  = 15         ' next byte in stream is y position value
      CLS     = 16
    
  • frank freedmanfrank freedman Posts: 1,729
    edited 2020-09-26 - 22:37:47
    Using Putty on second serial port of the PPDB.
    Thank you all for the fast replies.

    @JonnyMac, your con listing helped solve it. I had tried using $10 and that did not really clear it (possibly the PUTTY setting?), but using $C, the form feed took care of the issue.

    @Clock Loop, Guess I make some less than optimal assumptions on the PUTTY setup. Had not looked for a PUTTY setup screen such as you have posted. Gonna revisit that one now. Thx
    Close but I need to dig more on escape sequences.

    Parallax forums, best peeps, best ideas and help when needed!!
  • The control codes are dependent on the terminal program being used on the PC. It is the terminal program that implements the functions associated with control codes, not the prop code - the prop code just sends out whatever you request blindly. There are some control codes that most terminal program implement, such as CR and LF. However, even these two have different implementations usually depending on whether it is running on a dos/windows/unix pc or a mac - there is usually a setting for at least these, and often others.
  • Peter JakackiPeter Jakacki Posts: 9,707
    edited 2020-09-27 - 00:53:58
    Form Feed code $0C or ^L will normally clear the whole screen on most terminal emulators and also Linux terminals. This is the code I use for all my devices for clear screen since form feed back in the line printer says would feed to the next page or form, effectively a "clear screen" in early terminal emulators and something which ANSI terminals support.

    P.S. I've always wondered why PST pays no regard to these terminal standards and seems to be setup to emulate serial LCD codes for compatibility. What is needed in PST is an "LCD emulation mode" button just for that.
  • Clock LoopClock Loop Posts: 1,940
    edited 2020-09-27 - 02:52:18
    Using Putty on second serial port of the PPDB.

    @Clock Loop, Guess I make some less than optimal assumptions on the PUTTY setup. Had not looked for a PUTTY setup screen such as you have posted. Gonna revisit that one now. Thx
    Close but I need to dig more on escape sequences.

    I know the parallax serial terminal ascii codes do not work the same in putty, I don't use them.
    I strictly stick to ansi escape codes with putty, putty doesn't have a setup screen like the pst does(thats the image i posted from parallax serial terminal)

    The way they work is you first must SET COMMAND MODE before every command.
    And you must do it again if you issue another ansi command.
    And again if you issue yet another command.

    The sequence is, set command mode, then set the command, then send the text.


    https://forums.parallax.com/discussion/comment/1453119/#Comment_1453119
    Here are some escape sequences:
        '--------------SOME ANSI COMMAND CODE INFO---------
            'term.str(string(27))  'Set command mode          
            'term.str(string("[2J")) 'clear screen
                      
            'term.str(string(27))    'Set command mode
            'term.str(string("[0m")) 'Turn off character attributes
    
            'term.str(string(27))    'Set command mode
            'term.str(string("[1m")) 'Turn bold mode on
    
            'term.str(string(27))    'Set command mode
            'term.str(string("[2m")) 'Turn low intensity mode on
    
            'term.str(string(27))    'Set command mode
            'term.str(string("[4m")) 'Turn underline mode on
    
            'term.str(string(27))    'Set command mode
            'term.str(string("[5m")) 'Turn blinking mode on
    
            'term.str(string(27))    'Set command mode
            'term.str(string("[7m")) 'Turn reverse video on    
    
            'term.str(string(27))    'Set command mode
            'term.str(string("[8m")) 'Turn invisible text mode on
    
            'term.str(string(27))    'Set command mode     
            'term.str(string("#3"))  'Double-height letters, top half 
    
            'term.str(string(27))    'Set command mode     
            'term.str(string("#4"))  'Double-height letters, bottom half 
    
            'term.str(string(27))    'Set command mode     
            'term.str(string("#5"))  'Single width, single height letters 
    
            'term.str(string(27))    'Set command mode     
            'term.str(string("#6"))  'Double width, single height letters
    
            { 
            Esc#3   Double-height letters, top half         DECDHL
            Esc#4   Double-height letters, bottom half      DECDHL
            Esc#5   Single width, single height letters     DECSWL
            Esc#6   Double width, single height letters     DECDWL
            }
    
    


    For putty and ansi escape codes, heres how I do it in an accelerometer debug output to the putty terminal.
    https://forums.parallax.com/discussion/comment/1507383/#Comment_1507383
    Repeat                'The main repeat loop.  Cog#2
        ser.str(string(27))     'Set ansi command mode in putty.
        ser.str(string("[2J"))  'Clear putty telnet screen. 
        
        ser.str(string(27))      'Set ansi command mode in putty.                 
        ser.str(string("[2;3f")) 'Set Position in putty.      
        ser.str(string("Put your text here."))  'Send text to the putty terminal. 
                        
        ser.str(string(27))      'Set ansi command mode in putty.      
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[4;3f")) 'Set Position in putty
                                                               
        If ReplyStatus == 1     
          ser.str(string("Good reply."))   'If last reply was good, put it back up on putty which was cleared.
          ReplyStatus := 0                                 '                
        Else
          ser.str(string("  No reply."))    'If last reply was none, put it back up on putty which was cleared.   
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[5;3f")) 'Set Position in putty 
        ser.str(string("Tilt X that the Prop sent: ")) '
        ser.dec(long[@TiltX][0])
        
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[6;3f")) 'Set Position in putty 
        ser.str(string("Tilt Y that the Prop sent: ")) '
        ser.dec(long[@TiltY][0])
                                                  
        ser.str(string(27))      'Set ansi command mode in putty.                                               
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0   
    

  • Clock LoopClock Loop Posts: 1,940
    edited 2020-09-27 - 02:53:17
    Heres the code from my trillion year clock, it shows many more uses of color, large text, half height text etc..

    I removed all the code except the ansi command codes and sequences.
    https://hackaday.io/project/162734-a-trillion-year-clock
    '' =================================================================================================
    '   File......  TrillionYearClock.spin    
    '   Purpose...  Trillion Year Clock Telnet RGB Led Timer Eeprom Demo
    '   Author....  Clock Loop @ parallax forums 
    '   Started...  2016...
    '   Updated...  2018... See you in a trillion years.
    '' =================================================================================================
    Pub  PaintScreen 
                  
          term.str(string(27))  'Set command mode          
          term.str(string("[2J")) 'clear screen      
          
          term.str(string(27))  'Set command mode  
          term.str(string("[2;3f")) 'position
    
          term.str(string(27))   'Set command mode  
          term.str(string("[35m")) 'Purple color text
    
          term.str(string(27))   'Set command mode
          term.str(string("[1m")) 'Turn bold mode on 
    
          'term.str(string(27))   'Set command mode
          'term.str(string("[4m")) 'Turn underline mode on
    
          term.str(string(27))   'Set command mode 
          term.str(string("#3"))  'Double-height letters, top half 
          term.str(string("Trillion Year Clock"))
    
          term.str(string(27))  'Set command mode  
          term.str(string("[3;3f")) 'position
    
          term.str(string(27))   'Set command mode 
          term.str(string("#4"))  'Double-height letters, bottom half 
          term.str(string("Trillion Year Clock")) 
    
          'term.str(string(27))    'Set command mode 
          'term.str(string("[1;1f"))  'Set Position
          
          'term.str(string(27))    'Set command mode
          'term.str(string("[0m")) 'Turn off character attributes
    
          term.str(string(27))  'Set command mode  
          term.str(string("[2;25f")) 'position 
                                               
          'term.str(string(27))   'Set command mode
          'term.str(string("[1m")) 'Turn bold mode on 
                                  '
          term.str(string(27))    'Set command mode
          term.str(string("[33m")) 'Yellow color text
                                   '
          term.str(string(27))   'Set command mode 
          term.str(string("#3"))  'Double-height letters, top half 
          term.str(string("Ticker   : "))
                                         
          If Secs < 10
            term.dec(0)
          term.dec(Secs)           
          
          term.str(string(27))    'Set command mode 
          term.str(string("[2;39f"))  'Set Position
            
          term.dec(TenthTimer)
          term.str(string("   "))
    
          term.str(string(27))  'Set command mode  
          term.str(string("[3;25f")) 'position
    
          term.str(string(27))   'Set command mode 
          term.str(string("#4"))  'Double-height letters, bottom half 
          term.str(string("Ticker   : ")) 
      
          If Secs < 10
            term.dec(0)
          term.dec(Secs)
          
          term.str(string(27))    'Set command mode 
          term.str(string("[3;39f"))  'Set Position
            
          term.dec(TenthTimer)
          term.str(string("   "))
          
          term.str(string(27))    'Set command mode
          term.str(string("[0m")) 'Turn off character attributes
                                  
          term.str(string(27))    'Set command mode 
          term.str(string("[1;1f"))  'Set Position     
                                 
        '----------------------------------------------
            'term.str(string(27))  'Set command mode          
            'term.str(string("[2J")) 'clear screen
                      
            'term.str(string(27))    'Set command mode
            'term.str(string("[0m")) 'Turn off character attributes
            'term.str(string("[1m")) 'Turn bold mode on
            'term.str(string("[2m")) 'Turn low intensity mode on
            'term.str(string("[4m")) 'Turn underline mode on
            'term.str(string("[5m")) 'Turn blinking mode on
            'term.str(string("[7m")) 'Turn reverse video on    
            'term.str(string("[8m")) 'Turn invisible text mode on
         
            'term.str(string("#3"))  'Double-height letters, top half 
            { 
            Esc#3   Double-height letters, top half         DECDHL
            Esc#4   Double-height letters, bottom half      DECDHL
            Esc#5   Single width, single height letters     DECSWL
            Esc#6   Double width, single height letters     DECDWL
            }
            
                            
            'term.str(string(27))', HOME, LF, LF))
            'term.str(string(27))
            
            'term.str(string(27))    'Set command mode 
            'term.str(string("[1;1f"))  'Set Position
           
            'term.str(string(27))  'Set command mode           
            'term.str(string("[4;5f"))  'Set Position
             
            'term.str(string(27))  'Set command mode 
            'term.str(string("[30m")) 'Black color text
            'term.str(string("[31m")) 'Red color text
            'term.str(string("[32m")) 'Lime color text
            'term.str(string("[33m")) 'Yellow color text
            'term.str(string("[34m")) 'Blue color text  
            'term.str(string("[35m")) 'Purple color text
            'term.str(string("[36m")) 'SkyBlue color text  
            'term.str(string("[37m")) 'White color text
                                         
            term.str(string(27))    'Set command mode 
            term.str(string("[5;5f"))  'Set Position 
                                        '
            term.str(string(27))  'Set command mode 
            term.str(string("[32m")) 'Lime color text
            
            term.str(string("RunTime  : "))  
    
            term.dec(uTrillionYears)       
            term.str(string(":TrillionYears  "))
                                       
            term.dec(uBillionYears)       
            term.str(string(":BillionYears   "))
            
            term.dec(uMillionYears)       
            term.str(string(":MillionYears   "))
            
            term.dec(uMillennium)       
            term.str(string(":Millennium  "))
            
            term.str(string(27))    'Set command mode 
            term.str(string("[6;16f"))  'Set Position 
            
            term.dec(uCentury)       
            term.str(string(":Century   "))
            
            term.dec(uDecade)       
            term.str(string(":Decade   "))
            
            term.dec(uYears)       
            term.str(string(":Years  "))
            
            term.dec(uDayz)       
            term.str(string(":Days   "))
            
            term.dec(uHour)       
            term.str(string(":Hours   "))
    
            term.dec(uMnit)       
            term.str(string(":Min   "))
    
            term.str(string(27))    'Set command mode 
            term.str(string("[1;1f"))  'Set Position
    
            term.str(string(27))    'Set command mode 
            term.str(string("[8;5f"))  'Set Position 
    
            term.str(string(27))  'Set command mode 
            term.str(string("[31m")) 'Red color text  
            
            term.str(string("UpTime   : "))
    
            term.dec(TrillionYears)       
            term.str(string(":TrillionYears  "))
            
            term.dec(BillionYears)       
            term.str(string(":BillionYears   "))
            
            term.dec(MillionYears)       
            term.str(string(":MillionYears   "))
            
            term.dec(Millennium)       
            term.str(string(":Millennium  "))
            
            term.str(string(27))    'Set command mode 
            term.str(string("[9;16f"))  'Set Position 
            
            term.dec(Century)       
            term.str(string(":Century   "))
            
            term.dec(Decade)       
            term.str(string(":Decade   "))
    
            term.dec(Years)       
            term.str(string(":Years  "))
            
            term.dec(Dayz)       
            term.str(string(":Days   "))
            
            term.dec(Hour)       
            term.str(string(":Hours   "))
    
            term.dec(Mnit)       
            term.str(string(":Min   "))        
    
    Pub DotOff
    
        term.str(string(27))    'Set command mode 
        term.str(string("[2;38f"))  'Set Position
                                    '
        term.str(string(27))   'Set command mode
        term.str(string("[1m")) 'Turn bold mode on 
                                
        term.str(string(27))   'Set command mode  
        term.str(string("[35m")) 'Purple color text                            
                                  
        term.str(string(27))   'Set command mode 
        term.str(string("#3"))  'Double-height letters, top half 
                                
        term.str(string("."))                               
          
        term.str(string(27))    'Set command mode 
        term.str(string("[3;38f"))  'Set Position
                                    
        term.str(string(27))   'Set command mode 
        term.str(string("#4"))  'Double-height letters, bottom half                           
           
        term.str(string("."))
        
        term.str(string(27))    'Set command mode 
        term.str(string("[1;1f"))  'Set Position                                                        
                                                                    
    Pub DotOn
    
        term.str(string(27))    'Set command mode 
        term.str(string("[2;38f"))  'Set Position
                                    '
        term.str(string(27))   'Set command mode
        term.str(string("[1m")) 'Turn bold mode on 
                                
        term.str(string(27))   'Set command mode  
        term.str(string("[37m")) 'White color text                            
                                  
        term.str(string(27))   'Set command mode 
        term.str(string("#3"))  'Double-height letters, top half 
                                
        term.str(string("."))                               
          
        term.str(string(27))    'Set command mode 
        term.str(string("[3;38f"))  'Set Position
                                    
        term.str(string(27))   'Set command mode 
        term.str(string("#4"))  'Double-height letters, bottom half                           
           
        term.str(string("."))
        
        term.str(string(27))    'Set command mode 
        term.str(string("[1;1f"))  'Set Position                                                                              
                          
    Dat
    
    {{
    
      Terms of Use: MIT License
    
    }}
    
  • frank freedmanfrank freedman Posts: 1,729
    edited 2020-09-27 - 04:21:59
    @Clock Loop
    Nice, this will do very nicely for what I am trying to do. Thank you. If I get it right, I can place the labels on the screen where I want and then paste the values as needed whenever on an ANSI compliant terminal?
  • You do know that you can chain stuff in one string, right?
          term.str(string(27))  'Set command mode          
          term.str(string("[2J")) 'clear screen      
          term.str(string(27))  'Set command mode  
          term.str(string("[2;3f")) 'position
    

    becomes
          term.str(string(27, "[2J", 27, "[2;3f"))  'Clear screen and position.        
    

    -Phil
  • Clock LoopClock Loop Posts: 1,940
    edited 2020-09-27 - 05:33:05
    @Clock Loop
    Nice, this will do very nicely for what I am trying to do. Thank you. If I get it right, I can place the labels on the screen where I want and then paste the values as needed whenever on an ANSI compliant terminal?

    Thats exactly it, with ansi, you tell it what position you want your text.
    There are other command codes, but I do not know exactly which ones will work in putty.
    https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences

    All the ones in my example code above do work, i know that (so the text attributes and colors, cursor positioning etc)
    For some, needing to set the exact position of all text is annoying, but personally I love it, even though it gets kinda repetitive.

    Clear the screen at the first part of the loop.
    You don't HAVE to do this, but it prevents serial data output corruption that sometimes happens.
    Overwriting specific positions is possible but I found that when you don't repaint it all, things start to deteriorate.
    Repeat
          term.str(string(27))  'Set command mode          
          term.str(string("[2J")) 'clear screen 
    

    Set any special text features, like color or bold, etc.
          term.str(string(27))  'Set command mode 
          term.str(string("[31m")) 'Red color text
    
          term.str(string(27))  'Set command mode 
          term.str(string("[1m")) 'Turn bold mode on
    

    Set your position, this one is 3 lines down, 5 spaces in. Set the cursor position right before you output your text
    or you will have annoying blinking cursors all over the place in your terminal.
          term.str(string(27))  'Set command mode  
          term.str(string("[3;5f")) 'set position
    

    Output the text and values
          term.str(string("This is your variable:  "))
          term.dec(decimaldatavariable)
    

    Always set the cursor position back to 1,1 before you do any thing else in your code,
    or you will have annoying blinking cursors all over the place in your terminal.
          term.str(string(27))      'Set ansi command mode in putty.                                               
          term.str(string("[1;1f")) 'Set Position in putty to put cursor at 1,1 
    



    FYI, I THINK TEXT ATTRIBUTES STAY ON, until you turn them off or change the attributes.
    There is a command to turn off all attributes...
          term.str(string(27))    'Set command mode
          term.str(string("[0m")) 'Turn off character attributes
    
  • Clock LoopClock Loop Posts: 1,940
    edited 2020-09-27 - 05:36:09
    You do know that you can chain stuff in one string, right?

    -Phil

    Oh right, I suppose that does reduce code space and timing...
    My brain forgets things faster than a cat does, so I end up writing everything out, slow, clunky, and like a moron.
    That way I can read it 2 years from now and not scratch my head wondering wtf, and how did I even figure that out...
Sign In or Register to comment.