编写脚本以通过与 PuTTY 的串行连接执行一系列命令 [英] Writing script to perform a series of commands over serial connection with PuTTY

查看:69
本文介绍了编写脚本以通过与 PuTTY 的串行连接执行一系列命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 RFID 阅读器,我需要通过串行端口连接(串行到 USB)定期下载数据.我一直在使用 PuTTY 连接到阅读器.我在 PuTTY 中保存了一个会话,其中包含供读者使用的所有正确参数,并将其命名为测试".我还在 Logging 下使用了 所有会话输出",以便将输出存储在一个文件中.我通过 Windows 10 命令行访问会话,如下所示:

I have an RFID reader that I need to download data from periodically via a serial port connection (serial to USB). I have been using PuTTY to connect to the reader. I saved a session in PuTTY with all of the correct parameters for the reader and named it "test". I also used "All session output" under Logging so that the output will be stored in a file. I access the session via the Windows 10 command line like this:

putty.exe -load "test"

并且终端看起来就像我通过 GUI 一样.然后,我想在 PuTTY 终端中运行一系列命令,该终端提供我需要的输出数据.例如,假设我需要运行的命令是:

and the terminal appears just like it would if I went though the GUI. I then have a series of commands that I would like to run in the PuTTY terminal which provides the output data I need. For example lets say the commands I need to run are:

DT
UH
SS
TF

我想以某种方式自动执行此过程,以便每次连接到阅读器时都会运行相同的命令.可以在 PuTTY 中编写脚本来执行此操作,还是可以将这些命令从命令行发送到 PuTTY?有人可以演示如何做到这一点吗?

I would like to automate this process somehow, so that every time I connect to the reader the same commands are run. Can a script be written to do this in PuTTY or can these commands be sent to PuTTY from the command line? Could someone demonstrate how to do this?

推荐答案

PuTTY 不是自动化的正确工具,请使用 Plink:
使用 PuTTY 自动执行命令/脚本

PuTTY is not the right tool for automation, use Plink:
Automating command/script execution using PuTTY

您只需要知道在 Plink 命令上指定命令,或使用 Plink 常用的 -m 开关(-m 甚至与 PuTTY)一起使用仅限 SSH 协议.

You just need to know specifying the commands on Plink command-like or with the -m switch commonly used with Plink (the -m even with PuTTY) works with the SSH protocol only.

对于其他协议,尤其是串行连接,您只能使用输入重定向(也包含在我对上面链接的问题的回答中),如下所示:

With other protocols, notably with the serial connections, you can use the input redirection only (also covered in my answer to the question linked above), like this:

plink.exe -load "my serial connection" < c:\local\path\commands.txt

plink.exe -serial COMx -sercfg 19200,8,n,1,X < c:\local\path\commands.txt

另请参阅通过 Plink 串行连接在设备上执行命令.

(这是 GUI PuTTY 无法做到的,因此对于这种方法,Plink 是最佳选择).

(And this is something that you cannot do with GUI PuTTY, so for this approach, Plink is the way to go).

这篇关于编写脚本以通过与 PuTTY 的串行连接执行一系列命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