executing a batch or script of commands using Putty - serial-port

Currently I dial in to a site with putty and copy all 100 commands using notepad++ and paste them into putty using right click and they all give me the expected results.
I don't want to have to copy and paste each time I connect.
I am trying to use putty to load a saved session and then execute a series of commands.
can this be done with a serial connection ??
this is as far as I can get
my batch file looks like this
plink -load session1 < commands.cmd > output.txt
for testing my commands.cmd looks like this
ATDT5551212
functionally this is fine for dialing and executing a single line as my output.txt file looks like this
ATDT5551212
CONNECT 1200
so I know I can grab a command from a file and send the output of the session to another file...
if I add another command after the ATDT line then it fails to work properly however my output file shows it sent all the commands
The problem is after dialing and connecting I want to be able to send another set of about 100 commands to get programming data out of a serial device and record it to text.
How can I set this up as a batch to wait for the CONNECT 1200 and then execute another 100 different commands
I tried as Martin suggested to change the EOL
I added STXcommandETX and also separately tried an EOT and ESC and nothing changes its just dumping the entire command file and only executing the first line. the modem gets bombarded with all the other lines or commands, it is attempting to execute the first line and then subsequently trying to give a response meanwhile plink just took the entire commands.cmd and dumps it at the modem and the modem is not expecting the dump.
My guess is that plink can open and send my commands but cant interact with the Serial putty window once it is open.
I am trying another program called ScriptCommunicator but am still testing plink/putty

Related

Configure TeraTerm to wait for "Enter" key stroke? Or solve PuTTY COM connection error

I am using TeraTerm to send strings over COM port using the Serial connection in TeraTerm. I had tried to use PuTTY but it refuses to connect to the COM port and I am not sure why. It says
Unable to open connection to COM4
Unable to configure serial port
That is neither here nor there, but it does mean that PuTTY like will not be usable for my application.
One thing PuTTY does well, though, is it includes the option for "Local line editing" which means I can make the serial window wait for the "Enter" keystroke before it sends it over COM port. I am looking for a way to make TeraTerm do that as well as right now it sends every character as it is entered into the window.
ie if I type in the word "Test", the window is sending T/r/n, e/r/n, s/r/n, t/r/n as opposed to Test/r/n
If someone could help me solve this in TeraTerm, or help me fix my PuTTY connection, that would be much appreciated as well.
When typing characters into TT, the characters are sent out as you type them, and there is no way to configure it otherwise. If anything is sent with each character, this is configurable, but there is no way to configure TT in such a way to "send nothing" until you type 'enter', as other "terminals" do.
Some devices receive the commands in a buffered way and have a short timeout between the characters, so you are never able to "type" a command in TT. For example, many USB devices which use USB-to-serial internals (like ST development tools and MCUs). This is because the USB sends "frames" with each character you type, and the device expects to receive a "full command" in a frame, if the frame is not a valid command, is discarded.
When you type "test", unless you are lightning fast, four frames will be sent. If that is your case, you have to use another terminal program (there are plenty available). If for any reason you are restricted to TT, then you can use the following trick:
write the command in your favorite editor, like PN2, Notepad++, etc., (or even TT itself in a separate terminal, not connected to your target board) copy it with ctrl+c or whatever, and then switch to TT and press either alt+v or alt+r to send it out without, respective with, a CRLF ending (see the edit menu in TT/VT). The ending can be configured from the setup/terminal menu, and (if enabled in setup/additional_settings/copy_and_paste menu) the mouse's right or mid clicks can be also used.
I usually have a list of commands pre-written, opened in a different window, and instead of typing, the "work" is a sequence of "double click in pn2 window" (to select command), ctrl+c (to copy it), "right click in TT window" (to send it out).

How can I send printk message into ttyS0?

