#!/usr/bin/python ##################################################### # # This is a rig ctl sync for QS1RServer to hamlib # # QS1RServer is the master and the rig gets updated as # you change frequency and mode in the Panoptos GUI # # This should work with any of the GUIs if QS1RServer # polls and responds the same way between versions. # # Tested with Panoptos v1.0.0.4 and QS1RServer v2.0.0.8 # on an Ubuntu 8.10 system # # You'll need to apt-get install hamlib libhamlib2-python python # # Written by a loose screw, this comes with no warranty # # This is my first Python script....so you're on your own # # The rig definitions can be found in the example python # bindings files that ship with libhamlib2-python # # You can guess them by doing rigctl -l then using all # caps with no spaces for the rig name listed, just tack # it on where I put my rig names below # # ctrl-c breaks the script to stop it... maybe I'll make # this fancier later, but for my first run, this is working # well enough for what I needed it for. # # KC2RGW - Mar 2009 # # Jun 19 2009 # Made some mode changes and added comments #################################################### import socket import sys import struct import Hamlib import time # IP that QS1RServer is running on HOSTNAME = '127.0.0.1' # QS1R control port PORTNO = 55667 # Read buf size for udp poll response MAXLEN = 64 oldfqcy = 0 # place holder oldmde = 0 # place holder # Set up a UDP client socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Uncomment this line for debug into from hamlib Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_TRACE) # Set for no debug output from hamlib #Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_NONE) # The next two are for a TS-2000 Kenwood on ttyUSB3 my_rig = Hamlib.Rig (Hamlib.RIG_MODEL_TS2000) my_rig.set_conf ("rig_pathname","/dev/ttyUSB3") # These are for a TS-940 on ttyUSB3 #my_rig = Hamlib.Rig (Hamlib.RIG_MODEL_TS940) #my_rig.set_conf ("rig_pathname","/dev/ttyUSB3") # Initialize the connection via hamlib my_rig.open () print "getinfo: ",my_rig.get_info() # Open udp connect to the QS1RServer s.connect((HOSTNAME, PORTNO)) while True: # Get on with it, poll the QS1RServer for freq and mode # Poll frequency of the QS1R s.send("r:freq[0]\n") (data,addr) = s.recvfrom(MAXLEN) # Clean up frequency output format for hamlib use fqcy = (data).rsplit('.') fqcy=fqcy[0].rstrip() # Poll demod mode the QS1R is in s.send("r:mde[0]\n") (data,addr) = s.recvfrom(MAXLEN) # Clean up/upper case mode result for hamlib format mde = str.upper((data).rstrip()) # This just makes noise to show you it's running # comment this out if you want a blank terminal #print "Frequency on QS1R is %sHz Mode is %s" % (fqcy,mde) # Has frequency changed? Update rig if so if fqcy != oldfqcy : my_rig.set_freq (int(fqcy)) # Has mode changed? Update rig if so # Only supporting LSB USB DIG CW and AM, will fall through to # AM if it's something else..there is a bug with DIGU I haven't # figured out yet...sets rig to AM if mde != oldmde : if mde == "LSB" : my_rig.set_mode (Hamlib.RIG_MODE_LSB) elif mde == "USB" : my_rig.set_mode (Hamlib.RIG_MODE_USB) elif mde == "CWU" : my_rig.set_mode (Hamlib.RIG_MODE_CW) elif mde == "CWL" : my_rig.set_mode (Hamlib.RIG_MODE_CW) elif mde == "DIGU" : my_rig.set_mode (Hamlib.RIG_MODE_USB) elif mde == "DIGL" : my_rig.set_mode (Hamlib.RIG_MODE_LSB) else : my_rig.set_mode (Hamlib.RIG_MODE_AM) # Set marker to check if mode or frequency update is needed oldmde = mde oldfqcy = fqcy # Give the QS1RServer a break time.sleep(.1) # close connect to rig my_rig.close() # closing the udp socket s.close()