tcp2uart.lua 385 B

123456789101112131415161718
  1. do
  2. uart.setup(0, 9600, 8, 0, 1, 0)
  3. local sv = net.createServer(net.TCP, 60)
  4. local global_c = nil
  5. sv:listen(9999, function(c)
  6. if global_c~=nil then
  7. global_c:close()
  8. end
  9. global_c = c
  10. c:on("receive",function(_, pl) uart.write(0, pl) end)
  11. end)
  12. uart.on("data", 4, function(data)
  13. if global_c ~= nil then
  14. global_c:send(data)
  15. end
  16. end, 0)
  17. end