mobbyg

cat_freq.py

Sep 3rd, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. """ A simple program to read the frequency from my FT-847 using CAT
  4. through the serial port on the radio and a USB <=> Serial adapter
  5. on my iMac
  6. """
  7.  
  8. import serial, time
  9. result = 0
  10. EOM = "\xfd"
  11.  
  12. freq = serial.Serial("/dev/cu.usbserial-A900aaUV" , 9600 , timeout = 1) #Assign the USB<>Serial port to "freq"
  13. freq.open() # Opens the port for communications
  14. freq.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)) # Open CAT connection
  15. freq.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)+chr(0x03)) # What's the VFO freq?
  16.  
  17. cat_recev = []
  18. byte = ""
  19. while byte != EOM:
  20.     byte = freq.read()
  21.     if byte == "": break
  22.     else:
  23.         cat_recev.append("%02x" % ord(byte)) # Converts the Hex result into a numbers then puts it into a list
  24.        
  25. freq.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)+chr(0x80)) # Close the CAT connection
  26. freq.close() # Close the USB<>Serial port
  27.  
  28. temp_freq = "".join(cat_recev) # Takes the list and converts to a string
  29. temp_freq = temp_freq[0:3] + "." + temp_freq[3:6] + "." + temp_freq[6:8] # Formats the output of the frequency
  30. freq_out = temp_freq.lstrip("0") # Strips out leading 0's from display if below 100 MHz
  31.  
  32. # Takes the last numbers from the string and assigns it to the correct VFO mode
  33. if cat_recev[-1] == "00": vfo_mode = "LSB"
  34. elif cat_recev[-1] == "01": vfo_mode = "USB"
  35. elif cat_recev[-1] == "02": vfo_mode = "CW"
  36. elif cat_recev[-1] == "03": vfo_mode = "LSB CW"
  37. elif cat_recev[-1] == "04": vfo_mode = "AM"
  38. else: vfo_mode = "FM"
  39.  
  40. print "\nThe current frequency is: " + freq_out, "MHz", vfo_mode + "\n" # The end result
Advertisement
Add Comment
Please, Sign In to add comment