Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """ A simple program to read the frequency from my FT-847 using CAT
- through the serial port on the radio and a USB <=> Serial adapter
- on my iMac
- """
- import serial, time
- result = 0
- EOM = "\xfd"
- freq = serial.Serial("/dev/cu.usbserial-A900aaUV" , 9600 , timeout = 1) #Assign the USB<>Serial port to "freq"
- freq.open() # Opens the port for communications
- freq.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)) # Open CAT connection
- freq.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)+chr(0x03)) # What's the VFO freq?
- cat_recev = []
- byte = ""
- while byte != EOM:
- byte = freq.read()
- if byte == "": break
- else:
- cat_recev.append("%02x" % ord(byte)) # Converts the Hex result into a numbers then puts it into a list
- freq.write(chr(0x00)+chr(0x00)+chr(0x00)+chr(0x00)+chr(0x80)) # Close the CAT connection
- freq.close() # Close the USB<>Serial port
- temp_freq = "".join(cat_recev) # Takes the list and converts to a string
- temp_freq = temp_freq[0:3] + "." + temp_freq[3:6] + "." + temp_freq[6:8] # Formats the output of the frequency
- freq_out = temp_freq.lstrip("0") # Strips out leading 0's from display if below 100 MHz
- # Takes the last numbers from the string and assigns it to the correct VFO mode
- if cat_recev[-1] == "00": vfo_mode = "LSB"
- elif cat_recev[-1] == "01": vfo_mode = "USB"
- elif cat_recev[-1] == "02": vfo_mode = "CW"
- elif cat_recev[-1] == "03": vfo_mode = "LSB CW"
- elif cat_recev[-1] == "04": vfo_mode = "AM"
- else: vfo_mode = "FM"
- print "\nThe current frequency is: " + freq_out, "MHz", vfo_mode + "\n" # The end result
Advertisement
Add Comment
Please, Sign In to add comment