I'm an electronic engineer and I can use C. I'm writing a program that acquires data from an ECG module and send it to another remote pc using an arrays of data through socket. All works properly. My problem is, I need to plot that data in live stream.
To stream data I tried to use gnuplot, everything worked fine but when I put the fprintf code in a while loop to refresh the array and write new data it stopped working.
This is part of the raw code I used to call gnuplot in my c program:
FILE* gnuplot = popen("gnuplot -persist", "w");
while(1) {
//pulizia buffer e lettura
bzero(buffer, sizeof(buffer));
n = read(newsockfd,buffer,sizeof(buffer));
if (n < 0) error("Errore nella lettura del Socket");
for (j=0; j <= 255; j++){
printf("%d ",buffer[j]);
}
//comunico con gnuplot e invio i miei dati
fprintf(gnuplot, "plot '-' \n");
for (i = 0; i < NUM_POINTS; i++)
{
fprintf(gnuplot, "%d %d\n", (r+i), buffer[i]);
}
r = r+i+1;
fflush(gnuplot);
}
Why did the program stop working when I added the printf, and how do I fix it?