KinGorbaZ
KinGorbaZ

Reputation: 73

PuTTY serial connection reconnect

I have a USB device that I'm connecting to with serial connection ttyUSB0 on port 115200.

Currently I'm using PuTTY to establish this connection.

The problem is that my usage requires to toggle the power (for 1 sec) of that device and the ttyUSB0 is getting lost (like I've unplugged the device). While toggling the power, the PuTTY disconnects automatically and I need to re-connect allover again.

I'm looking for solution that can keep the connection alive (or keep trying to reconnect) for few seconds (or more).

Thanks :)

Upvotes: 5

Views: 5306

Answers (3)

Henry
Henry

Reputation: 109

Here's a Windows cmd.exe solution. It's hard-coded to use COM3 (and the standard 115.2k baud rate, 8bit, no parity, one stop bit). I also redirect stderr to nul so you don't get thousands of error messages while the device reboots.

for /L %I in (1,0,2) do @(
  .\PuTTY\plink.exe -sercfg "115200,8,n,1" -serial COM3 2> nul
)

If you put this into a batch file / cmd script, remember to double the % character:

for /L %%I in (1,0,2) do @(
  .\PuTTY\plink.exe -sercfg "115200,8,n,1" -serial COM3 2> nul
)

Upvotes: 0

matthewk
matthewk

Reputation: 1

If you are using putty with a fddi or what not, you can unplug the USB for a second and putty will drop the connection, than you can use what ever other tool you want to use on the usb serial line. I am playing with esp8266's and I go back and forth between putty for watching and talking to the thing and DOS for programming it. I find it is much faster to keep the putty terminal set up all the time and just disconnect the serial line to disconnect putty. When you want puty back again use the restart session option in the dropdown menu.

Upvotes: 0

Martin Prikryl
Martin Prikryl

Reputation: 202098

You can use Plink (PuTTY command-line tool) in a loop in a batch file:

:start
plink -serial ... -sercfg ...
timeout /t 2
goto start

Upvotes: 1

Related Questions