Open file at startup

Here is where you can request new features or special features.

Re: Open file at startup

Postby cahit » Sat Feb 27, 2021 4:22 am

hi dezsoe,

i have this code:

Public Sub Loop_event()
If LoopStop Then
Return
End If
LoopWorking = True

reloadcode()

If FirstRun Then
testcmdline()
' Write code here which has to be run on first cycle only...
End If
Try

Catch ex As Exception

End Try
LoopWorking = False
' Console.WriteLine("" + Convert.ToInt32("A"))
End Sub





Dim cnt As Integer = 25
Private Sub testcmdline()

If Not UC.GetLED(25) Then Return
If cnt > 0 Then
cnt -= 1
Return
End If

UC.Loadfile("file to be loaded")

FirstRun = False

End Sub



Dim cnt2 As Integer = 250
Private Sub reloadcode()

If Not UC.GetLED(25) Then Return
If cnt2 > 0 Then
cnt2 -= 1
Return
End If

UC.Callbutton(555) 'reload the same file again

End Sub





after 10 sec he has to reload a file but UCCNC crashes. what i am doing wrong?

regards
cahit
 
Posts: 73
Joined: Thu Jun 09, 2016 6:27 pm
Location: the Netherlands

Re: Open file at startup

Postby cncdrive » Sat Feb 27, 2021 5:56 am

Make sure to do the file load/reload on the UIthread.
Try to invoike the main UIthread of your form and do the file load/reload there.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Open file at startup

Postby eabrust » Sat Feb 27, 2021 4:23 pm

Hi Cahit,

Maybe instead of having your code for loading / reloading the gcode file in the startup/loop event of the main plugin class, take your load / reload code into the form.

You could put the code for loading into the forms into the 'load' or 'shown' event ('shown' event probably gets you enough delay for UCCNC to be active), and just put your 'reload' code into a button that the user presses (unless you need it to be automatic after a certain amount of time from the loading). You'd have to shuffle the 'testcmdline' code to the form class.

If you find it still fires to fast, you could add a threadsleep in there too

Code: Select all

Private Sub PluginForm_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown

'thread.sleep(1000)   ' wait for second if form opens faster than UCCNC gets ready.

testcmdline()

 End Sub


Just suggesting for how I tackle the many issues I solve by trial and error (and error and error... :) ) I'm an amateur programmer, so take my suggestions as such .

regards,
Eric
CraftyCNC: Plugins for UCCNC (and other neat stuff): http://www.craftycnc.com/plugins-for-uccnc/
eabrust
 
Posts: 357
Joined: Fri Sep 16, 2016 2:32 am
Location: Near Shirland IL, USA

Previous

Return to Feature Request

Who is online

Users browsing this forum: El Ventu and 3 guests