ラズベリーパイ4を使っている初心者です。
ラズパイ4のUPSを購入しそれに使うソフトを使おうとしてます。
upsの状態を見るソフトなのですが実行するとエラーが出ます。
どうすればいいか教えていただければと思います。
よろしくお願いします。
発生している問題・エラーメッセージ
Python 3.7.3 (/usr/bin/python3) >>> %Run UPS_GUI_demo.py Traceback (most recent call last): File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 265, in open self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) PermissionError: [Errno 13] Permission denied: '/dev/ttyAMA0' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/pi/UPSPACK_V3/UPS_GUI_py/UPS_GUI_demo.py", line 10, in <module> test = UPS2("/dev/ttyAMA0") File "/home/pi/UPSPACK_V3/UPS_GUI_py/upspackv2.py", line 11, in __init__ self.ser = serial.Serial(port,9600) File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 240, in __init__ self.open() File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)) serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0' >>>
該当のソースコード
python
1#!/usr/bin/python3 2 3from upspackv2 import * 4import tkinter as tk 5import re 6import serial 7import time 8 9 10test = UPS2("/dev/ttyAMA0") 11 12 13def reflash_data(): 14 version,vin,batcap,vout = test.decode_uart() 15# loc_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 16 cur_time = time.time() 17 cur_time = cur_time - load_time 18# print(cur_time) 19 20 21 22 time_var.set("Running: "+str(int(cur_time)) + "s") 23 24 25 26 batcap_int = int(batcap) 27# print(type(batcap_int)) 28 29 if vin == "NG": 30 vin_lable.config(bg = "red") 31 vin_var.set("Power NOT connected!") 32 else: 33 vin_lable.config(bg = "green") 34 vin_var.set("Power connected!") 35 36 if batcap_int< 30: 37 cap_lable.config(bg = "red") 38 if batcap_int == 1: 39 cur_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) 40 stop_time = "\nHalt time :"+cur_time 41 with open("log.txt","a+") as f: 42 f.write(stop_time) 43 os.system("sudo shutdown -t now") 44 sys.exit() 45 else: 46 cap_lable.config(bg = "green") 47 48 49 cap_var.set("Battery Capacity: "+str(batcap)+"%") 50 vout_var.set("Output Voltage: "+vout+" mV") 51 52 window.after(1000,reflash_data) 53 54def hit_exit(): 55 window.destroy() 56 57 58 59#loc_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 60#print(loc_time) 61load_time = time.time() 62 63#cur_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) 64#start_time = "\nStart time :"+cur_time 65 66#with open("log.txt","a+") as f: 67# f.write(start_time) 68 69window = tk.Tk() 70window.title("UPS GUI demo") 71window.geometry("400x200") 72 73time_var = tk.StringVar() 74ver_var = tk.StringVar() 75vin_var = tk.StringVar() 76vout_var = tk.StringVar() 77cap_var = tk.StringVar() 78 79version,vin,batcap,vout = test.decode_uart() 80ver_var.set("Smart UPS "+version) 81 82ver_lable = tk.Label( window, 83 textvariable = ver_var, 84# bg = "green", 85 font = ("Arial",12), 86 width = 20,height = 2) 87ver_lable.pack() 88 89 90 91time_lable = tk.Label( window, 92 textvariable = time_var, 93 bg = "green", 94 font = ("Arial",12), 95 width = 20,height = 2) 96 97time_lable.place(x=10, y=50, anchor='nw') 98 99 100 101vin_lable = tk.Label( window, 102 textvariable = vin_var, 103 bg = "green", 104 font = ("Arial",12), 105 width = 20,height = 2) 106 107vin_lable.place(x=210, y=50, anchor='nw') 108 109 110cap_lable = tk.Label( window, 111 textvariable = cap_var, 112 bg = "green", 113 font = ("Arial",12), 114 width = 20,height = 2) 115 116cap_lable.place(x=10, y=100, anchor='nw') 117 118 119vout_lable = tk.Label( window, 120 textvariable = vout_var, 121 bg = "green", 122 font = ("Arial",12), 123 width = 20,height = 2) 124 125vout_lable.place(x=210, y=100, anchor='nw') 126 127 128b1 = tk.Button(window, 129 text = "Exit", 130 width = 30,height = 2, 131 command = hit_exit) 132b1.place(x=70, y=150, anchor='nw') 133 134 135window.after(100,reflash_data) 136 137window.mainloop() 138
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/05/30 09:06