Click here to Skip to main content
15,885,068 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Hi,
I'am developed one c# application in which i want to update graph real time data receiving from
udp & plot it accordingly different conditions in 13 controls of zed graph control also dump
data to file also. Second part works fine but graph plotting is not done correctly.
Below i paste code for both module,please suggest any change or show logical error in code.
1. Code for save data in file also add to rollingpointpairlist buffer.
C#
private void updateFile() {
           f = new Form1();
            for (int i = 0; i < arrLen; ) {
                chnId = buff[i];
                ushort smpCnt = toUInt16(buff, i + 1);

                if (chnId > 12) {
                    log.WriteLine("{0:D}\t{1:D} ???", new object[] { chnId, smpCnt });
                    return;
                }
                i += 3;
                try {
                    if (BitConverter.IsLittleEndian) {
                        for (int j = 0; j < smpCnt * chnCnt[chnId]; j++) {
                            for (int k = 0; k < smpSize[chnId]; k++)
                                smpData[(j + 1) * smpSize[chnId] - k] = buff[j * smpSize[chnId] + k];
                        }
                        fs[chnId].Write(smpData, 0, smpSize[chnId] * smpCnt * chnCnt[chnId]);
                        f.fillBuffer(smpData,chnId);//Here i add data to rolling point pairlist for plot into graph
}
2. code for insert data in rolling buffer according to condition on chId

C#
public void fillBuffer(byte[] data, int chId)
        {
            int bufLength = data.Length;
            double[] plotData = new double[data.Length];

                 switch (chId)
                    {
                        case 0:
                            intrptval1 -= initTimer;
                            if (intrptval1 <= 0)
                            {
                                updtGraph(ch0.tSmpCh1, data, bufLength, ch0.plotBuff1, zedGraphControl1, ch0.pane1);
                                ch0.definedCntValues1 = ch0.valToSet1;
                                bufLength -= bufLength;
                            }
                            break;
}
}


3. Code for update graph
C#
private void updtGraph(double smpTime, byte[] data, int ptsToPlot, RollingPointPairList rollBuff, ZedGraphControl ctrl, GraphPane pane)
       {
           pane = ctrl.GraphPane;
           double[]  plotData = new double[data.Length];
        //  double[] plotData = toDouble(data, 0);

           try
           {
               for (int index = 0; index < ptsToPlot; index++)
               {
                   plotData[index] = toDouble(data, index);
                   startTimer += smpTime;
                   rollBuff.Add(startTimer, plotData[index]);

                   Scale xScale1 = ctrl.GraphPane.XAxis.Scale;
                   double delta = startTimer - rollBuff[0].X;
                   if (delta > smpTime * ptsToPlot - 1)
                   {
                       xScale1.Min = startTimer - smpTime * (ptsToPlot);
                       xScale1.Max = startTimer + smpTime;
                   }
                   else
                   {
                       xScale1.Min = rollBuff[0].X;
                       xScale1.Max = rollBuff[0].X + smpTime * (ptsToPlot);
                   }
                   ctrl.AxisChange();
                   ctrl.Invalidate();
                   ctrl.Refresh();
               }
}
Posted
Updated 28-Dec-13 4:10am
v3
Comments
ZurdoDev 28-Dec-13 11:09am    
What's your question?
Venkat Raghvan 30-Dec-13 4:29am    
why graph control is not updated?
Venkat Raghvan 31-Dec-13 0:40am    
can i write graph updating code in Timer event of form??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900