Author Topic: Batch script for serial control  (Read 2692 times)

0 Members and 1 Guest are viewing this topic.

Offline Mad ProfessorTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Batch script for serial control
« on: January 18, 2023, 07:17:11 pm »
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: [Select]
@echo off
cls

set /p ComPortNumber=Enter Serial Port Number:

(
echo *IDN?
timeout /t 1 > nul
echo SETTINGS
timeout /t 1 > nul
) | "C:\Program Files\PuTTY\plink.exe" -v -serial COM%ComPortNumber% -sercfg 9600,8,1,n,X

The 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?\r
My batch script would result in the serial output of *IDN \r\n

I am not sure how to fix this issue, and welcome any suggestions.

Thanks for your time.

Best Regards.
« Last Edit: January 18, 2023, 07:19:52 pm by Mad Professor »
 

Offline buta

  • Contributor
  • Posts: 44
  • Country: au
Re: Batch script for serial control
« Reply #1 on: January 18, 2023, 08:58:26 pm »
my 2 cents

Using 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.txt

command.txt:
*IDN?
SETTINGS

If your equipment supports SCPI commands, python visa is an alternative.
 

Offline cantata.tech

  • Regular Contributor
  • *
  • Posts: 75
  • Country: au
Re: Batch script for serial control
« Reply #2 on: January 19, 2023, 02:11:35 am »
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.

 
The following users thanked this post: NiHaoMike

Offline PeteH

  • Supporter
  • ****
  • Posts: 114
  • Country: ca
Re: Batch script for serial control
« Reply #3 on: January 19, 2023, 02:20:09 am »
Please do this in python. You'll be happy you took the leap.
 
The following users thanked this post: NiHaoMike

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6087
  • Country: es
Re: Batch script for serial control
« Reply #4 on: January 19, 2023, 02:56:23 am »
Not sure if fits your needs, YAT terminal have programmable macros, so you can make tons of buttons, each one sending the specified command.
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12041
  • Country: ch
Re: Batch script for serial control
« Reply #5 on: January 19, 2023, 07:33:58 am »
I’ve been using the macro function in Coolterm, might be worth a shot: https://freeware.the-meiers.org/
 

Online bookaboo

  • Frequent Contributor
  • **
  • Posts: 738
  • Country: ie
Re: Batch script for serial control
« Reply #6 on: January 19, 2023, 09:18:13 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf