Skip to content

Commit

Permalink
完善默认脚本,加上等待超时实例
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Jun 26, 2019
1 parent 1f634e5 commit 78345fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 1 addition & 6 deletions llcom/DefaultFiles/core_script/head.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ function print(...)
arg = { ... }
local logAll = {}
for i=1,select('#', ...) do
if type(arg[i]) ~= "string" then
table.insert(logAll, tostring(arg[i]))
else
local str = apiUtf8ToHex(arg[i]):fromHex()
table.insert(logAll, str)
end
table.insert(logAll, tostring(arg[i]))
end
apiPrintLog(table.concat(logAll, "\t"))
end
Expand Down
14 changes: 9 additions & 5 deletions llcom/DefaultFiles/user_script_run/example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@

--注册串口接收函数
uartReceive = function (data)
log.info("uartReceive",data)
log.info("uart receive",data)
sys.publish("UART",data)--发布消息
end

--新建任务,等待接收到消息再继续运行
sys.taskInit(function()
while true do
local _,udata = sys.waitUntil("UART")--等待消息
log.info("task waitUntil",udata)
local sendResult = apiSendUartData("ok!")--发送串口消息
log.info("uart send",sendResult)
--等待消息,超时1000ms
local r,udata = sys.waitUntil("UART",1000)
log.info("uart wait",r,udata)
if r then
--发送串口消息,并获取发送结果
local sendResult = apiSendUartData("ok!")
log.info("uart send",sendResult)
end
end
end)

Expand Down

0 comments on commit 78345fd

Please sign in to comment.