0
Good afternoon friends, I am creating a program in c# that should plot in a graph the current values of the serial port (Arduino) in a picture box. To draw the graph I am creating points(x,y) and connecting the same forming lines (drawline). In this way the graphic is drawn, but the "pen" that runs through the picturebox. I’m trying to make an effect similar to a seismograph (as if the paper(picturebox) dislocated, as in the video https://www.youtube.com/watch?v=0cSlxPeqHA8). I believe it is basically to shift several lines. Currently, I am doing it this way:
int contDRAW = 0, a; //contadores
private PointF[] vetpoint = new PointF[6000];//vetor para incrementar o X para fazer o deslocamento
float[] aquisicaoplot = new float[6000]; //vetor onde armazeno cada valor enviado pela serial
//a cada vez que for chamada a função desenhar já tenho um novo y
private void Desenhar()
{
vetpoint[contDRAW].Y = aquisicaoplot[contDRAW];
for (a = 0; a <= contDRAW; a++)
{
if (contDRAW != a)
{
vetpoint[a].X ++;
}
else vetpoint[a].X = 0;
if (contDRAW == 0 || a==0) timerDRAW.Enabled = true;
else graph.DrawLine(new Pen(Color.LightGreen, 0.1f), vetpoint[a - 1].X, 24 * aquisicaoplot[a-1], vetpoint[a].X, 24 *aquisicaoplot[a]);
}
contDRAW++;
}
private void timerDRAW_Tick(object sender, EventArgs e)
{
Refresh();
}
This code comes close to the intended result. The chart is currently shifting, but it is reset and redrawn every time it enters "for". What can I do? Am I following the right path? If anyone knows or has any tips on how to do this please reply.
EDIT1:
I updated the Draw() function to the following:
private void Desenhar()
{
System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.LimeGreen, 0.1f);
vetpoint[contDRAW].Y = 24*aquisicaoplot[contDRAW];
for (a = 0; a <= contDRAW; a++)
{
if (contDRAW != a) vetpoint[a].X++;
else vetpoint[a].X = 0;
}
if (contDRAW == 0) timerDRAW.Enabled = true;
else graph.DrawLines(myPen, vetpoint);
//else graph.DrawLine(myPen, vetpoint[contDRAW - 1].X, 24 * aquisicaoplot[contDRAW-1], vetpoint[contDRAW].X, 24 * aquisicaoplot[contDRAW]);
contDRAW++;
myPen.Dispose();
}
I had a small advance in relation to the effect I want to produce, because the graph moves without being redesigned from the beginning, however, now it is with a lot of Flicker and delay after drawing several points.
Whatever the method is
Refresh()
does? He was called in the methodtimerDRAW_Tick
and was not posted. And where the functionDesenhar
is called?– Kevin Kouketsu
The function Draw( ) is called every time I have a new data in the serial. That is, another y that must be placed on the graph. Refresh( ) would be to "update" the chart with the new points shifted.
– Felipe Mateus
Every time I read a serial data I draw the new point in the coordinate (0,0) and move the remaining points to the right.
– Felipe Mateus