@@ -188,7 +188,7 @@ def __init__(
188
188
# attempt to initialize the module
189
189
self ._ch_base_msb = 0
190
190
if self ._w5100_init () != 1 :
191
- raise AssertionError ("Failed to initialize WIZnet module." )
191
+ raise RuntimeError ("Failed to initialize WIZnet module." )
192
192
# Set MAC address
193
193
self .mac_address = mac
194
194
self .src_port = 0
@@ -216,7 +216,7 @@ def __init__(
216
216
if ret != 0 :
217
217
self ._dhcp_client = None
218
218
if ret != 0 :
219
- raise AssertionError ("Failed to configure DHCP Server!" )
219
+ raise RuntimeError ("Failed to configure DHCP Server!" )
220
220
221
221
def set_dhcp (
222
222
self , hostname : Optional [str ] = None , response_timeout : float = 30
@@ -275,7 +275,7 @@ def get_host_by_name(self, hostname: str) -> bytes:
275
275
if self ._debug :
276
276
print ("* Resolved IP: " , ret )
277
277
if ret == - 1 :
278
- raise AssertionError ("Failed to resolve hostname!" )
278
+ raise RuntimeError ("Failed to resolve hostname!" )
279
279
return ret
280
280
281
281
@property
@@ -485,7 +485,7 @@ def detect_w5500(self) -> int:
485
485
"""
486
486
self ._chip_type = "w5500"
487
487
if self .sw_reset () != 0 :
488
- raise AssertionError ("Chip not reset properly!" )
488
+ raise RuntimeError ("Chip not reset properly!" )
489
489
self ._write_mr (0x08 )
490
490
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
491
491
if self ._read_mr ()[0 ] != 0x08 :
@@ -516,7 +516,7 @@ def detect_w5100s(self) -> int:
516
516
self ._chip_type = "w5100s"
517
517
# sw reset
518
518
if self .sw_reset () != 0 :
519
- raise AssertionError ("Chip not reset properly!" )
519
+ raise RuntimeError ("Chip not reset properly!" )
520
520
if self .read (REG_VERSIONR_W5100S , 0x00 )[0 ] != 0x51 :
521
521
return - 1
522
522
@@ -629,7 +629,7 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
629
629
)
630
630
)
631
631
if socket_num > self .max_sockets :
632
- raise AssertionError ("Provided socket exceeds max_sockets." )
632
+ raise ValueError ("Provided socket exceeds max_sockets." )
633
633
634
634
res = self ._get_rx_rcv_size (socket_num )
635
635
@@ -683,7 +683,7 @@ def socket_connect(
683
683
defaults to SNMR_TCP.
684
684
"""
685
685
if not self .link_status :
686
- raise AssertionError ("Ethernet cable disconnected!" )
686
+ raise ConnectionError ("Ethernet cable disconnected!" )
687
687
if self ._debug :
688
688
print (
689
689
"* w5k socket connect, protocol={}, port={}, ip={}" .format (
@@ -693,7 +693,7 @@ def socket_connect(
693
693
# initialize a socket and set the mode
694
694
res = self .socket_open (socket_num , conn_mode = conn_mode )
695
695
if res == 1 :
696
- raise RuntimeError ("Failed to initialize a connection with the socket." )
696
+ raise ConnectionError ("Failed to initialize a connection with the socket." )
697
697
698
698
# set socket destination IP and port
699
699
self ._write_sndipr (socket_num , dest )
@@ -707,7 +707,7 @@ def socket_connect(
707
707
if self ._debug :
708
708
print ("SN_SR:" , self .socket_status (socket_num )[0 ])
709
709
if self .socket_status (socket_num )[0 ] == SNSR_SOCK_CLOSED :
710
- raise RuntimeError ("Failed to establish connection." )
710
+ raise ConnectionError ("Failed to establish connection." )
711
711
elif conn_mode == SNMR_UDP :
712
712
self .udp_datasize [socket_num ] = 0
713
713
return 1
@@ -752,7 +752,7 @@ def socket_listen(
752
752
UDP, defaults to SNMR_TCP.
753
753
"""
754
754
if not self .link_status :
755
- raise AssertionError ("Ethernet cable disconnected!" )
755
+ raise ConnectionError ("Ethernet cable disconnected!" )
756
756
if self ._debug :
757
757
print (
758
758
"* Listening on port={}, ip={}" .format (
@@ -813,7 +813,7 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
813
813
:return int: 1 if the socket was opened, 0 if not.
814
814
"""
815
815
if not self .link_status :
816
- raise AssertionError ("Ethernet cable disconnected!" )
816
+ raise ConnectionError ("Ethernet cable disconnected!" )
817
817
if self ._debug :
818
818
print ("*** Opening socket %d" % socket_num )
819
819
status = self ._read_snsr (socket_num )[0 ]
@@ -846,7 +846,7 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
846
846
self ._write_sncr (socket_num , CMD_SOCK_OPEN )
847
847
self ._read_sncr (socket_num )
848
848
if self ._read_snsr ((socket_num ))[0 ] not in [0x13 , 0x22 ]:
849
- raise AssertionError ("Could not open socket in TCP or UDP mode." )
849
+ raise RuntimeError ("Could not open socket in TCP or UDP mode." )
850
850
return 0
851
851
return 1
852
852
@@ -888,9 +888,9 @@ def socket_read( # pylint: disable=too-many-branches
888
888
"""
889
889
890
890
if not self .link_status :
891
- raise AssertionError ("Ethernet cable disconnected!" )
891
+ raise ConnectionError ("Ethernet cable disconnected!" )
892
892
if socket_num > self .max_sockets :
893
- raise AssertionError ("Provided socket exceeds max_sockets." )
893
+ raise ValueError ("Provided socket exceeds max_sockets." )
894
894
895
895
# Check if there is data available on the socket
896
896
ret = self ._get_rx_rcv_size (socket_num )
@@ -984,7 +984,7 @@ def socket_write(
984
984
:return int: The number of bytes written to the buffer.
985
985
"""
986
986
if not self .link_status :
987
- raise AssertionError ("Ethernet cable disconnected!" )
987
+ raise ConnectionError ("Ethernet cable disconnected!" )
988
988
assert socket_num <= self .max_sockets , "Provided socket exceeds max_sockets."
989
989
status = 0
990
990
ret = 0
0 commit comments