use the output automatically

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hdgmbh
Posts: 1
Joined: 14 Oct 2019 07:29

use the output automatically

#1 Post by hdgmbh » 14 Oct 2019 07:33

We connect a smartphone to our computer.
automatically the smartphone get a random COM-port.

with this script we detect the correct PORT:

Code: Select all

@echo off
setlocal
title MSM8998 Boot Recovery Program
mode con cols=110 lines=40

set port=

:RETRY
color a
cls
echo.
mode
echo.
echo ¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë¡ë
set /p port=Input Port Number[1~300,x:Exit]:
if "%port%" == "x" goto EXIT
for /L %%a in (1,1,300) do (
           IF "%port%" == "%%a" (
           		goto ChoiceOK
           )           
)
echo %port% is BAD!!
goto RETRY

goto ChoiceOK

:ChoiceOK

echo %port%

echo Start Recovery.
echo emmcdl.exe -p COM%port% -f prog_ufs_firehose_8998_ddr.elf -MemoryName ufs -SetActivePartition 1 -x rawprogram0.xml
emmcdl.exe -p COM%port% -f prog_ufs_firehose_8998_ddr.elf -MemoryName ufs -SetActivePartition 1 -x rawprogram0.xml
:EXIT

how is it possible automatically the use the correct PORT number and use it.
(because at the moment we have to type it in, manually by keyboard)


Thank you in advance!

pieh-ejdsch
Posts: 207
Joined: 04 Mar 2014 11:14
Location: germany

Re: use the output automatically

#2 Post by pieh-ejdsch » 15 Oct 2019 09:54

hello hdgmbh,

you can try
looks for ONE used com port.
or outputs the com port of the device to be connected.

Code: Select all

@echo off
echo looks for ONE used com port.
echo or outputs the com port of the device to be connected.
setlocal enabledelayedexpansion
set prompt=$G$S
set "exclude=;"
set "include=;"
call :findcom oldComDevices # N 
if %n% equ 0 echo NO device found ...
if %n% equ 1 echo 1 device found  skip/wait or ...
if %n% gtr 1 echo several devices found  please again or ...
echo  ... plug in next Device ...
timeout /t 12
call :findcom newComDevices ## N
if %n% equ 0 echo NO new device found ... sorry
if %n% equ 1 echo only 1 device where found ... is it correct?
if %n% gtr 1 echo several devices found please try again ... or use it
 rem last new device
set "com=!newComDevices_%##_%!"
if NOT defined com set "com=!oldComDevices_%#_%!"
if NOT defined com (echo NO com port ...) else echo  com=%com%
echo(
 rem echo exclude=%exclude:~1%
2>nul set oldcomdevices_
 rem echo include=%include:~1%
2>nul set newcomdevices_

pause
exit /b

:findcom
 rem find connection
set /a %2=1000, %3=0
set "%1="
<nul set/p"=scanning wait a moment please ....
for /l %%i in (1 1 300) do @ ( >nul mode com%%i
 if !errorlevel! == 0 (
  echo(
  set /a %2=1000+%%i, %3+=1
  set "%2=!%2:~-3!"
  if NOT defined com_!%2! (
   echo new Device found COM%%i
   set "%2_=!%2!"
   set "include=!include!%%i;"
   set "%1_!%2!=COM%%i"
   set "%1=!%1! !%2!=COM%%i;"
  ) else (
   set "exclude=!exclude!%%i;"
   set "include=!include:;%%i;=;!"
  )
  set "com_!%2!=COM%%i"
 ) 
 2>nul set/ai/=%%i%%5 || <nul set/p"=."
)
echo(
exit /b 
please give feedback

Phil

Post Reply