Browse code

fixed but in read memory settings

Gandolf authored on 11/30/2019 04:34:27
Showing 2 changed files
... ...
@@ -132,8 +132,6 @@ def getMemory(memloc):
132 132
     # Send the get memory settings string to the FT991.
133 133
     sCmd = 'MT%0.3d;' % (memloc)
134 134
     sResult = sendCommand(sCmd)
135
-    if sResult == '?;':
136
-        return None
137 135
 
138 136
     # Parse memory settings string returned by the FT991
139 137
     memloc = sResult[2:5]
... ...
@@ -212,9 +210,9 @@ def getTxClarifier():
212 210
     return dTxClar.keys()[dTxClar.values().index(state)]
213 211
 ## end def
214 212
 
215
-#########################################################################
216
-# Define 'set' functions to encapsulate the various FT991 CAT commands. #
217
-#########################################################################
213
+#############################################################################
214
+# Define 'set' functions to encapsulate the various FT991 CAT commands.     #
215
+#############################################################################
218 216
 
219 217
 def setMemory(dMem):
220 218
     """
... ...
@@ -372,7 +370,8 @@ def setMemoryLocation(iLocation):
372 370
     Description:  Sends a formatted MC command that sets the current
373 371
                   memory location.
374 372
     Parameters: location - integer specifying memory location
375
-    Returns: nothing
373
+    Returns: None if the memory location is blank, otherwise
374
+             returns a string containing the memory location.
376 375
     """
377 376
     # Validate memory location data and send the command.
378 377
     if iLocation < 1 or iLocation > 118:
... ...
@@ -382,12 +381,14 @@ def setMemoryLocation(iLocation):
382 381
     # Send the completed command.
383 382
     sResult = sendCommand(sCmd)
384 383
     if sResult == '?;':
385
-        raise Exception('setMemoryLocation error')
384
+        return None
385
+    else:
386
+        return str(iLocation)
386 387
 ## end def
387 388
 
388
-############################################################################
389
-# Helper functions to assist in various tasks.                             #
390
-############################################################################
389
+#############################################################################
390
+# Helper functions to assist in various tasks.                              #
391
+#############################################################################
391 392
 
392 393
 def parseCsvData(sline):
393 394
     """
... ...
@@ -447,7 +448,9 @@ def sendCommand(sCmd):
447 448
     return sResult
448 449
 ## end def
449 450
 
450
-# Low level serial communications functions.
451
+#############################################################################
452
+# Low level serial communications functions.                                #
453
+#############################################################################
451 454
 
452 455
 def begin(baud=9600):
453 456
     """
... ...
@@ -562,28 +565,28 @@ def main():
562 565
             'mode': 'FM', 'encode': 'TONE ENC', 'tag': 'KA7JLO', \
563 566
             'clarfreq': '1234', 'rxclar': 'ON', 'txclar': 'ON' \
564 567
            }
565
-    setMemory(dMem)
566 568
     setMemoryLocation(int(dMem['memloc']))
569
+    setMemory(dMem)
567 570
     setRxClarifier(dMem['rxclar'])
568 571
     setTxClarifier(dMem['txclar'])
569 572
     setCTCSS('127.3 Hz')
570 573
     setDCS('115')
571 574
     print
572
-    getMemory(98)
575
+    getMemory(int(dMem['memloc']))
573 576
     print
574 577
     # Set and receive a memory channel
575 578
     dMem = {'memloc': '99', 'rxfreq': '146.52', 'shift': 'OFF', \
576 579
             'mode': 'FM', 'encode': 'OFF', 'tag': 'KA7JLO', \
577 580
             'clarfreq': '0', 'rxclar': 'OFF', 'txclar': 'OFF' \
578 581
            }
579
-    setMemory(dMem)
580 582
     setMemoryLocation(int(dMem['memloc']))
583
+    setMemory(dMem)
581 584
     setRxClarifier(dMem['rxclar'])
582 585
     setTxClarifier(dMem['txclar'])
583 586
     setCTCSS('141.3 Hz')
584 587
     setDCS('445')
585 588
     print
586
-    getMemory(99)
589
+    getMemory(int(dMem['memloc']))
587 590
     print
588 591
 
589 592
     # Test set commands
... ...
@@ -264,28 +264,26 @@ def readMemorySettings():
264 264
     # Define the column headers as the first item in the list.
265 265
     lSettings = [ 'Memory Ch,Rx Frequency,Tx Frequency,Offset,' \
266 266
                         'Repeater Shift,Mode,Tag,Encoding,Tone,DCS,' \
267
-                        'Clarifier, RxClar, TxClar' ]
267
+                        'Clarifier,RxClar,TxClar' ]
268 268
 
269 269
     for iLocation in range(1, _MAX_NUMBER_OF_MEMORY_ITEMS):
270 270
 
271
+        # If a memory location is empty (has not been programmed or has
272
+        # been erased), skip that location and do not create a list entry
273
+        # for that location.
274
+        if ft991.setMemoryLocation(iLocation) == None:
275
+            continue
271 276
         # For each memory location get the memory contents.  Note that
272 277
         # several CAT commands are required to get the entire contents
273 278
         # of a memory location.  Specifically, additional commands are
274 279
         # required to get DCS code and CTCSS tone.
275 280
         dMem = ft991.getMemory(iLocation)
276
-        # If a memory location is empty (has not been programmed or has
277
-        # been erased), do not created a list entry for that location.
278
-        if dMem == None:
279
-            continue
280
-        # Set current memory location to the channel being set.
281
-        sResult = ft991.setMemoryLocation(iLocation)
282
-        # Get DCS and CTCSS.
283 281
         tone = ft991.getCTCSS()
284 282
         dcs = ft991.getDCS()
285 283
         # getMemory, above, stores data in a dictionary object.  Format
286 284
         # the data in this object, as well as, the DCS code and CTCSS
287 285
         # tone into a comma-delimited string.
288
-        sCsvFormat = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,' % \
286
+        sCsvFormat = '%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s' % \
289 287
                ( dMem['memloc'], dMem['rxfreq'], '', '', \
290 288
                  dMem['shift'], dMem['mode'], dMem['tag'], dMem['encode'], \
291 289
                  tone, dcs, dMem['clarfreq'], dMem['rxclar'], \
... ...
@@ -310,10 +308,10 @@ def writeMemorySettings(lSettings):
310 308
         if dItem == None:
311 309
             continue
312 310
         try:
313
-            # Set the parameters for the memory location.
314
-            ft991.setMemory(dItem)
315 311
             # Set current channel to memory location being set.
316 312
             ft991.setMemoryLocation(int(dItem['memloc']))
313
+            # Set the parameters for the memory location.
314
+            ft991.setMemory(dItem)
317 315
             # Set CTCSS tone for memory channel.
318 316
             ft991.setCTCSS(dItem['tone'])
319 317
             # Set DCS code for memory channel. 
... ...
@@ -520,7 +518,7 @@ def main():
520 518
 
521 519
     # Else enter user interactive mode.
522 520
     printMenuSplash()
523
-    while(1):
521
+    while(True):
524 522
         doUserCommand()
525 523
 ## end def
526 524