testUart3SentFile.lua 947 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --- 模块功能:串口3功能测试
  2. -- @author openLuat
  3. -- @module uart.testUartTask
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2018.05.24
  7. module(...,package.seeall)
  8. require"utils"
  9. require"pm"
  10. local uartID = 3
  11. sys.taskInit(
  12. function()
  13. local fileHandle = io.open("/lua/mcu101.bin","rb")
  14. if not fileHandle then
  15. log.error("testALiYun.otaCb1 open file error")
  16. return
  17. end
  18. pm.wake("UART_SENT2MCU")
  19. uart.on(uartID,"sent",function() sys.publish("UART_SENT2MCU_OK") end)
  20. uart.setup(uartID,115200,8,uart.PAR_NONE,uart.STOP_1,nil,1)
  21. while true do
  22. local data = fileHandle:read(1460)
  23. if not data then break end
  24. uart.write(uartID,data)
  25. sys.waitUntil("UART_SENT2MCU_OK")
  26. end
  27. uart.close(uartID)
  28. pm.sleep("UART_SENT2MCU")
  29. fileHandle:close()
  30. end
  31. )