-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblynk-ser.bat
77 lines (62 loc) · 2.14 KB
/
blynk-ser.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@echo off
setlocal EnableDelayedExpansion
REM === Edit these lines to match your need ===
set COMM_PORT=COM3
set COMM_BAUD=9600
set SERV_ADDR=192.168.137.1
set SERV_PORT=8442
REM === Edit lines below only if absolutely sure what you're doing ===
rem Get command line options
:loop
IF NOT "%1"=="" (
IF "%1"=="-c" set COMM_PORT=%2& SHIFT & SHIFT & GOTO :loop
IF "%1"=="-b" set COMM_BAUD=%2& SHIFT & SHIFT & GOTO :loop
IF "%1"=="-s" set SERV_ADDR=%2& SHIFT & SHIFT & GOTO :loop
IF "%1"=="-p" set SERV_PORT=%2& SHIFT & SHIFT & GOTO :loop
CALL :usage
GOTO :eof
)
rem Find ports
set PORTS=
for /f "tokens=4 delims=: " %%A in ('mode^|findstr "COM[0-9]*:"') do IF not [%%A] == [] set PORTS=!PORTS! %%A
set PORTS=!PORTS:~1!
rem Check port
rem Skip check if no ports at all - Windows bug?
if not "x%PORTS%"=="x~1" (
if "x!PORTS:%COMM_PORT%=!"=="x%PORTS%" (
echo %COMM_PORT% not found, or may be busy.
set /p COMM_PORT="Select serial port [ %PORTS% ]: "
)
)
rem Create exe
if not exist com2tcp.exe (
copy com2tcp.bin com2tcp.exe
)
rem Do the job
echo Connecting device at %COMM_PORT% to %SERV_ADDR%:%SERV_PORT%...
rem Try resetting board
rem mode %COMM_PORT%:%COMM_BAUD%,N,8,1 >nul
:restart
com2tcp --baud %COMM_BAUD% --ignore-dsr \\.\%COMM_PORT% %SERV_ADDR% %SERV_PORT%
echo Reconnecting in 3s...
timeout /T 3
goto restart
goto:eof
:usage
echo.
echo. This script redirects serial communication to the server.
echo.
echo. You can specify port, baud rate, and server endpoint like this:
echo. blynk-ser.bat -c ^<serial port^> -b ^<baud^> -s ^<server^> -p ^<port^>
echo.
echo. The defaults are:
echo. -c /dev/ttyUSB0 (on Linux)
echo. COM1 (on Windows)
echo. /dev/tty.usbserial (on OSX)
echo. -b 9600
echo. -s blynk-cloud.com
echo. -p 8442
echo.
echo. If the specified serial port is not found, it will ask to enter another one.
echo. The script also tries to reestablish connection if it was lost.
goto:eof