+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Junior Member level 3
    Points: 321, Level: 3

    Join Date
    Oct 2016
    Posts
    30
    Helped
    0 / 0
    Points
    321
    Level
    3

    Program to write in a terminal every period of time

    Hi,

    I need to program the computer for him to write some words every 10 seconds in tera term terminal.
    For exemple, I need him to write for exemple
    Abc+enter key, def+enter key, ghi+enter key, klmn+enter key. etc....(in loop)

    IN the terminal, I would like it to be written this way
    Abc+enter key
    wait 10 seconds
    def+enter key
    wait 10 seconds
    ghi+enter key
    wait 10 seconds
    klmn+enter key
    wait 1minute
    Abc+enter key
    wait 10 seconds
    def+enter key
    wait 10 seconds
    ghi+enter key
    wait 10 seconds
    etc.....(in loop)
    Is it possible to do ? If yes, can you please tell me how?

    Thank you

    •   Alt26th September 2017, 16:39

      advertising

        
       

  2. #2
    Junior Member level 1
    Points: 2,288, Level: 11

    Join Date
    Oct 2005
    Location
    Mexico
    Posts
    15
    Helped
    4 / 4
    Points
    2,288
    Level
    11

    Re: Program to write in a terminal every period of time

    Just use a python script that load the commands from a file

    Commands.txt
    Code:
    Abc
    def
    ghi
    klmn
    Code Python - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    
    import os
    import serial
    import time
     
    fcmd = open("Commands.txt")
    commands = fcmd.read().split("\n")[:-1]
     
    cmd_len = len(commands)
     
    # Serial Port open
     
    ser = serial.Serial('COM3',38400,
                        parity=serial.PARITY_NONE,
                        stopbits=serial.STOPBITS_ONE,
                        bytesize=serial.EIGHTBITS
                        )
     
    time.sleep(2)
     
    i=0
    while(1):
        cmd = commands[i]
        i = (i+1) % cmd_len
        print(cmd)
        ser.write("%s\n"%cmd)
        time.sleep(10)
     
    ser.close()


    1 members found this post helpful.

    •   Alt26th September 2017, 17:04

      advertising

        
       

  3. #3
    Junior Member level 3
    Points: 321, Level: 3

    Join Date
    Oct 2016
    Posts
    30
    Helped
    0 / 0
    Points
    321
    Level
    3

    Re: Program to write in a terminal every period of time

    I am using windows 10 and downloaded python 3.6.2 shell
    When I type import serial from the python, I get this error
    Code:
    >>> import serial
    Traceback (most recent call last):
      File "<pyshell#12>", line 1, in <module>
        import serial
    ModuleNotFoundError: No module named 'serial'
    and when I type fcmd = open("Commands.txt")
    I get this one
    Code:
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
    How can I correct that ?



    •   Alt26th September 2017, 22:18

      advertising

        
       

  4. #4
    Advanced Member level 5
    Points: 11,570, Level: 25
    Achievements:
    7 years registered

    Join Date
    Apr 2010
    Posts
    1,770
    Helped
    385 / 385
    Points
    11,570
    Level
    25

    Re: Program to write in a terminal every period of time

    One option is to write a code with the following flow:

    Make a character array of strings consisting of all messages .

    main routine will read the string one by one and display it in terminal.
    Call delay of 10 seconds .
    and reapeat the above for next string

    until end of string.



--[[ ]]--