Optimized no Pandas Python band scope for the Uniden scanners
Works with all Uniden scanners which have PWR remote command.
https://techcoderadio.blogspot.com/2025/05/optimized-python-uniden-pwr-command.html
Optimized, Pandas removed
import serial
import matplotlib.pyplot as plt
import csv
import os
import time
from datetime import datetime
SER_PORT = 'COM14'
SER_BAUD = 115200
SER_TIMEOUT = 0.5
SER_CMD = b'PWR\r'
READ_SIZE = 19
OUT_DIR = r"c:\temp"
OUT_FILE = os.path.join(OUT_DIR, 'unidenscope.csv')
def out_dir():
try:
os.makedirs(OUT_DIR, exist_ok=True)
except Exception:
pass
def main():
ser = serial.Serial(SER_PORT, SER_BAUD, timeout=SER_TIMEOUT)
print(ser.name)
readings = {}
log_data = []
plt.ion()
fig, ax = plt.subplots()
ax.set_xlabel("Frequency")
ax.set_ylabel("RSSI")
fig.set_figwidth(15)
fig.set_figheight(9)
fig.canvas.manager.window.move(0,0)
try:
while True:
ser.write(SER_CMD)
raw = ser.read(READ_SIZE)
res = raw.decode(errors='ignore').replace('\r', '').strip()
parts = res.split(',')
if len(parts) < 3:
continue
freq = parts[2]
rssi = int(parts[1])
readings[freq] = rssi
log_data.append([freq, rssi, datetime.now().strftime("%Y%m%d%H%M%S")])
freqs = sorted(readings.keys(), key=lambda x: float(x))
values = [readings[f] for f in freqs]
ax.clear()
ax.bar(range(len(freqs)), values)
ax.set_xticks(range(len(freqs)))
ax.set_xticklabels(freqs, rotation=90)
ax.set_xlabel("Frequency")
ax.set_ylabel("RSSI")
plt.pause(0.03)
except KeyboardInterrupt:
plt.close()
finally:
try:
ser.close()
except Exception:
pass
out_dir()
cols = ['Frequency', 'RSSI', 'Timestamp']
try:
with open(OUT_FILE, 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(cols)
csvwriter.writerows(log_data)
except Exception as e:
print('Failed writing CSV:', e)
if __name__ == '__main__':
main()

Comments
Post a Comment