import serial import string # *************************************************************************** # * QT_Test.py * # * * # * Simulates the functionality of the QuickTune for the YAESU FT-817 * # * (can be found at http://www.min.at/OE1RIB/QT) * # * * # * 2003-17-11 by OE1RIB@MIN.at * # *************************************************************************** def CATSend(Text = "", c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, wanted = 1, timeout = 1): """ CATSend sends 5 CAT command bytes (c1-c5) to the radio, and waits for (timeout) seconds to receive (wanted) bytes back from the radio """ LeadingZeros = lambda v, l: ("0" * l)[:l - len(str(v))] + str(v) ser.timeout = timeout binOut = chr(c1) + chr(c2) + chr(c3) + chr(c4) + chr(c5) strOut = string.join([LeadingZeros(hex(ord(c))[2:],2) for c in binOut]," ") strIn = "" ser.write(binOut) if wanted > 0: binIn = ser.read(wanted) if len(binIn) > 0: strIn = string.join([LeadingZeros(hex(ord(x))[2:],2) for x in binIn]," ") print "%-16s: %-5s --> %-5s" % (Text, strOut.upper(), strIn.upper()) #print Text + strOut.upper() + " --> " + strIn.upper() return binIn ser = serial.Serial(port=0, baudrate=9600, bytesize=8, parity=serial.PARITY_NONE, stopbits=1, timeout=1, xonxoff=0, rtscts=0) ser.open() if ser.isOpen(): print print # read mode SavedMode = CATSend("read mode",0x00,0x00,0x00,0x00,0x03,5,2) # read power SavedPower = CATSend("read power",0x00,0x79,0x00,0x00,0xBB,2,2) # set CW-Mode CATSend("set CW mode",0x02,0x00,0x00,0x00,0x07,1,2) # set power CATSend("set power",0x00,0x79,0x0B,ord(SavedPower[1:2]),0xBC,1,2) # set lock CATSend("lock",0x00,0x00,0x00,0x00,0x00,1,2) # PTT on CATSend("PTT on",0x00,0x00,0x00,0x00,0x08,1,2) wait=raw_input("please press a key") # PTT off CATSend("PTT off",0x00,0x00,0x00,0x00,0x88,1,2) # unlock CATSend("unlock",0x00,0x00,0x00,0x00,0x80,1,2) # restore power CATSend("restore power",0x00,0x79,ord(SavedPower[0:1]),ord(SavedPower[1:2]),0xBC,1,2) # restore mode CATSend("restore mode",ord(SavedMode[4:5]),0x00,0x00,0x00,0x07,1,2) ser.close()