简体   繁体   中英

How to send a single digit number to a COM port from a batch file?

I need to send some single character commands from a batch file to a Bus Pirate hanging off a COM port, but I am having trouble sending single numbers.
If I send a double digit number it sends fine, it seems just the single digit numbers are a problem.

In the code below, the letters send fine, but the numbers don't seem to send at all.

Set "CNum=COM5" 
echo m>\\.\%CNum%
echo 4>\\.\%CNum%
echo 4>\\.\%CNum%
echo W>\\.\%CNum%
echo P>\\.\%CNum%

Is there a trick to get this working?

The problem is occurring because you are not using the full redirection handle, so the numeric string you are sending to the COM port is being mistaken for one. ie 1>\\.\COM5 .

You could use either:

Set "CNum=COM5" 
>\\.\%CNum% echo m
>\\.\%CNum% echo 4
>\\.\%CNum% echo 4
>\\.\%CNum% echo W
>\\.\%CNum% echo P

or:

Set "CNum=COM5" 
(echo m) >\\.\%CNum%
(echo 4) >\\.\%CNum%
(echo 4) >\\.\%CNum%
(echo W) >\\.\%CNum%
(echo P) >\\.\%CNum%

You may even want to try:

Set "CNum=COM5" 
(   echo m
    echo 4
    echo 4
    echo W
    echo P
) >\\.\%CNum%

or:

Set "CNum=COM5" 
>\\.\%CNum% (
    echo m
    echo 4
    echo 4
    echo W
    echo P
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM