Files
micro_bit_interface/bin/others/run_command.py
2022-05-14 18:04:52 +02:00

27 lines
835 B
Python

import serial
import bin.com.csv_parsers
import bin.com.lib
cvr = bin.com.csv_parsers.CsvRead()
com = bin.com.lib.Com()
class RunCommand:
def __init__(self):
self.__all_commands = []
self.__return = ""
def runcommand(self, command, command_list_path):
self.__all_commands = cvr.importing(command_list_path).pop(0)
if command in self.__all_commands:
try:
com.connect(19200, "")
com.send(command)
self.__return = "The command executed successfully"
except serial.SerialException:
self.__return = f"[micro:bit - {command}]: An error occurred running the command. (Maybe disconnected or no permission?)"
else:
self.__return = "-micro:bit - No such command"
return self.__return