File tree 1 file changed +11
-4
lines changed 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 3
3
# Copyright Peter Hinch 2017-2022 Released under the MIT license
4
4
# Link X1 and X2 to test.
5
5
6
+ # We run with no UART timeout: UART read never blocks.
6
7
import uasyncio as asyncio
7
8
from machine import UART
9
+
8
10
uart = UART (4 , 9600 , timeout = 0 )
9
11
12
+
10
13
async def sender ():
11
14
swriter = asyncio .StreamWriter (uart , {})
12
15
while True :
13
- swriter .write (' Hello uart\n ' )
16
+ swriter .write (" Hello uart\n " )
14
17
await swriter .drain ()
15
18
await asyncio .sleep (2 )
16
19
20
+
17
21
async def receiver ():
18
22
sreader = asyncio .StreamReader (uart )
19
23
while True :
20
24
res = await sreader .readline ()
21
- print ('Received' , res )
25
+ print ("Received" , res )
26
+
22
27
23
28
async def main ():
24
29
asyncio .create_task (sender ())
25
30
asyncio .create_task (receiver ())
26
31
while True :
27
32
await asyncio .sleep (1 )
28
33
34
+
29
35
def test ():
30
36
try :
31
37
asyncio .run (main ())
32
38
except KeyboardInterrupt :
33
- print (' Interrupted' )
39
+ print (" Interrupted" )
34
40
finally :
35
41
asyncio .new_event_loop ()
36
- print ('as_demos.auart.test() to run again.' )
42
+ print ("as_demos.auart.test() to run again." )
43
+
37
44
38
45
test ()
You can’t perform that action at this time.
0 commit comments