Python Forum
Function to Continuasly monitor serial port and control other functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function to Continuasly monitor serial port and control other functions
#6
(Mar-03-2018, 11:08 PM)marsokod Wrote:
(Mar-03-2018, 10:16 PM)ricardons Wrote: Function1() acquires sensor data and show it on lcd Function2() is the same as 1 but also writes the data to a text file So threading?
Yes, threading since you will be mostly IO-bound so there is very little risk of suffering from global interpreter lock. Unless Larz60+ has a better solution, I would advise going with the third option I gave you: At the beginning of your code, create 2 queue.Queue() and start 2 threads fetching data from these queues with a timeout. This timeout shall be big enough not to impact your performances with too many loops, but small enough as it will be the time you may have to wait to shut down your program. I run CAN bus monitoring on a Raspberry Pi and had no problem with a loop of 10ms, but 100ms should be even safer. Your serial monitor will just put a meaningful value in the corresponding queue. Your threads will pick this value up and act accordingly. When the main program shuts down, you can put a None value in the queues and make sure that your threads interpret that as a signal they should leave the queue monitoring loop and return. This way, your threads close nicely.
Thank you for your advicebut I'm not sure I have enough knowledge to put all that in a syntax code. Do you have any similar code. Thread +queue
Reply


Messages In This Thread
RE: Function to Continuasly monitor serial port and control other functions - by ricardons - Mar-04-2018, 12:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,221 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 507 Mar-19-2024, 09:02 AM
Last Post: zazas321
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,820 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,564 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  Is it possible to make a program recognize how many clicks it has had on the monitor? jao 0 1,181 Feb-25-2022, 06:31 PM
Last Post: jao
  python serial port barryjo 2 1,700 Dec-27-2021, 11:09 PM
Last Post: barryjo
  is there a way to mention port range or search for port dynamically with qConnection Creepy 0 1,515 Sep-09-2021, 03:15 PM
Last Post: Creepy
  How to Properly Open a Serial Port in a Function bill_z 2 4,577 Jul-22-2021, 12:54 PM
Last Post: bill_z
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 2,906 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea
Question Python3 - serial port reload parovelb 4 6,038 Apr-08-2021, 09:18 AM
Last Post: parovelb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020