PlotPanel contains a nice demo (TryPlotPanel) so we are based in the official demo example.
We create a new "graph" form .
We add these variables :
public My_PlotPanel: TPlotpanel; Xcur : integer; //Xcur is the current time stamp Xwidth : integer;
We make the CreatePanel and the ClearPanel procedures.
procedure TFormGraph.CreatePanel(Sender: TObject); begin My_PlotPanel:=Tplotpanel.Create(Self); My_PlotPanel.Top:=8; My_PlotPanel.Left:=8; My_Plotpanel.Width:=462; My_PlotPanel.Height:=300; My_PlotPanel.Margin:=10; My_PlotPanel.Anchors:=[akTop,akLeft,akBottom,akRight]; My_PlotPanel.Color:=clBtnFace; My_PlotPanel.BackColor:=clWhite; My_PlotPanel.GridColor:=clSilver; My_PlotPanel.PlotPen.Color:=clBlue; My_PlotPanel.PlotPen.Width:=2; My_PlotPanel.XLabel:='Record number'; My_PlotPanel.YLabel:='Value'; end; procedure TFormGraph.ClearPanel(); begin My_PlotPanel.Freeze(True); My_PlotPanel.XMarks:=true; My_PlotPanel.YMarks:=true; My_PlotPanel.XMarksFont.Color:=clBlack; My_PlotPanel.YMarksFont.Color:=clBlack; My_PlotPanel.XMin:=0; My_PlotPanel.XMax:=Xwidth; My_PlotPanel.YMin:=0; My_PlotPanel.YMax:=10; My_PlotPanel.XInterval:=1; My_PlotPanel.YInterval:=1; My_PlotPanel.ClearData; My_PlotPanel.Freeze(False); end;
Focus your attention at the TryPlotPanel -> TimerPlot tab -> Start/Stop Chart button event
On the new form on the create event we do :
procedure TFormGraph.FormCreate(Sender: TObject); begin CreatePanel(nil); ClearPanel(); end;
Now the TTimer can plot the graph !
//The timer ! procedure TFormMain.TimerTimer(Sender: TObject); var y:double; begin Application.ProcessMessages; GetCode(); StatusBar.Panels.Items[1].Text := 'Code : ' + PrintCode(); if IsValidCode then begin StatusBar.Panels.Items[1].Text := StatusBar.Panels.Items[1].Text + ' [valid]'; ParseStatus(); LabelScreen.Caption := PrintStatusInLabel(); //Plot the graph ! if CheckBoxEnableGraph.Checked then begin inc(FormGraph.Xcur); //increase the time stamp With FormGraph.My_PlotPanel do begin Freeze(True); PlotPen.Width:=2; PlotMode:=pmLine; if TryStrToFloat(My_Multimeter.Status.ValueNoPrefix,y) then begin AddXY(FormGraph.Xcur,y); //Plot x,y point //Autoscale if FormGraph.CheckBoxAutoscaleY.Checked then begin if FormGraph.Xcur > 10 then AutoScale(0); //Autoscale x,y end else begin YMax:=FormGraph.SpinEditMaxY.Value; YMin:=FormGraph.SpinEditMixY.Value; end; XMin:=FormGraph.Xcur-FormGraph.Xwidth; //Scale X to XWidth XMax:=FormGraph.Xcur; XInterval:=1; YInterval:=(YMax-YMin)/10; end; Freeze(False); end; end; end else begin StatusBar.Panels.Items[1].Text := StatusBar.Panels.Items[1].Text + ' [invalid]'; end; FormMain.Refresh; //Close the timer and disconnect if IsConnected is false if not IsConnected then begin Timer.Enabled:=false; Disconnect(); end; end;
We are done !
DMM Data Logger can be downloaded from here
The video presentation is located below :
We started form a hardware hack and we made a dedicated software for our hacked hardware from scratch.
The hardware to software approach is now finished !
Enjoy !