Thanks for your response
You said reading Input in a Loop can cause much CPU. Thanks for the tip. Can you please tell me what is the alternative. I need to continually monitor the inputs for changes. Is there any way like events attached to inputs which get raised ? I just observed that it occupies 100% of the cpu
Thanks once again
Hi Eugene. Thanks for the prompt response.
I will prefer option 1 : Program in another language and send the data to Xojo application.
But I am trying to see how this can be done. Google shows that one particular method is to use IPCSocket. Is that the only way.
I am trying to do some serious stuff.I am just trying to evaluate if Xojo fits the requirements.
Also, right now I am using Xojo for raspberry Pi which is with a free license. I am not n able to deploy the app on to Rasperry other than the Run Remotely option.
Not sure again if there is another way
There is an example of the pigpio library in Xojo (not supported) in Example 19-1. The same pigpio library that is used with Xojo also is supported by Python and there are many references to example code
thats a Python .py script which start a shell script.
Python can also handle tcp connections with a few rows, means it can speak with xojo.
also useful at raspberry pi is remote gpio via tcp because you can run your gui app elsewhere.
I “discovered” that you are the author of the book " I Wish I Knew How to… Program Raspberry Pi 4B Electronics with Xojo" . I have a Raspberry Pi 3b+. Will this book help in to write programs for that or I need to buy the Rpi 4B ?
Probably my dumbest question even after your earlier answer “The pigpio has a method called gpioSetISRFunc … So can this be used to raise the interrupts or should I have to go with the earlier suggested answer of 2 programs communicating over ISOSocket ?”
I am trying to develop an application for the industrial environment, if I have to use arduino then I will rather go with a small PLC (with High speed counter ) and use Modbus (if a library is available in Xojo) to connect Pi with the PLC …
Else give up the RPi approach all together
Thanks and sorry for so many questions …
If you don’t want to get into interrupts, callbacks, IPC, Python and so forth, you can also just check the state of your inputs at intervals using a timer, depending on what amount of latency you can tolerate. Checking at say 100ms intervals should leave plenty of time for the processor to handle other tasks like the UI. Not sure how short the polling interval can be made before things get bogged down.
Yeah. That is what I have already done. But the latency I have given is 20ms. This i have kept in a separate thread.
But, as MarkusR said, the cpu used is 97 to 100%. Of course, there is not really much work apart from monitoring the gpio. The status of the GPIO is shown on the front GUI.
I am not facing much issue as far as response is concerned. But I am still concerned. I am planning to set up the electronics side to run the RPi for a few hours and test if there is any issue. This will be my deciding factor else I will go back to the toradex board which I have been using earlier. Issue is , it is quite costly and gets costlier as I scale it match the RPi
Thanks for your response.
This is digital input equivalent to a PLC’s High Speed Counter input.
As an example scenario : counting the products moving on a conveyor at a speed for 20 products per second
That is why I have to have a very low latency . As suggested by Eugene, Interrupts are the best way, but I am not so strong in python to write a program which communicates with Xojo. And I somehow do not feel comfortable with the idea of 2 programs for a single task.
Thanks for your response
You said your program loops, which would explain 100% CPU usage. If it’s not looping, I would not expect a 20ms timer that reads some ports and updates some controls to use 97-100% CPU. Are you sure your program is not looping? It should just sit idle until the timer fires.
Not sure that a thread is giving you any benefit here; Xojo only uses one CPU core no matter how many threads you run, unless you use Worker apps.
First of all, I am sorry. I did not get things straight. Somewhere my replies were misleading. Yes , my progam has a loop in a separate thread. I also use a thread.sleep for 20ms.
Ok , thanks for pointing out, I will try the 20ms timer.
BTB, I am from the Desktop (C#) world. You rightly brought the single core usage of Xojo to my attention. Seeing the threads example I got carried away.
I will also look into Worker apps.
And my thanks to all of you. Honestly, i have worked with various other s/w and forums, but the response in Xojo forum tops the list.
i have a idea to run the Python script in a shell and read the output data in xojo Shell.
this Python could count perfect the signals often and output it each second as sum with print. https://docs.xojo.com/Shell
the python interpreter need to start with the name of the .py script.
as example the interpreter path is hidden in remark at the first line of a .py script #! /usr/bin/python
I really appreciate your effort in replying . I have been trying to get your book online , but the payment is failing consistently. I will raise the issue with my credit card company and find if it is any way related to international transaction being blocked.
I will try again today.
Thanks a lot.
And, I am trying Julia’s suggestion. I am trying to use the timer event in the MainWindow itself. That part is ok, I am just trying to get the pigpio library to work . OF course, I am scouring some of the help on the internet finding how to use the library, which is a bit difficult, in the absence of your book (my purchase attempt failed multiple times)