Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
871 views
in Technique[技术] by (71.8m points)

arduino - How come when I try to run 2 python scripts that give and take data from another and one's reading serial port data I get a permission error?

So I have 2 python scripts, one is reading serial port data and the other is receiving a list from that data, however once I run the second script I get a permission error and can no longer read from the serial port. These are my 2 scripts and I'm doing stuff with Arduino, I know that I can have all this in 1 file but for latency purposes I separated the logic from the read. Here are my scripts:

read.py:

import serial
from time import sleep

ser = serial.Serial('COM7', 9600)

while True:

    ser_bytes = ser.readline()
    decoded_bytes = ser_bytes[0:len(ser_bytes)-2].decode('utf-8')

    if len(decoded_bytes) == 0:
        ser.flushInput()
    if len(decoded_bytes) != 0:

        find1 = decoded_bytes.find('&')
        find2 = decoded_bytes.find('|')
        find3 = decoded_bytes.find('/')

        left = decoded_bytes[0:find1]
        right = decoded_bytes[find1+1:find2]
        fire = decoded_bytes[find2+1: find3]
        jump = decoded_bytes[find3+1:]

        keypresses = [left, right, fire, jump]

    ser.flushInput()

do.py:

from read import keypresses
import pyautogui as pg

while True:
    if keypresses[0] == 1:
        pg.keyDown('a')
    else:
        pg.keyUp('a')

    if keypresses[1] == 1:
        pg.keyDown('d')
    else:
        pg.keyUp('d')

    if keypresses[2] == 1:
        pg.mouseDown()
    else:
        pg.mouseUp()

    if keypresses[3] == 1:
        pg.keyDown('w')
    else:
        pg.keyUp('w')

If you could help that'd be nice, thanks.

question from:https://stackoverflow.com/questions/65516958/how-come-when-i-try-to-run-2-python-scripts-that-give-and-take-data-from-another

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...