Skip to content

Instantly share code, notes, and snippets.

@JHay0112
Created December 28, 2023 10:43
Show Gist options
  • Save JHay0112/6e942c7b50c9714163e6c0d7b089ab17 to your computer and use it in GitHub Desktop.
Save JHay0112/6e942c7b50c9714163e6c0d7b089ab17 to your computer and use it in GitHub Desktop.
Prompt for SCPI over USB
"""
Script for issuing SCPI commands over USB. Slightly nicer to use than `echo "RCL5" > /dev/ttyACM0`.
Author: J. L. Hay
"""
from select import select
from time import sleep
POWER_SUPPLY_FILEPATH = "/dev/ttyACM0"
POWER_SUPPLY_FILE_W = open(POWER_SUPPLY_FILEPATH, "w")
POWER_SUPPLY_FILE_R = open(POWER_SUPPLY_FILEPATH, "r")
PROMPT = ">>> "
def main():
while (user_input := input(PROMPT)) != None:
POWER_SUPPLY_FILE_W.write(user_input + "\n")
sleep(0.1)
can_read, _, _ = select([POWER_SUPPLY_FILE_R], [], [], 0)
if can_read:
print(POWER_SUPPLY_FILE_R.readline().strip())
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
POWER_SUPPLY_FILE_W.close()
POWER_SUPPLY_FILE_R.close()
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment