testUartSentFile.lua 1015 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --- 模块功能:串口功能测试(非TASK版,串口帧有自定义的结构)
  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 = 1
  11. function sendFile()
  12. sys.taskInit(
  13. function()
  14. local fileHandle = io.open("/testCamera.jpg","rb")
  15. if not fileHandle then
  16. log.error("testALiYun.otaCb1 open file error")
  17. return
  18. end
  19. pm.wake("UART_SENT2MCU")
  20. uart.on(uartID,"sent",function() sys.publish("UART_SENT2MCU_OK") end)
  21. uart.setup(uartID,115200,8,uart.PAR_NONE,uart.STOP_1,nil,1)
  22. while true do
  23. local data = fileHandle:read(1460)
  24. if not data then break end
  25. uart.write(uartID,data)
  26. sys.waitUntil("UART_SENT2MCU_OK")
  27. end
  28. uart.close(uartID)
  29. pm.sleep("UART_SENT2MCU")
  30. fileHandle:close()
  31. end
  32. )
  33. end