coroutine使用错误,如果不熟练推荐直接用task框架里的任务+消息收发来实现
这是收发线程和http在线程在一起的,http在网络上的找json 然后串口还给单片机
module(...,package.seeall)
require"ril"
require"pins"
require"sys"
local a=0;
local uart_id=0;
local console_task
log.info("App_Task_YYJ")
local function Uart_Recive()
while true do
print("I find I")
--
end
end
function Uart_TimerTest()
uart_id = 1
baudrate = 115200
-- 创建console处理的协程
console_task = coroutine.create(Uart_Recive)
uart.setup(uart_id, baudrate, 8, uart.PAR_NONE, uart.STOP_1)
-- 串口收到数据时唤醒console协程
uart.on(uart_id, "receive", function()
coroutine.resume(console_task)
end)
coroutine.resume(console_task)
while true do
a=a+1
print("Uart_TimerTest.",a)
uart.write(uart_id,"123456")
sys.wait(1000);
end
end
function Http_TimerTest()
while true do
a=a+1
print("Http_TimerTest.",a)
sys.wait(1000);
end
end
sys.taskInit(Uart_TimerTest)
sys.taskInit(Http_TimerTest)
--sys.timerLoopStart(Uart_TimerTest, 3000)
--sys.timerLoopStart(Http_TimerTest, 3000)
--建立两个线程
--一个去守护串口
--一个去守护http连接
--开启一个循环定时器
--sys.timerLoopStart(loopTimerTest, 3000)
--如果关闭定时器,可以使用如下代码:
--sys.timerStop(timerTest)