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.
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);
}
2. code for insert data in rolling buffer according to condition on chId
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
private void updtGraph(double smpTime, byte[] data, int ptsToPlot, RollingPointPairList rollBuff, ZedGraphControl ctrl, GraphPane pane)
{
pane = ctrl.GraphPane;
double[] plotData = new double[data.Length];
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();
}
}