Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Program to write in a terminal every period of time

Status
Not open for further replies.

Alex329

Junior Member level 3
Joined
Oct 14, 2016
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
272
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
 

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()

 
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 ?
 

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.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top