Multiprocessing/ Threading / asyncio for PyQt6 and python-can

39 views Asked by At

EDIT: Relocated useless paragraphs.

Program Background: I'm making a program to replace a radio controller for my car's head unit. The goal is to create a GUI for a tablet to display the current screen and replace the current button controller for the (AC) Air Conditioning, and (AVU) Audio-Video-Navigation Unit.

Program Structure:

  • PyQt6 -> Creates app (QApplication) -> Creates Window(QWidget) -> Creates Buttons (QButton) and Potentiometer(QSlider)
  • Create Controller -> Connects to Virtual CAN Network -> Starts Periodic Send
  • Configure Widgets -> Button Press -> Button Release -> Dial Change State -> Dial Release
  • PyQt Main-Loop

Flow Diagram(hopefully useful....) Flow Diagram Showing Program Object Creation, and Flow of Message Information

The End Goal #EDIT for clarity

  • My GUI needs to be able to run continuously. When a button is pressed and held, I need to be able to check every 1/10 seconds whether or not it's still pressed.
  • On button press, I need to send a message on the network, listen on the network for an acknowledge.
  • On acknowledge receipt, if the last message wasn't a release-> wait 0.1 seconds, else return to main loop. If button is still pressed send another message, else send release message.

Problems: If I create a can.Notifier object, the periodic messages on the network lock the interpreter, the debugger gets locked within repeated calls from the busy network. (There is a filter installed, but the specifc controller ID has a broadcast sent twice a second)

It seems like what I need is two, or multiple, main loops running.

  1. A GUI - provides button status information or triggers function/method calls.
  2. A network interface that reads/filters frames, and sends cyclic / instantaneous messages.
  3. A top level controller that reads button states, and controls spacing between user messages.

My program works segregated.

  1. I can connect to the network, send and receive messages, wait on acknowledge and send follow up.
  2. I have a GUI with a grid array whose objects contain their specific can-frame-data lists.
  3. I can send messages from the GUI to the network on press, release, state-change.

When I try to connect them all together, I get restricted by a cyclic process in one of those three apps.

  1. The GUI can't update because the can.Notifier gets caught in processing new network messages.
  2. When the GUI doesn't update, I cannot check QPushButton state or run QPushButton release events.
  3. I can't make the interpreter wait for the 0.1 second delay without freezing the GUI, or missing the state change.

I appreciate anyone taking the time to help this cluster question.

UPDATE

Very constructive comments lead me to Qt's CAN and Threading packages/modules. I made the problem more difficult by attempting to create my own implementation of each without the background. Will post a write up "how I solved" after creating an appropriate workflow.

Summarizing Bad Post Paragraphs: P1 - Apologizing for stack exchange inexperience. My Background: P2 - Stating beginner to intermediate programming experience. I'm missing a critical principal in programming and I can't identify the topic to go research. P3, P4 - Word salad about how the problem feels like a quick fix, and am looking for the buzz word to research.

0

There are 0 answers