问题描述
我正在使用 ESP8266 和 Nodemcu 与使用 Putty 的串行终端进行通信。 使用这些问题中引用的转义序列:
Read ANSI escape from terminal
How do I determine size of ANSI terminal?
转义序列列表 https://vt100.net/docs/vt100-ug/chapter3.html
我正在尝试回读一个转义序列,该序列是使用 LUA 查找光标位置的回复。我似乎没有得到明显的答复(预期),但我似乎也没有得到任何东西。除了回复之外的所有内容似乎都有效。
我做错了什么,如何捕获响应?
-- Clear screen
uart.write(0,"\033[2J")
-- Setup event handler callback to read data from terminal
-- Control sequence is terminated with an 'R'
-- I'm replacing ESC in the reply so that I can hopefully get a visible reply like _[25;80R
uart.on("data",function(data)
if data ~= 'R' then
uart.write(0,data)
end
if data == '\033' then
uart.write(0,"_")
end
end,0)
-- ESC = \033
-- cursorpos(v,h) CUP Move cursor to screen location v,h ^[[<v>;<h>H
uart.write(0,"\033[20;20H")
uart.write(0,"\033[6n")
-- Response:
-- cursorpos CPR Response: cursor is at v,h ^[<v>;<h>R
解决方法
看起来我的 uart 读取处理程序有语法错误。 我将 ESC 的 /033 更改为 CTRL-v[ 以及我的 IF 语句的条件。我不确定为什么 \033 不起作用。
为了测试,我还将 20;20 部分更改为 200;200 只是为了看看它是如何工作的,它给出了正确的预期响应:_[45;157R
我更改了代码:
uart.on("data",function(data)
if data ~= 'R' then
uart.write(0,data)
end
if data == '\033' then
uart.write(0,"_")
end
end,0)
致:
uart.on("data",function(data)
if data == '\27' then
uart.write(0,"_")
else
uart.write(0,data) end end,0)