tcp2uart.lua 314 B

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