@@ -315,7 +315,7 @@ def remote_ip(self, socket_num):
315
315
316
316
@property
317
317
def link_status (self ):
318
- """"Returns if the PHY is connected."""
318
+ """ "Returns if the PHY is connected."""
319
319
if self ._chip_type == "w5500" :
320
320
data = self .read (REG_PHYCFGR , 0x00 )
321
321
return data [0 ] & 0x01
@@ -553,10 +553,11 @@ def get_socket(self):
553
553
print ("Allocated socket #{}" .format (sock ))
554
554
return sock
555
555
556
- def socket_listen (self , socket_num , port ):
557
- """Start listening on a socket (TCP mode only ).
556
+ def socket_listen (self , socket_num , port , conn_mode = SNMR_TCP ):
557
+ """Start listening on a socket (default TCP mode).
558
558
:parm int socket_num: socket number
559
559
:parm int port: port to listen on
560
+ :parm int conn_mode: connection mode SNMR_TCP (default) or SNMR_UDP
560
561
"""
561
562
assert self .link_status , "Ethernet cable disconnected!"
562
563
if self ._debug :
@@ -567,15 +568,15 @@ def socket_listen(self, socket_num, port):
567
568
)
568
569
# Initialize a socket and set the mode
569
570
self .src_port = port
570
- res = self .socket_open (socket_num , conn_mode = SNMR_TCP )
571
+ res = self .socket_open (socket_num , conn_mode = conn_mode )
571
572
self .src_port = 0
572
573
if res == 1 :
573
574
raise RuntimeError ("Failed to initalize the socket." )
574
575
# Send listen command
575
576
self ._send_socket_cmd (socket_num , CMD_SOCK_LISTEN )
576
577
# Wait until ready
577
578
status = [SNSR_SOCK_CLOSED ]
578
- while status [0 ] not in (SNSR_SOCK_LISTEN , SNSR_SOCK_ESTABLISHED ):
579
+ while status [0 ] not in (SNSR_SOCK_LISTEN , SNSR_SOCK_ESTABLISHED , SNSR_SOCK_UDP ):
579
580
status = self ._read_snsr (socket_num )
580
581
if status [0 ] == SNSR_SOCK_CLOSED :
581
582
raise RuntimeError ("Listening socket closed." )
0 commit comments