cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Script can not find available COM port automatically

Ivan Feoctistov
Associate II

Hi!

I'm talking here about script "StartTTPL4.bat".

I've removed "rem" before "pause" word at the end to see results of the script.

Results are: "Error! No Com port available !"

But I'm sute that it's available, because I can select it manually in teraterm and see in device manager (COM4 in my case).

Can I fix the script somehow to make it work automatically, how it should be?

What data do you need to help me with that?

I'm not strong enough in windows bash scripting.

There's full script log if I'll remove "rem" before "echo on" at the start.

C:\STM32SecuWS\Tools\teraterm>SET DIR_MYSCRIPT=C:\STM32SecuWS\Tools\teraterm\
 
C:\STM32SecuWS\Tools\teraterm>call :getport COMPORT
 
C:\STM32SecuWS\Tools\teraterm>FOR /F "tokens=4 USEBACKQ" %F IN (`mode | find " COM"`) DO (
echo %F
 if %F NEQ CON: SET COMPORT=%F
)
 
C:\STM32SecuWS\Tools\teraterm>echo Return : COMPORT
Return : COMPORT
 
C:\STM32SecuWS\Tools\teraterm>rem GOTO :EOF
 
C:\STM32SecuWS\Tools\teraterm>GOTO :End
 
C:\STM32SecuWS\Tools\teraterm>endlocal
 
C:\STM32SecuWS\Tools\teraterm>pause
any key to continue . . .
 
C:\STM32SecuWS\Tools\teraterm>if "" == "" goto ErrorCOM
 
C:\STM32SecuWS\Tools\teraterm>echo "Error! No Com port available !"
"Error! No Com port available !"
 
C:\STM32SecuWS\Tools\teraterm>goto End
 
C:\STM32SecuWS\Tools\teraterm>endlocal
 
C:\STM32SecuWS\Tools\teraterm>pause
any key to continue . . .

1 ACCEPTED SOLUTION

Accepted Solutions
Ivan Feoctistov
Associate II

I've found the problem.

Because of different language (russian in my case) parsing results from "mode" command was incorrect.

Parsing is done very simple, by taking 4th word from input (which is e.g. "COM4" or other number). In russian language needed word is 3rd.

So, if you're having problems with launching teratermcorrectly you can try this: run command "mode" in your command line and count position of it in string. After it, just replace digit '4' in "tokens=4" to a digit corresponding with position of word with COM port number.

That's all.

If you need help or more info - ask for it here and I'll try to explain.

View solution in original post

2 REPLIES 2
Ivan Feoctistov
Associate II

I've found the problem.

Because of different language (russian in my case) parsing results from "mode" command was incorrect.

Parsing is done very simple, by taking 4th word from input (which is e.g. "COM4" or other number). In russian language needed word is 3rd.

So, if you're having problems with launching teratermcorrectly you can try this: run command "mode" in your command line and count position of it in string. After it, just replace digit '4' in "tokens=4" to a digit corresponding with position of word with COM port number.

That's all.

If you need help or more info - ask for it here and I'll try to explain.

AlTishchenko
Associate

Was going to write the same, language pack is the problem.