From 0a673e300800b91342499cec9cd482b5d2d9c603 Mon Sep 17 00:00:00 2001 From: binary Date: Tue, 10 Nov 2020 20:46:04 +0100 Subject: Fully working init for alpine vm --- roles/serial/files/serial_macro.py | 14 ++++++++++++++ roles/serial/tasks/main.yml | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 roles/serial/files/serial_macro.py (limited to 'roles/serial') diff --git a/roles/serial/files/serial_macro.py b/roles/serial/files/serial_macro.py new file mode 100644 index 0000000..eb47226 --- /dev/null +++ b/roles/serial/files/serial_macro.py @@ -0,0 +1,14 @@ +#!/bin/python3 + +import serial +import time + + +def send_cmd(ser, delay, cmd): + ser.write(f"{cmd}\n".encode("utf-8")) + time.sleep(delay) + +def send_cmds(ser, cmds): + for cmd in cmds: + send_cmd(ser, cmd[0], cmd[1]) + diff --git a/roles/serial/tasks/main.yml b/roles/serial/tasks/main.yml index 95a8ff5..2db546d 100644 --- a/roles/serial/tasks/main.yml +++ b/roles/serial/tasks/main.yml @@ -5,3 +5,15 @@ - name: Check pyserial installation command: python3 -m pip install pyserial + +- name: Ensure python scripts directory exists + file: + path: /data/python + recurse: true + state: directory + +- name: Copy custom serial library + copy: + src: serial_macro.py + dest: /data/python/serial_macro.py + -- cgit v1.2.3