Rig Control with pySerial

Let’s write a rig control program with pySerial.

import serial
ser = serial.Serial('/dev/ttyUSB0', 19200, timeout=1)

for freq_khz in range(567,1449,3):
	khz    = freq_khz         % 10
	khz10  = freq_khz //   10 % 10
	khz100 = freq_khz //  100 % 10
	mhz    = freq_khz // 1000 % 10

	set_freq = b'\xfe\xfe\x80\xe0\x05\x00' \
			+bytes([16*khz         ])      \
			+bytes([16*khz100+khz10])      \
			+bytes([          mhz  ])      \
			+b'\x00\xfd'
	ser.write(set_freq)
	data1 = ser.read(18) # not 17 to raise timeout
	
	get_Smeter = b'\xfe\xfe\x80\xe0\x15\x02\xfd'
	ser.write(get_Smeter)
	data2 = ser.read(16)

	print(freq_khz, int( data2.hex()[26:30] ))
ser.close()

A simple program to scan the AM band and to record the signal strength.

The stations are, from left to right, NHK-1, NHK-2, AFN, and TBS.

Leave a Reply

Your email address will not be published. Required fields are marked *