@@ -187,7 +187,8 @@ def __init__(
187
187
188
188
# attempt to initialize the module
189
189
self ._ch_base_msb = 0
190
- assert self ._w5100_init () == 1 , "Failed to initialize WIZnet module."
190
+ if self ._w5100_init () != 1 :
191
+ raise AssertionError ("Failed to initialize WIZnet module." )
191
192
# Set MAC address
192
193
self .mac_address = mac
193
194
self .src_port = 0
@@ -214,7 +215,8 @@ def __init__(
214
215
ret = self .set_dhcp (hostname , dhcp_timeout )
215
216
if ret != 0 :
216
217
self ._dhcp_client = None
217
- assert ret == 0 , "Failed to configure DHCP Server!"
218
+ if ret != 0 :
219
+ raise AssertionError ("Failed to configure DHCP Server!" )
218
220
219
221
def set_dhcp (
220
222
self , hostname : Optional [str ] = None , response_timeout : float = 30
@@ -272,7 +274,8 @@ def get_host_by_name(self, hostname: str) -> bytes:
272
274
ret = _dns_client .gethostbyname (hostname )
273
275
if self ._debug :
274
276
print ("* Resolved IP: " , ret )
275
- assert ret != - 1 , "Failed to resolve hostname!"
277
+ if ret == - 1 :
278
+ raise AssertionError ("Failed to resolve hostname!" )
276
279
return ret
277
280
278
281
@property
@@ -481,7 +484,8 @@ def detect_w5500(self) -> int:
481
484
:return int: 1 if a W5500 chip is detected, -1 if not.
482
485
"""
483
486
self ._chip_type = "w5500"
484
- assert self .sw_reset () == 0 , "Chip not reset properly!"
487
+ if self .sw_reset () != 0 :
488
+ raise AssertionError ("Chip not reset properly!" )
485
489
self ._write_mr (0x08 )
486
490
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
487
491
if self ._read_mr ()[0 ] != 0x08 :
@@ -511,7 +515,8 @@ def detect_w5100s(self) -> int:
511
515
"""
512
516
self ._chip_type = "w5100s"
513
517
# sw reset
514
- assert self .sw_reset () == 0 , "Chip not reset properly!"
518
+ if self .sw_reset () != 0 :
519
+ raise AssertionError ("Chip not reset properly!" )
515
520
if self .read (REG_VERSIONR_W5100S , 0x00 )[0 ] != 0x51 :
516
521
return - 1
517
522
@@ -623,7 +628,8 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
623
628
socket_num , sock_type
624
629
)
625
630
)
626
- assert socket_num <= self .max_sockets , "Provided socket exceeds max_sockets."
631
+ if socket_num > self .max_sockets :
632
+ raise AssertionError ("Provided socket exceeds max_sockets." )
627
633
628
634
res = self ._get_rx_rcv_size (socket_num )
629
635
@@ -676,7 +682,8 @@ def socket_connect(
676
682
:param int conn_mode: The connection mode. Use SNMR_TCP for TCP or SNMR_UDP for UDP,
677
683
defaults to SNMR_TCP.
678
684
"""
679
- assert self .link_status , "Ethernet cable disconnected!"
685
+ if not self .link_status :
686
+ raise AssertionError ("Ethernet cable disconnected!" )
680
687
if self ._debug :
681
688
print (
682
689
"* w5k socket connect, protocol={}, port={}, ip={}" .format (
@@ -744,7 +751,8 @@ def socket_listen(
744
751
:param int conn_mode: Connection mode SNMR_TCP for TCP or SNMR_UDP for
745
752
UDP, defaults to SNMR_TCP.
746
753
"""
747
- assert self .link_status , "Ethernet cable disconnected!"
754
+ if not self .link_status :
755
+ raise AssertionError ("Ethernet cable disconnected!" )
748
756
if self ._debug :
749
757
print (
750
758
"* Listening on port={}, ip={}" .format (
@@ -804,7 +812,8 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
804
812
UDP, defaults to SNMR_TCP.
805
813
:return int: 1 if the socket was opened, 0 if not.
806
814
"""
807
- assert self .link_status , "Ethernet cable disconnected!"
815
+ if not self .link_status :
816
+ raise AssertionError ("Ethernet cable disconnected!" )
808
817
if self ._debug :
809
818
print ("*** Opening socket %d" % socket_num )
810
819
status = self ._read_snsr (socket_num )[0 ]
@@ -836,10 +845,8 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
836
845
# open socket
837
846
self ._write_sncr (socket_num , CMD_SOCK_OPEN )
838
847
self ._read_sncr (socket_num )
839
- assert (
840
- self ._read_snsr ((socket_num ))[0 ] == 0x13
841
- or self ._read_snsr ((socket_num ))[0 ] == 0x22
842
- ), "Could not open socket in TCP or UDP mode."
848
+ if self ._read_snsr ((socket_num ))[0 ] not in [0x13 , 0x22 ]:
849
+ raise AssertionError ("Could not open socket in TCP or UDP mode." )
843
850
return 0
844
851
return 1
845
852
@@ -879,8 +886,10 @@ def socket_read(
879
886
was unsuccessful then both items equal an error code, 0 for no data waiting and -1
880
887
for no connection to the socket.
881
888
"""
882
- assert self .link_status , "Ethernet cable disconnected!"
883
- assert socket_num <= self .max_sockets , "Provided socket exceeds max_sockets."
889
+ if not self .link_status :
890
+ raise AssertionError ("Ethernet cable disconnected!" )
891
+ if socket_num > self .max_sockets :
892
+ raise AssertionError ("Provided socket exceeds max_sockets." )
884
893
885
894
# Check if there is data available on the socket
886
895
ret = self ._get_rx_rcv_size (socket_num )
@@ -973,7 +982,8 @@ def socket_write(
973
982
974
983
:return int: The number of bytes written to the buffer.
975
984
"""
976
- assert self .link_status , "Ethernet cable disconnected!"
985
+ if not self .link_status :
986
+ raise AssertionError ("Ethernet cable disconnected!" )
977
987
assert socket_num <= self .max_sockets , "Provided socket exceeds max_sockets."
978
988
status = 0
979
989
ret = 0
0 commit comments