This little project just took on a life of its own this afternoon. What started out as an experiment in writing a single program to read output data from my radio via the RS232 serial interface has turned into a full blown radio remote control program.
The current state of the program will let me control my rig from a remote PC across the local network at my QTH.
There are 4 separate programs involved in this. Much of the code from my previous blog post comprises the heart of the system.
Here is how it all works. On the PC that is connected to the radio (we will call this the PC-Radio system) resides two programs – K2client.py and K2server.py. On the remote PC across the network (we will call this the PC-operator system) resides two other programs – client.py and server.py. On the PC-Radio system, the programs each have to communicate with both the network and the radio. The K2client.py program takes any output data from the radio and sends it out to the network to be received as feedback from the radio by the server.py program on the PC-operator system. The K2server.py program receives any data sent to it from across the network by the client.py program on the PC-operator system and passes these as commands to the radio. The radio takes the command, gives feedback, and cycle begins again. As a diagram, it looks like this.
server.py[PC-operator system]client.py —————->K2server.py [PC-Radio system]K2client.py —>
^ (operator) (network) (radio) |
It was not as that this was all entirely necessary. I could have downloaded software already designed to do this, and have used such in the past with my computers and radio. However, for me, it is the difference between buying a radio and building a radio. You can accomplish the very same thing in the end, e.g. communication. Both ways are OK. However, there are added benefits from building equipment such as the opportunity to learn, pride in the work one has done, the sense of accomplishment, etc. The same is true for this type of homebrewing, the only difference is that it is homebrewed software rather than hardware. The Python source code for the project is available. This code is very minimalist and intended only to demonstrate the principles involved. Please feel free to use, adapt, or modify it in any way you may wish.
NOTE: The code from my previous blog post contains comments that explain how to take this Linux implementation of RS232 communications and adapt it for use on a Windows system. Also note that there are hard coded IP addresses in the code that would need to be changed for implementation elsewhere. Aside from those differences, this code should be fully cross-platform and usable anywhere as it pertains to the parts dealing with the serial and network communications. The control codes and settings I am sending to my radio may not be applicable to your own, so please see the users or programming manual for your rig for appropriate codes, settings and methods for communicating and controlling it. Additionally, the code found in this project that implements the network socket clients and servers are adaptations of code found at evolt.org.
I found a terrific little tutorial on the subject of programming network socket Server/Client communications in Python. Very clear and concise! The author did a nice job with this.
Socket Programming in Python @ evolt.org
#k2test1.py by Bill Allen – WA5PB
#This is an experiment in communicating with an Amateur Radio transceiver
#via Python through RS232 serial communications. Similar code could be used
#to communicate with any device supporting serial communications.
#This was written using Python 2.6.5, but I like using the new
#Python 3.x print function so we pull it in for use here.
from __future__ import print_function
#We will be using the PySerial library to provide RS232 serial communications.
#PySerial is a third party library module that can be found here:
#Configure the serial port to communicate with the Elecraft K2 xcvr.
#I am coding this on a Linux system, so the device string /dev/ttyS0
#works for the first serial port. Your system my use a different serial
#port device. For a Windows system, try COM1 for the first serial port.
ser = serial.Serial(‘/dev/ttyS0’, 4800, timeout=1)
#Sanity check for the K2 AutoInfo mode, turn it off.
#Now set the K2 AutoInfo mode to mode 1 and get some initial data.
#Read up to 150 bytes of returned data from the K2 and print it out.
K2_data = ser.read(150)
#Now set the K2 AutoInfo mode to return the most data while it is being polled.
#Ctrl-C will be used to end the program. End the program gracefully by trapping
#the Ctrl-C, turning off the K2 AutoInfo mode and closing the serial port prior
K2_data = ser.read(150)
if K2_data != “”:
print(“Reseting K2 AutoInfo mode OFF”)
print(“Closing Serial Port”)
Fldigi (Fast Light Digital Modem Application) is a cross-platform modem program that supports most of the digital modes used on the amateur radio bands.
Fldigi is a digital modem program for Linux, Free-BSD, OS X, Windows XP, W2K, and Vista (probably Win7).
Bill – WA5PB
There are lots of ways to experiment with electronics. One way is to use a programmable testbed system. There are several available at various costs. One that I am looking at that seems interesting is the Arduino UNO, which sells for about $30. I was shown this one at work by our electronics engineer. I may get one for myself to play with. It looks like a very inexpensive way to experiment with programmable electronics. Such system can be used for data output and display, data collection, motor control, ham radio applications, and much more.
The main website.
A hands on turtorial.
Another programmable testbed system that is quite popular is the Parallax Basic Stamp.
The Arduino UNO
The PC sound card may just be one of the most useful electronic devices that nearly everyone owns. Not only can you listen to music with it, but you can do nearly any Ham Radio digital mode. However, did you know you can also use your PC+sound card combination as a spectrum analyzer or even as an Oscilloscope? Here are links to software that will allow you do this. Both are easy to install and free.
Spectrogram 5.17 – for Windows. I did all the xtal alignment work on my Elecraft K2 radio with this program.
Baudline – for Linux, Mac OS X, and Solaris SPARC systems. This one has LOTS of features. Simple to install! Download, unzip, and run the “baudline” program from the unziped folder.
Bill – WA5PB