打开串口,发送十六进制数据并等待响应

时间:2018-01-19 14:43:10

标签: batch-file serial-port

假设我想将0x42(十六进制)传递给串口。我的串口连接到卡自动售货设备。

如何在.bat文件中编写它,然后等待设备本身的响应。

现在我可以做的是将字符串设为十六进制。

@echo off
setlocal EnableDelayedExpansion

rem Store the string in chr.tmp file
set /P "=%~1" < NUL > chr.tmp

rem Create zero.tmp file with the same number of Ascii zero characters
for %%a in (chr.tmp) do fsutil file createnew zero.tmp %%~Za > NUL

rem Compare both files with FC /B and get the differences
set "hex="
for /F "skip=1 tokens=2" %%a in ('fc /B chr.tmp zero.tmp') do set "hex=!hex!%%a"

del chr.tmp zero.tmp
echo %hex%

0 个答案:

没有答案