8 Star 26 Fork 14

wibim / luat-jt808

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
uartcan.lua 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
wibim 提交于 2020-02-15 14:44 . 第一次上代码
--[[
模块名称:uartcan
模块功能:can收发
模块最后修改时间:2019.04.18
]]
require "utils"
require "pm"
module(...,package.seeall)
-- 配置串口1 -- 蓝牙通信口
pm.wake("mcuUart.lua")
uart.setup(1, 115200, 8, uart.PAR_NONE, uart.STOP_1)
uart.on(1, "receive", function()sys.publish("UART1_RECEIVE") end)
-- 串口读指令
local function read(uid, timeout)
local cache_data = ""
if timeout == 0 or timeout == nil then timeout = 20 end
sys.wait(timeout)
while true do
local s = uart.read(uid, "*l")
if s == "" then
return cache_data
else
cache_data = cache_data .. s
end
end
end
function write(uid, s)
log.info("testUart.write", s)
uart.write(uid, s)
end
-- 串口收到什么就返回什么
sys.taskInit(function()
while true do
if sys.waitUntil("UART1_RECEIVE", 1000) then
local dat = read(1, 20)
log.info("串口收到的数据:", dat)
write(1, dat)
else
write(1, "read wait timeout!")
end
end
end)
Lua
1
https://gitee.com/wibim/luat-jt808.git
git@gitee.com:wibim/luat-jt808.git
wibim
luat-jt808
luat-jt808
master

搜索帮助