@@ -315,7 +315,7 @@ def remote_ip(self, socket_num):
315315
316316 @property
317317 def link_status (self ):
318- """"Returns if the PHY is connected."""
318+ """ "Returns if the PHY is connected."""
319319 if self ._chip_type == "w5500" :
320320 data = self .read (REG_PHYCFGR , 0x00 )
321321 return data [0 ] & 0x01
@@ -553,10 +553,11 @@ def get_socket(self):
553553 print ("Allocated socket #{}" .format (sock ))
554554 return sock
555555
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).
558558 :parm int socket_num: socket number
559559 :parm int port: port to listen on
560+ :parm int conn_mode: connection mode SNMR_TCP (default) or SNMR_UDP
560561 """
561562 assert self .link_status , "Ethernet cable disconnected!"
562563 if self ._debug :
@@ -567,15 +568,15 @@ def socket_listen(self, socket_num, port):
567568 )
568569 # Initialize a socket and set the mode
569570 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 )
571572 self .src_port = 0
572573 if res == 1 :
573574 raise RuntimeError ("Failed to initalize the socket." )
574575 # Send listen command
575576 self ._send_socket_cmd (socket_num , CMD_SOCK_LISTEN )
576577 # Wait until ready
577578 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 ):
579580 status = self ._read_snsr (socket_num )
580581 if status [0 ] == SNSR_SOCK_CLOSED :
581582 raise RuntimeError ("Listening socket closed." )
0 commit comments