I'm trying to debug my PC using laptop and serial port.
So, I wanna get some printk log from tty connected laptop.
I referred this sites (https://help.ubuntu.com/community/SerialConsoleHowto), and I already set all of console setup on my laptop and I also saw the login session from laptop.
However, despite all my effort, I couldn't get the printk log message at the tty console (I also set /proc/sys/kernel/printk as 7417 to get all the message of printk).
The curious thing is, my local console (ctrl + alt + f1~f6) are printing the printk log at the same time.
So, how can I get printk message from tty connected host device?
thnks,
This command
dmesg -wH &
could be used to force all your kernel messages, that are printed to dmesg (and also the virtual terminals like Ctrl+Alt+F1 , depending on your /proc/sys/kernel/printk log level and a level of your message), to also appear at your SSH or GUI console: Konsole, Terminal or whatever you are using! Should also work for ttyS0 console, I hope. And, if you need to monitor only for the specific messages:
dmesg -wH | grep ERR &
I'm using it to monitor for the "ERROR" messages like
printk(KERN_EMERG "ERROR!\n");
that I printk from my driver

stty and sending carriage return

I have a serial device with which I am trying to communicate. This device knows when a complete command has been sent when the command string is terminated with a "\r". Thus, a typical command string might be something like "COMMAND \r".
I'm having trouble configuring stty in such a way that the carriage return gets sent to the device. Currently, the device will not respond to any of my commands, so it's as if the input to the device is still "hanging."
I've written some simple C code where I bypass the terminal and there I can successfully elicit replies from the device, which is the reason why I think that the commands are not being properly terminated in the terminal. I've tried many different permutations of -+onlcr, +icanon, etc to no avail. The baudrate, parity, data bits, start and stop bits are all properly configured, as far as I can tell.
How can I debug this issue?
What is the platform (machine)? What is the OS?
Have you tried to flush the output with
fflush( FILE * FP );
Tried COMMAND\r\n ? What's the device?

How can I "telnet" with the STDIO of another process?

Normally CouchDB communicates with a view server over STDIO via a simple line-based protocol.
What I want to do is, instead of a view server, have it read and write to some sort of pipe or pseudo terminal, to which I then connect, and play the view server.
I think one way to do it is with a lot of complicated use of cat and FIFO's.
But I found out that on my Mac echo "hi" > /dev/ttys000 comes back to my terminal, so I was thinking it should be possible to establish a connection this way, but I can't tell from manpages how to do it for real.
[update] I found write, which sends message from couch to my terminal, but couch is not attached, so I can't send messages in return.
nc -l 12345
And then a regular netcat to connect to it.

Prevent FIFO from closing / reuse closed FIFO

Consider the following scenario:
a FIFO named test is created. In one terminal window (A) I run cat <test and in another (B) cat >test. It is now possible to write in window B and get the output in window A. It is also possible to terminate the process A and relaunch it and still be able to use this setup as suspected. However if you terminate the process in window B, B will (as far as I know) send an EOF through the FIFO to process A and terminate that as well.
In fact, if you run a process that does not terminate on EOF, you'll still not be able to use your FIFO you redirected to the process. Which I think is because this FIFO is considered closed.
Is there anyway to work around this problem?
The reason to why I ran into this problem is because I'd like to send commands to my minecraft server running in a screen session. For example: echo "command" >FIFO_to_server. This is problably possible to do by using screen by itself but I'm not very comfortable with screen I think a solution using only pipes would be a simpler and cleaner one.
A is reading from a file. When it reaches the end of the file, it stops reading. This is normal behavior, even if the file happens to be a fifo. You now have four approaches.
Change the code of the reader to make it keep reading after the end of the file. That's saying the input file is infinite, and reaching the end of the file is just an illusion. Not practical for you, because you'd have to change the minecraft server code.
Apply unix philosophy. You have a writer and a reader who don't agree on protocol, so you interpose a tool that connects them. As it happens, there is such a tool in the unix toolbox: tail -f. tail -f keeps reading from its input file even after it sees the end of the file. Make all your clients talk to the pipe, and connect tail -f to the minecraft server:
tail -n +1 -f client_pipe | minecraft_server &
As mentioned by jilles, use a trick: pipes support multiple writers, and only become closed when the last writer goes away. So make sure there's a client that never goes away.
while true; do sleep 999999999; done >client_pipe &
The problem is that the server is fundamentally designed to handle a single client. To handle multiple clients, you should change to using a socket. Think of sockets as “meta-pipes”: connecting to a socket creates a pipe, and once the client disconnects, that particular pipe is closed, but the server can accept more connections. This is the clean approach, because it also ensures that you won't have mixed up data if two clients happen to connect at the same time (using pipes, their commands could be interspersed). However, it require changing the minecraft server.
Start a process that keeps the fifo open for writing and keeps running indefinitely. This will prevent readers from seeing an end-of-file condition.
From this answer -
On some systems like Linux, <> on a named pipe (FIFO) opens the named pipe without blocking (without waiting for some other process to open the other end), and ensures the pipe structure is left alive. For instance in:
So you could do:
cat <>up_stream >down_stream
# the `cat pipeline keeps running
echo 1 > up_stream
echo 2 > up_stream
echo 3 > up_stream
However, I can't find documentation about this behavior. So this could be implementation detail which is specific to some systems. I tried the above on MacOS and it works.
You can add multiple inputs ino a pipe by adding what you require in brackets with semi-colons in your 'mkfifo yourpipe':
(cat file1; cat file2; ls -l;) > yourpipe

Resources