Skip to content

Commit 360fb59

Browse files
committed
add tcp2uart.lua example
1 parent 9b472a4 commit 360fb59

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

examples/fragment.lua

+18
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,21 @@ m:connect("192.168.18.101",1883)
319319
m:subscribe("/topic",0,function(m) print("sub done") end)
320320
m:on("message",function(m,t,pl) print(t..":") if pl~=nil then print(pl) end end )
321321
m:publish("/topic","hello",0,0)
322+
323+
uart.setup(0,9600,8,0,1,0)
324+
sv=net.createServer(net.TCP, 60)
325+
global_c = nil
326+
sv:listen(9999, function(c)
327+
if global_c~=nil then
328+
global_c:close()
329+
end
330+
global_c=c
331+
c:on("receive",function(sck,pl) uart.write(0,pl) end)
332+
end)
333+
334+
uart.on("data",4, function(data)
335+
if global_c~=nil then
336+
global_c:send(data)
337+
end
338+
end, 0)
339+

lua_examples/tcp2uart.lua

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
12+
uart.on("data",4, function(data)
13+
if global_c~=nil then
14+
global_c:send(data)
15+
end
16+
end, 0)

0 commit comments

Comments
 (0)