Go Back   IceInSpace > Equipment > Software and Computers
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread
  #1  
Old 07-03-2020, 10:44 AM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
VB.net error - could use some help!

I've decided to post this again here as I don't think it is getting noticed in the parent thread. I've been working on an arduino cloud detector project, mainly to learn how arduinos work and also to learn some basic computer programming. I've created a desktop application using visual studio VB forms to receive the sensor data from the arduino, do the cloud prediction calcs and display the information. It is all working well except I get an occasional error in the VB app. The error appears to be related to updating one of the three plots I have on the VB form.

I get the following exception code when it occurs:

************** Exception Text **************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOper ationException(ExceptionResource resource)
at System.Collections.Generic.List`1.E numerator.MoveNextRare()
at System.Collections.Generic.List`1.E numerator.MoveNext()
at System.Windows.Forms.DataVisualizat ion.Charting.ChartTypes.LineChart.P rocessChartType(Boolean selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
at System.Windows.Forms.DataVisualizat ion.Charting.ChartTypes.LineChart.P aint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
at System.Windows.Forms.DataVisualizat ion.Charting.ChartArea.Paint(ChartG raphics graph)
at System.Windows.Forms.DataVisualizat ion.Charting.ChartPicture.Paint(Gra phics graph, Boolean paintTopLevelElementOnly)
at System.Windows.Forms.DataVisualizat ion.Charting.Chart.OnPaint(PaintEve ntArgs e)
at System.Windows.Forms.Control.PaintW ithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPain t(Message& m)
at System.Windows.Forms.Control.WndPro c(Message& m)
at System.Windows.Forms.Control.Contro lNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.Contro lNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.C allback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I've done the obvious Google search and have arrived at the conclusion this error is related to updating or modifying the chart from a different thread than it was created on.

My code is divided into a series of subroutines:

ProcessData() ' do the basic calcs
CloudCalcs() ' do the cloud calculations
UpdateHistory() ' update the graphs

The subroutine for the graph updates is:

Private Sub UpdateHistory()
time = TimeOfDay() ' retrieves current system time (used for plot x axis)
Chart1.Series("Series1").Points.Add XY(time, cloud)
Chart2.Series("Series1").Points.Add XY(time, light)
Chart3.Series("Series1").Points.Add XY(time, wind)

If HistoryFull = False Then
j = j + 1
End If

' this starts removing the oldest data points when the required number of points have been added to the history

If j > hpt Then
HistoryFull = True
Chart1.Series("Series1").Points.Rem oveAt(0)
Chart2.Series("Series1").Points.Rem oveAt(0)
Chart3.Series("Series1").Points.Rem oveAt(0)
End If

End Sub

I've tried various things to stop it executing other parts of the code while the UpdateHistory() part is running but haven't managed to avoid the error yet.

Just wondering if anyone with more programming experience has any tips?

Thanks

Peter
Attached Thumbnails
Click for full-size image (VBR1.JPG)
43.6 KB16 views
Reply With Quote
  #2  
Old 09-03-2020, 10:55 PM
peter_4059's Avatar
peter_4059 (Peter)
Big Scopes are Cool

peter_4059 is offline
 
Join Date: Jun 2007
Location: SE Tasmania
Posts: 4,532
Just an update on this. A fellow IIS member reached out over the weekend and has provided some changes to my code to deal with the error. I've got them implemented and running tonight and so far no errors.

I never would have worked out how to fix this without help. What an amazing community!

Thanks Raki.
Reply With Quote
  #3  
Old 10-03-2020, 10:51 AM
niharika
Registered User

niharika is offline
 
Join Date: Jun 2012
Location: melbourne
Posts: 216
Good to hear its working Peter. All the best with the project.


Quote:
Originally Posted by peter_4059 View Post
Just an update on this. A fellow IIS member reached out over the weekend and has provided some changes to my code to deal with the error. I've got them implemented and running tonight and so far no errors.

I never would have worked out how to fix this without help. What an amazing community!

Thanks Raki.
Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time is now 02:49 PM.

Powered by vBulletin Version 3.8.7 | Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Advertisement
Bintel
Advertisement
Testar
Advertisement