I'm working on a python program in which I use a PyQt GUI to send data to an Arduino by pressing a button. The Arduino should then perform a measurement while python is waiting, and send a message back to the PC where the output is displayed on the GUI. The problem is that when I press the button, I only receive the following message while the window is closing:
Process finished with exit code -1073740791 (0xC0000409)
I guess that the GUI has problems to perform a delay or to wait for an input but I'm not sure. Does anyone have an idea?
Thanks for any attempt to help!
Python Code:
#check connection
try:
    arduino = serial.Serial('COM10', 9600, timeout=0)
    print("Connected to port!\n")
except Exception as e:
    print(e)
class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.initWindow()
    def initWindow(self):
        self.resize(1000, 100)    #window size
        self.setWindowTitle("Test")
        startButton = QPushButton("Start",self)
        startButton.move(50,10)
        self.textBox = QTextEdit(self)
        self.textBox.move(300,10)
        self.textBox.resize(500,40)
        startButton.clicked.connect(self.action)
        self.show()
    def action(self):
        arduino.write('s'.encode())
        while not arduino.in_waiting():
            time.sleep(0.001)
        incomingData = arduino.readline().decode("utf-8")
        self.textBox.setText(incomingData)
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec())
Arduino Code:
void setup() 
{
  Serial.begin(9600);
}
void loop() 
{
  if(Serial.available() > 0)
  {    
    String testString = Serial.readString();
    delay(4000);  //measurement simulation, taking several seconds
    Serial.println("Result");
  }
}
User contributions licensed under CC BY-SA 3.0