2016-09-30 85 views
3

我有一個批處理文件,我想發送命令到串口COM1。我有以下,我可以看到它正確設置端口。但是,它在設置串口後停止,它不發送任何命令。批處理文件不發送串行命令

@ echo off 
color b0 
cls 
echo. 
echo.  
echo. Enter IP address of the CSR on the site. 
echo. Example: 11.152.34.82 
set /p IP="IP Address: " 
for /F "tokens=1,2,3,4 delims=." %%a in ("%IP%") do (
echo %%a, %%b, %%c, %%d 
set last=%%d 
set first=%%a 
set second=%%b 
set third=%%c 
) 
pause 
cls 
echo. select the technology you are trying to restore 
echo. 1: AWS 
echo. 2: PCS 
echo. 3: LTE 1 
echo. 4: LTE 2 
set /p tech="Enter number: " 
if "%tech%"=="1" goto AWS 
if "%tech%"=="2" goto PCS 
if "%tech%"=="3" goto LTE1 
if "%tech%"=="4" goto LTE2 
echo. Not found 
goto commonexit 

:AWS 
set /a z=%last% - 2 
set /a y=%last% - 25 
goto UMTSScript 

:PCS 
set /a z=%last% -3 
set /a y=%last% - 24 
goto UMTSScript 

:UMTSScript 
mode COM1 BAUD=9600 Parity=n DATA=8 
echo. command1 > COM1 
echo. command2 > COM1 
+0

也許命令不明白,因爲它的前面有一個空格?嘗試使用'echo command1> COM1'而不是'echo.'。 – soja

+0

試試看:'set/p「= COMMAND1」 \\。\ COM1' – Squashman

+0

請閱讀本幫助主題:[如何創建一個最小,完整和可驗證的示例](http://stackoverflow.com/幫助/ mcve) – aschipfl

回答

0

在腳本的開頭,第一行:

@echo off 

然後我會嘗試:

@echo command1>COM1 
@echo command2>COM1 

如果不行,我會嘗試:

@echo command1|COM1 
@echo command2|COM1 
+1

管道將無法正常工作,因爲在'|'的左側和右側有一個命令... – aschipfl