PeaButters
Posts: 12
Joined: Tue Aug 02, 2016 1:15 am

sending integer value to GUI

Sun Aug 21, 2016 2:29 am

Hey guys, so I've got an Arduino measuring water flow though a tap and sending the data via RF Transmission to a Raspberry Pi 3 Model B. I've got the data being received and displayed but now i am trying to implement a GUI to display the data on. I've written the Transmission code and the GUI code separately and run them through from the terminal. They both work.

Here's my problem, I need to try to get the transmission code to send the integer value to the GUI. The integer value of updating every three seconds. I have tried numerous ways to get the value into the GUI with no luck. The most promising way Iv'e found is to write the value to a text file every time it updates. How can i get the GUI to read this file. It seems to me that i cant read and write text files from to different programs at the same time? When i put the read code in the GUI is a loop, it never exits the loop hence not letting the GUI open.

Any ideas on this will be much appreciated!

dddomodossola
Posts: 42
Joined: Thu Jan 22, 2015 8:56 am

Re: GUI

Sun Aug 21, 2016 8:07 am

Is there a motivation for which gui and transmission code must work in separate programs?

With this architecture you can make them communicate by means of a tcp socket or a database.

User avatar
Gavinmc42
Posts: 4527
Joined: Wed Aug 28, 2013 3:31 am

Re: GUI

Sun Aug 21, 2016 9:21 am

Logger - open file, write data, close file.
GUI, open file, read data, close file.
Multitasking Linux handles the rest.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

PeaButters
Posts: 12
Joined: Tue Aug 02, 2016 1:15 am

Re: GUI

Sun Aug 21, 2016 9:47 am

Gavinmc42 wrote:Logger - open file, write data, close file.
GUI, open file, read data, close file.
Multitasking Linux handles the rest.
Thats what I've tried. The transmission program is updating the text file nicely, but the GUI program seems to just read it once and not update again and a while loop isn't working. Could the problem be that i can't be opening and reading from a file from one program while another program is opening and updating that value? Also, the receiving data and GUI are running on the same Raspberry Pi.
Last edited by PeaButters on Sun Aug 21, 2016 10:17 am, edited 1 time in total.

PeaButters
Posts: 12
Joined: Tue Aug 02, 2016 1:15 am

Re: GUI

Sun Aug 21, 2016 9:48 am

dddomodossola wrote:Is there a motivation for which gui and transmission code must work in separate programs?

With this architecture you can make them communicate by means of a tcp socket or a database.
Yeah i've tried other ways but i can't make it work. This is the closest i've gotten.
What is a tcp pocket? Also, the receiving data and GUI are running on the same Raspberry Pi.

jogl
Posts: 93
Joined: Sun Mar 13, 2016 12:02 pm
Location: SW Ontario Canada

Re: GUI

Sun Aug 21, 2016 10:57 am

You cannot (I believe) have a text file open twice. So your logger program and your gui program need to open, write/read, and then close the file. You should put some error handling in both so that if they try to access the file when it is already open, they wait for it to close (or whatever).

PeaButters
Posts: 12
Joined: Tue Aug 02, 2016 1:15 am

Re: GUI

Sun Aug 21, 2016 11:15 am

jogl wrote:You cannot (I believe) have a text file open twice. So your logger program and your gui program need to open, write/read, and then close the file. You should put some error handling in both so that if they try to access the file when it is already open, they wait for it to close (or whatever).
That makes sense. But how should i handle this error? Should i make them do what they need at specific intervals? eg, every 2 seconds for the logger and every 2.5 seconds for the GUI? What other error handing techniques are there?
Thanks for the help

jogl
Posts: 93
Joined: Sun Mar 13, 2016 12:02 pm
Location: SW Ontario Canada

Re: GUI

Sun Aug 21, 2016 11:28 am

Using try: is a common way,

Code: Select all

>>> while True:
...     try:
...         x = int(input("Please enter a number: "))
...         break
...     except ValueError:
...         print("Oops!  That was no valid number.  Try again...")
...
That is from the python.org site, it is a good resource, check it out.

https://docs.python.org/3/tutorial/errors.html

Return to “Python”