This repository contains two Python scripts for controlling relay modules and automating command execution. The relay_control.py
script is used for controlling relays via a serial interface, while run_commands.py
automates the execution of a series of commands from a file.
This script provides functionality for controlling relay modules via a serial interface. It supports ad-hoc command-line control and automated control via an input file.
- Control individual relays on/off for specified durations
- Read relay control sequences from an input file for automation
- Command line based, easy to integrate with other systems
- Python 3
- pyserial package
- Command line (Linux):
python3 relay_control.py -d '/dev/ttyUSB0' -r 1 -t 5
- Command line (Windows):
python relay_control.py -d COM1 -b 9600 -r 1 -t 1
- With input file:
python relay_control.py -f playfile.txt
A script to automate the execution of a series of commands listed in a specified file. It can execute the commands a specified number of times or continuously in an infinite loop.
- Execute commands from a file
- Supports finite or infinite execution cycles
- Useful for repetitive tasks and automation
- Finite number of cycles:
python run_commands.py commands.txt 10
- Infinite execution:
python run_commands.py commands.txt infinite
Save yourself a lot of headache. Let's use /dev/ttyUSB0
as the reference CH340 device:
# Disconnect USB device if connected
sudo systemctl mask brltty-udev.service
sudo apt-get remove --yes brltty
# Reconnect USB device if disconnected
sudo chmod 0666 /dev/ttyUSB0
We test everything in Ubuntu (currently 22.04). For Windows, you’d probably need to run as Administrator.
To use these scripts, clone this repository or download the scripts directly. Ensure Python 3 is installed on your system.
git clone https://github.com/your-repository/relay-automation.git
cd relay-automation
pip uninstall serial
pip install pyserial
Run the script with the required arguments. For example:
python relay_control.py -d COM1 -b 9600 -r 1 -t 1
Create a file (e.g., commands.txt
) with each command on a new line and run the script:
python run_commands.py commands.txt 10
For infinite execution:
python run_commands.py commands.txt infinite
These scripts are provided "as is", without warranty of any kind. Use at your own risk. The author is not responsible for any damage or loss resulting from the use of these scripts.
Name: William Blair
Contact: Create an Issue
`