|
|
On 2020-10-20 03:24, Ian MacArthur wrote:
> So, if you are comfortable with threads and such, that should be pretty
> straightforward. I you are not comfortable with threads... then this might
> be too complex a solution (sorry!)
A possibly easier solution would just be to call fork() to start
a separate process, then the child can handle sending data to the
"Oszilloskop-App" as a realtime process, and the FLTK app can just
kill the process ID to stop it.
So if the FLTK app is simply a Start and Stop button for starting
the data hose to the Oszilloskop-App, then the start button starts
the child process to feed data to the scope, and stop kills the child
to stop it, e.g.
#include <unistd.h> // fork
#include <sys/types.h> // kill()
#include <signal.h> // kill()
..
pid_t G_child = 0;
// Your start button callback
void start_callback() {
if ( (G_child = fork()) == 0 ) {
// We are the child.. forever loop feed data to scope app
while ( 1 ) {
val = read_adc(); // whatever code reads the ADC
write_scope(val); // whatever code writes to the "Oszilloskop-App"
usleep(100); // yield some cpu to the rest of the machine for the scope app to run
}
}
}
// Your stop button callback
void stop_callback() {
if ( G_child == 0 ) return; // child already stopped? early exit
kill(G_child, 9); // stop child
if ( waitpid(G_child, NULL, 0); // wait for child to stop
, G_child = 0;
}
Depending on how "realtime" the data flow needs to be, you can use linux's
realtime API to adjust the child process to be unaffected by some system
hiccups, e.g. http://www.isy.liu.se/edu/kurs/TSEA81/lecture_linux_realtime.html
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/31dfd906-45b7-37f6-8e7c-e190429927be%40seriss.com.
[ Direct Link to Message ] | |
|
| |