@@ -362,16 +362,17 @@ def __init__(self, spi, cs, reset, frequency, *, preamble_length=8,
362
362
self .reset ()
363
363
# No device type check! Catch an error from the very first request and
364
364
# throw a nicer message to indicate possible wiring problems.
365
- try :
366
- # Set sleep mode, wait 10s and confirm in sleep mode (basic device check).
367
- # Also set long range mode (LoRa mode) as it can only be done in sleep.
368
- self .sleep ()
369
- time .sleep (0.01 )
370
- self .long_range_mode = True
371
- if self .operation_mode != SLEEP_MODE or not self .long_range_mode :
372
- raise RuntimeError ('Failed to configure radio for LoRa mode, check wiring!' )
373
- except OSError :
374
- raise RuntimeError ('Failed to communicate with radio, check wiring!' )
365
+ version = self ._read_u8 (_RH_RF95_REG_42_VERSION )
366
+ if version != 18 :
367
+ raise RuntimeError ('Failed to find rfm9x with expected version -- check wiring' )
368
+
369
+ # Set sleep mode, wait 10s and confirm in sleep mode (basic device check).
370
+ # Also set long range mode (LoRa mode) as it can only be done in sleep.
371
+ self .sleep ()
372
+ time .sleep (0.01 )
373
+ self .long_range_mode = True
374
+ if self .operation_mode != SLEEP_MODE or not self .long_range_mode :
375
+ raise RuntimeError ('Failed to configure radio for LoRa mode, check wiring!' )
375
376
# clear default setting for access to LF registers if frequency > 525MHz
376
377
if frequency > 525 :
377
378
self .low_frequency_mode = 0
@@ -496,7 +497,8 @@ def frequency_mhz(self):
496
497
497
498
@frequency_mhz .setter
498
499
def frequency_mhz (self , val ):
499
- assert 240 <= val <= 960
500
+ if val < 240 or val > 960 :
501
+ raise RuntimeError ('frequency_mhz must be between 240 and 960' )
500
502
# Calculate FRF register 24-bit value.
501
503
frf = int ((val * 1000000.0 ) / _RH_RF95_FSTEP ) & 0xFFFFFF
502
504
# Extract byte values and update registers.
@@ -526,7 +528,8 @@ def tx_power(self):
526
528
def tx_power (self , val ):
527
529
val = int (val )
528
530
if self .high_power :
529
- assert 5 <= val <= 23
531
+ if val < 5 or val > 23 :
532
+ raise RuntimeError ('tx_power must be between 5 and 23' )
530
533
# Enable power amp DAC if power is above 20 dB.
531
534
# Lower setting by 3db when PA_BOOST enabled - see Data Sheet Section 6.4
532
535
if val > 20 :
0 commit comments