Skip to content

Instantly share code, notes, and snippets.

@f4iey
Last active June 24, 2024 14:15
Show Gist options
  • Save f4iey/756efb9dd542967c818e34bac370b080 to your computer and use it in GitHub Desktop.
Save f4iey/756efb9dd542967c818e34bac370b080 to your computer and use it in GitHub Desktop.
PoC of remote CW keyer operation
# SPDX-License-Identifier: GPL-3.0-or-later
import select
import serial
import sys
import time
def wpm_to_millis(wpm):
return 60000/(wpm*50)
def dit(ser, millis):
ser.rts = True
time.sleep(millis)
ser.rts = False
time.sleep(millis)
def dah(ser, millis):
dit(ser, 3*millis)
def speed_control(wpm):
# Detects keyboard actions to increase or decrease sleep time
if select.select([sys.stdin], [], [], 0)[0]:
char = sys.stdin.read(1)
if char == 'W':
wpm += 1
elif char == 'w':
wpm -= 1
elif char == 'q':
break
# Connects to physical serial port
physical_port = serial.Serial('COM1', 9600, timeout=1)
# Creates a virtual serial port
virtual_port = serial.Serial('COM2', 9600, timeout=1)
print("Manual serial CW keyer: perss [q] to exit")
while(1):
# Sets wpm speed
wpm = 28
speed_control(wpm)
millis = wpm_to_millis(wpm)
print("Speed: ", wpm, " wpm", " [w-W]", end='\r')
# Tests if either CTS or DSR is set on the physical serial port
if physical_port.dsr:
dah(virtual_port, millis)
elif physical_port.cts:
dit(virtual_port, millis)
# Closes the serial ports
physical_port.close()
virtual_port.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment