I have an application that communicates via USB over COM and I usually use Putty to develop. Some of the users will use Teraterm instead and want the user experience to be as similar as possible.
In Putty, I can send a 0x7F which is ASCII "DEL" and when that value is echo'd back from my application, Putty does a backspace+delete (destructive backspace). With Teraterm, Backspace sends 0x08 which is ASCII "BS" (backspace) and, as long as the "Transmit DEL by:" box for Backspace Key is not checked, the key is returned as 0x08 without any delete (non-destructive backspace).
Is there any way to enable configuration of Teraterm to move cursor position back one character and delete that character when it receives the 0x08 command?
This has been a long time with no answer, so hopefully you worked through it. I don't understand if this scripted through the teraterm macro or if you are just manually navigating through teraterm.
But if this is for a script (.ttl) file or just a command within teraterm, and you know what string is being sent that needs this, you can do the following:
wait "[insert string you are looking for here]"
send 8 127
Where 8 means backspace and 127 means delete. Hope that helps. But teraterm will accept multiple ascii codes in one send command. The wait command could also be further rounded out to accept a timer for the wait action before it performs anything. The wait command can also accept up to 10 strings to wait for: https://ttssh2.osdn.jp/manual/en/macro/command/wait.html
You can also find the ASCII code table for teraterm here: https://ttssh2.osdn.jp/manual/en/macro/appendixes/ascii.html
Related
I am trying to send a message including carriage returns (represented without pressing enter) over a serial connection. It works if i press enter with an open serial connection, but I have not found a way to represent the carriage return character successfully within the message body. Need to reprsent the "CR" in txt file.
how could I close the file descriptor (fd) of the serial port before sending next command line?
Note: the modem documentation says: In order to successfully communicate with modem device, the ā$WPā prefix is required when issuing command and the "CR" is required for terminating the command line.
I tried minicom/picocom over /dev/ttyACM0, but same issues only first line of command is performed
You can use printf:
$ printf 'whatever\r' > /dev/ttyACM0
to send the CR
I succeeded using minicom with script.
It was necessary to consider answers sent by the modem to be able to proceed to the following command. What I managed to do with "expect" as following:
send <command>
expect "OK"
send <command>
expect "OK"
....
You can refer to minicom man page https://www.systutorials.com/docs/linux/man/1-runscript/
The goal is to connect to an embedded device using serial interface.
So far, I've used:
stty -F /dev/ttyS2 115200 cs8 ixoff
socat readline,history=/etc/socat.history /dev/ttyS2,raw,echo=0
And it works excellent, but then I discovered that there are some options during system boot that require you to press a single key without pressing enter, and readline fails there. So my idea was to bind the ttyS2 to cons0, but then I discovered multiple problems, such as inability to quit (ctr+c, ctr+q ctr+] and even esc doesn't work), backspace and delete do not work, letters are typed twice, etc. So after some trial and error, I came up with this:
socat /dev/cons0,raw,echo=0,crnl /dev/ttyS2,raw,echo=0,escape=0x03,crnl
raw on both sides allows a single key press to trigger a boot option
echo=0 on both sides prevents key press doubling
crnl on both sides prevent enter key press doubling
escape=0x03 allows me to quit the thing by pressing ctr+c
The problem is, when I quit, my cons0 is all f****d up, as if it somehow preserved the raw,echo=0,crnl settings. I know this problem is probably too specific for my scenario, but I just need a simple way to send keystrokes to serial as I would with putty (which is not available on my platform). I am using socat because it is extremely lightweight, does not require any aditional libraries, and because the shown commands are a part of the greater script that uses expect.
Any ideas and suggestions are greatly appreciated.
As Austin Phillips says, you can use stty sane to recover...
...but what is even better is that you can (probably) append it to your socat command as socat xxxxx ; stty sane and have the recovery be automatic when you quit with ctrl-c.
Thanks, that worked for me!
I just want to point out that the script should not rely on "static" console identification, because when expect spawns the script, it is going to have a completely different tty, therefor:
socat $(tty),raw,echo=0,escape=0x03 /dev/ttyS2,raw,echo=0,nonblock ; stty sane
edit: nonblock also solved the "enter" problem
im working on a keyboard injection for a /dev/tty device.
The only thing i found out was using the TIOCSTI ioctl command to inject text into the buffer. As far as good, but i also need to submit the command i typed in. Is there a way to send command keys like strg, return, shift, etc to a /dev/tty?
Thanks in advance.
Made some mistake in the past. You can send any ascii char via TIOCSTI, so sending an '\n' or ASCII 27 you simulate a press on Return.
Does Linux buffer keys typed in terminal so that you can read them later one key at a time?
I am asking because I want to catch ESC and arrow key presses and can't find a way to reliably read the codes. I put terminal in non-canonical mode and want program to block if there is no input, but if there is, I want to fetch only one key press for processing.
Update 2: Arrow keys is just an example. I need to identify key presses even for the keys with unknown escape sequences for my program.
There are two conflicting cases:
read(1) returns one character. For both function keys and ESC key this character will be 0x1b. To check if it was an arrow key, you need to read(1), which will block if only single ESC is pressed.
Solution: blocked read(1), non-blocked read(1)
Problem: if second read didn't match any function key, it may mean that it was buffered ESC followed by some sequence, or an unknown function key. How to detect unknown function key press?
read(4) returns at most 4 characters, but if you press ESC four times to let it buffer, you'll get a string of four 0x1b. The same problem to find out if there is an unknown function key press as above.
Can anybody explain how to deal with these problems in Linux terminal, or at least post a proof that Linux just doesn't have input buffer for keys?
You should read up on VT100 escape sequences.
You've discovered that the character code for the escape button (which is sent as a real character, but tends to be used almost exclusively for signalling the beginning of an escape sequence) is 0x1b.
To move the cursor UP: <ESC>[{COUNT}A
To move the cursor DOWN: <ESC>[{COUNT}B
To move the cursor RIGHT: <ESC>[{COUNT}C
To move the cursor LEFT: <ESC>[{COUNT}D
You can test these yourself by typing them into the terminal. Just type the keys one after another. My terminal does not recognize the count argument, but will work successfully if I type <ESC>[X (for X in A,B,C,D).
If your terminal isn't in VT100 mode, look up the escape sequences for whichever mode it's in. You might realize that depending too much on terminal specific escape codes restricts your program to one specific terminal type.
I have a switch (CLI based) that takes me to the present STP setting when you hit the alphabets (which iam able to automate with tcl) but when it comes to changing the STP setting say from RSTP to MSTP, manually, I have to hit the up arrow and down arrow keys( only option available).
I need help to give the up arrow and down arrow commands in tcl format to automate it.
I read about rlwrap but thats more of history/ file editing which may not be helpful for me.
I have tried the " ^[[A" and "[A" options and hexacodes with no success.
I have tried "\u001b[A" etc but the value STP does not change. The CLI is A XML CLI. This is my script .
spawn telnet $DUT1_IP expect "login:" send "$user\r" expect "Password:" send "$password\r" expect "sh-3.2#" #sleep 2 send "xml_cli\r" expect ">> " send "bridge_config_mode = STP"
If i have to change mode STP to MSTP i need to use up arrow key in my keyboard to change it to MSTP /RSTP . how to use in expect to handle the same . Please give your thoughts if we can use shell scripting for the same (or any other).
Thanks and Regards
Mo
Up is mapped by your system keyboard driver to a three-character sequence: ^[[A. The first character, rendered as ^[ here, is an Escape character that is not normally renderable on your screen, and you write a real one in a Tcl script with \u001b. Down is correspondingly ^[[B. (Strictly, it could be other character sequences ā it depends on the terminal type after all ā but virtually everything uses the same thing here, and thank goodness!)
Let's simplify things for you by putting those key sequences in variables (we also need a backslash before the real [ because it is a Tcl metasyntax character):
set up "\u001b\[A"
set down "\u001b\[B"
Now you can do this to send the characters to the remote side:
send $up
expect "...whatever..."
send $down
expect "...blah..."