Batch script for serial control - Page 1
Forum section: electronics / projects

author: Mad Professor
author_rank: Regular Contributor
timestamp: January 18, 2023, 07:17:11 pm
content: Good day all.I am hoping that someone here might be able to give me some ideas on how best to carry out the following.I have a piece of equipment and all changes to the settings have to be manually typed via serial terminal, in my case I use PuTTY for this.As there is no software for this equipment, I wanted to try and write a little windows batch script that would send the serial commands for me.Unfortunately I can't seem to get my batch script to work correctly when sending the commands over serial via Plink (PuTTY Link).If I do everything manually via PuTTY it works, for example. I type *IDN? followed by the enter key, the command is sent and I get the desired response with serial number, firmware, etc.The same is true for any following commands.However my batch script works of sort, but fails when sending the serial commands.The first command is executed, but all following commands come back with an error.This is because the serial command(s) being sent are slightly changed. This was confirmed by checking with a logic analyzer.Snippet of the batch file.Code:@echo offclsset /p ComPortNumber=Enter Serial Port Number:(echo *IDN?timeout /t 1 > nulecho SETTINGStimeout /t 1 > nul) | "C:\Program Files\PuTTY\plink.exe" -v -serial COM%ComPortNumber% -sercfg 9600,8,1,n,XThe above is sending the commands, but is adding a Space and Line feed.For example again.Manual input via PuTTY would result in the serial output of*IDN?\rMy batch script would result in the serial output of*IDN \r\nI am not sure how to fix this issue, and welcome any suggestions.Thanks for your time.Best Regards.

author: buta
author_rank: Contributor
timestamp: January 18, 2023, 08:58:26 pm
content: my 2 centsUsing plink -m options, but I don't test this method:-m file read remote command(s) from file"C:\Program Files\PuTTY\plink.exe" -v -serial COM%ComPortNumber% -sercfg 9600,8,1,n,X -m command.txtcommand.txt:*IDN?SETTINGSIf your equipment supports SCPI commands, python visa is an alternative.

author: cantata.tech
author_rank: Regular Contributor
timestamp: January 19, 2023, 02:11:35 am
content: The basic problem is that if shells can't do the job of serial communications, then its because they have been dumbed down so they can't do that job.The shell looks like its filtering the characters because that is what it was made to do. Newlines are being filtered correctly.I would try writing the program in C or Python.

author: PeteH
author_rank: Unknown
timestamp: January 19, 2023, 02:20:09 am
content: Please do this in python. You'll be happy you took the leap.

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 19, 2023, 02:56:23 am
content: Not sure if fits your needs, YAT terminal have programmable macros, so you can make tons of buttons, each one sending the specified command.

author: tooki
author_rank: Super Contributor
timestamp: January 19, 2023, 07:33:58 am
content: I’ve been using the macro function in Coolterm, might be worth a shot:https://freeware.the-meiers.org/

author: bookaboo
author_rank: Frequent Contributor
timestamp: January 19, 2023, 09:18:13 am
content: As suggested Python may be the best fit for this, though I use Docklight for serial terminal stuff and the paid (reasonable perpetual licence fee) version has decent scripting.