08-04-2010 01:49 AM
Hi All
I working on my application library which including almost every instrument drivers from NI in this library .
I have tested a few classes of this library where I get a support from my NI local supplier to lend me .
Now I Test my Scope class and found some errors related to WaveformGraph which is an UI control of Measurement studio ( I use Ver.9)
The error message tell me that Message="Collection was modified; enumeration operation may not execute." ( suspect one of the Axises, Cursor ,plot or annotation) after I continously acquire data from scope channels . The detail of exception is attached herewith.
The fragment of the code where the plot going on is shown bellow:
Public
Sub PlotGraph(ByVal WaveFormGraph As WaveformGraph)
For i As Integer = WaveFormGraph.Plots.Count To m_NumPlotChannel - 1 Step i + 1
WaveFormGraph.XAxes.Add(
WaveFormGraph.YAxes.Add(
New XAxis())New YAxis())newPlot As WaveformPlot = New WaveformPlot(WaveFormGraph.XAxes(i), WaveFormGraph.YAxes(i))
Dim
WaveFormGraph.Plots.Add(newPlot)
Next
If m_IsMultipleChannel Then
Dim nCh, nRec, I, J As Integer
nCh = m_MultipleAnalogWaveForm.Channels
nRec = m_MultipleAnalogWaveForm.Records
For I = 0 To nCh - 1 For J = 0 To nRec - 1Of Double)(m_MultipleAnalogWaveForm(J, I)) Next
Next
Else End If End Sub
WaveFormGraph.Plots(0).PlotWaveformAppend(Of Double)(m_AnalogWaveform(0))
WaveFormGraph.Invalidate()
WaveFormGraph is passed to this method by client object ( library consumer) and this method is called when a client get an event GotDataForPlot which raised from a separate thread that handle by a special delegate.
I'm not sure it is a bug of measurement studio or not , who know a solution please advise.
Regards
WaveFormGraph.Plots(I).PlotWaveformAppend(
WaveFormGraph.Invalidate()
08-04-2010 03:24 AM
The Code in the body of my post was messy by a cut and paste operation. I couldn't edit it so I attached 2 files which one of them is the code of the method which get messy in my post.
08-05-2010 08:03 AM
Hi Khammonh,
Please try to reproduce the error in a more simple program that uses only software. If you are able to reproduce the error in another, more simple project please attach a ZIP of your Solution, Project and source files. If you are unable to reproduce and it works correctly in your simple test project, we can assume it is a bug on your end.
08-06-2010 02:48 AM
Hi Micheal
Thank for reply.
I use sample code from NI website which quite similar to my case and try I can't reproduce an error but there is a different with sample code ,when I use multiple channel in the plot just plot only one graph plot (curve) but on my plot 2 curves . Actually the plot procedure is in the attached on my previous post.
The different of my code and sample code is my code take WaveFormGraph object as an argument which pass by value and does a plot insite by library code . But in the sample code does a plot locally .
I don't see any thing that could be a bug in a plot code did you?
I try to copy a plot code in my library to a form where I test this library and take a raw data from my library . With this method I still found the same error.
What happen in the library code is when it completely fetch a data from device it will rise the event GetDataToPlot . In a client application in this case is the test form when received this call back event will take a received data and plot by the above plot code . So the different is the sample code does every thing locally but my , received an event notice then plot the graph. Is there any property of the WaveFormGraph need to pay attention on , I mean to set a proper value so that we can overcome this error.
Regards
08-09-2010 02:38 PM
Hi Khammonh,
Are you saying that you are able to reproduce with simluated data or data from a text file? If you can pull from a data file instead of from your actual hardware, this would really help. If you take hardware out of the picture, please attach your code and I'll try to reproduce the problem.
Otherwise it is difficult to guess at the cause.
08-10-2010 02:39 AM
Hi Michael
No I didn't say that and I don't think a hardware would cause this problem rather than WaveFormGraph component . In the same project where I didn't plot a graph I can acquire a data from hardware and find scalar values and their statistic and do some sort of calculation in a continous mode (forever) I didn't get any error . Once I do a plot I will get an error after 200 loops or so and when the error occured and I relaunch a project I will get an immediate error regardless of number of loop . It is interesting that if the error occur in the next launch if I do a debug step (F10 or F11) for 2-3 loops then use F5 to continue without break point it can be ran another 200 loops then error again. I don't know why 200 loops ( the history capacity is 1000) .
The point where the error occurs is in the line where I put an arrow in the front of the attached file LocalPlotCode.txt .
You will see that this code and previous code is almost identical but this code I put in a local form where the Graph component located and this code run on the event where local form get data from hardware.
So it is help you to identify what's wrong?
Regards
08-11-2010 01:27 PM
Hi Khammonh,
I apologize for the misunderstanding. I agree this problem likely doesn't involve hardware.
I was asking you to help me reproduce the problem. Currently, your program pulls data from your hardware and graphs it. I'm hoping you can simulate the hardware data acquisition by reading from a text file for example. If so, you could send me your entire solution, project, code and data in a ZIP. This should allow me to easily tell whether or not I can reproduce the problem on a test machine here.
This will help isolate the problem so we can determine if we have a bug or not.
08-12-2010 09:36 AM
Hi Michael
To do as per your request I should create another Library which does exactly the same flow as my current library but instead of reading from hardware , read from text file . This will take some time .
I want to let you know that in my current library , I have a method that do an instant reading and continous reading both go to the same plot procedure. The problem I face with is on a continous read which launch by a thread that working on background . Yesterday I try one idea to test does the thread causes this error.
So I do a loop outside the library ( in a client application ) . In this loop I call a method that do an instant read so when data ready my library raise event and on this event I plot a waveform the loop stop when a certain count is reach , I try with 1000 loops count I didn't get any error but just observe a slow down of the plot near 1000 loops. This procedure by idea it does the same thing as my continous read method but not run on a thread but on a Do While loop in a client code . A thread on my library also call an instant read method in a loop as I did in my client application and this thread is put on background . So a big question why the reading thread effect a plot of WaveFormGraph? Is possible that a reading on a background thread is faster than what it does on a loop of client application so that the WaveFormGraph can't update its collection on time.
Regards