C# example throws exception

C# example throws exception

Postby Trumo » 05 Jul 2013, 11:08

I tried running the basic example after finally downloading the DLL from the website but nothing happens if I press any button except init. When I perss init it crashes with an unhandled exception:

System.TypeInitializationException was unhandled
Message=The type initializer for '<Module>' threw an exception.
Source=CNCUSBControllerAPI
TypeName=<Module>
StackTrace:
at PlanetCNC.API.CNC.Initialize()
at CNCUSBControllerAPI_CSharp.TestForm.btnInit_Click(Object sender, EventArgs e) in C:\Kit\CNC API\CNCUSBControllerAPI_CSharp\TestForm.cs:line 31
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CNCUSBControllerAPI_CSharp.Program.Main() in C:\Kit\CNC API\CNCUSBControllerAPI_CSharp\Program.cs:line 18
InnerException:
Message=Debugger detected - this software cannot run with Debugger.
Source=CNCUSBControllerLib
StackTrace:
at A.
.()
at .cctor()
InnerException:
Trumo
 
Posts: 4
Joined: 05 Jul 2013, 10:20

Re: C# example throws exception

Postby Andrej » 05 Jul 2013, 20:17

You can not use API from debugger. Compile application and start it without debugger.
Andrej
 
Posts: 2489
Joined: 10 Jan 2012, 16:09
Controller: Many controllers

Re: C# example throws exception

Postby Trumo » 08 Jul 2013, 09:30

Ok I tried that too but things look pretty much the same. When I press init the only message I get is Initialize FAILED
Trumo
 
Posts: 4
Joined: 05 Jul 2013, 10:20

Re: C# example throws exception

Postby Andrej » 08 Jul 2013, 10:23

Do you have your .exe in same folder as CNCUSBControllerAPI.dll and CNCUSBControllerLib.dll?
Andrej
 
Posts: 2489
Joined: 10 Jan 2012, 16:09
Controller: Many controllers

Re: C# example throws exception

Postby Trumo » 08 Jul 2013, 10:28

Yes they are both in the folder
Trumo
 
Posts: 4
Joined: 05 Jul 2013, 10:20

Re: C# example throws exception

Postby Andrej » 08 Jul 2013, 10:41

And you are not running from visual studio? You doubleclicked your .exe?

You do have connected controller?
Is our software working with controller without problems?
Andrej
 
Posts: 2489
Joined: 10 Jan 2012, 16:09
Controller: Many controllers

Re: C# example throws exception

Postby Trumo » 08 Jul 2013, 10:45

Yes I have connected the controller and it runs perfectly with your CNC USB software. After testing it like this I exit CNC USB and run CNCUSBControllerAPI_CSharp.exe

In CNCUSBControllerAPI_CSharp.exe the all the buttons don't do anything other than Init. When I press init it works for a little then says initialize failed. It does the same even if the controller is not connected.
Trumo
 
Posts: 4
Joined: 05 Jul 2013, 10:20

Re: C# example throws exception

Postby Andrej » 08 Jul 2013, 11:09

And you have CNCUSBControllerAPI_CSharp.exe in same folder as CNCUSBControllerAPI.exe? This should work.

Do you use latest beta version?

Try this.
Code: Select all
Set cnc = CreateObject("PlanetCNC.API.CNC")
cnc.Initialize
MsgBox "Serial: " & clng(cnc.Serial)
MsgBox "Position: " & cnc.Position
Set cnc = Nothing

Copy this to file named "test.vbs" and double click it. This file should be in same folder where you install beta software.
Andrej
 
Posts: 2489
Joined: 10 Jan 2012, 16:09
Controller: Many controllers

Re: C# example throws exception

Postby paulrengifo » 29 Sep 2014, 21:34

Greetings friends. can you help me with two questions please /
Because I get 1 license = false, if cncusncontroller enables all functions with the license I have.
2.The image(Testform) below corresponds to the run direct CNCUSBControllerAPI_CSharp.exe file, but opening to change the buttons and make a custom application, there is a bug that I show in the second image(error.png)

please help me
Attachments
testform.png
testform.png (43.94 KiB) Viewed 2797 times
error.png
error.png (89.5 KiB) Viewed 2797 times
paulrengifo
 
Posts: 9
Joined: 15 May 2014, 16:03
Controller: Mk1

Re: C# example throws exception

Postby Support » 30 Sep 2014, 11:51

You cannot run your application directly in visual studio. Please read all posts that were already posted in this topic.
Support
 
Posts: 2631
Joined: 07 Apr 2014, 17:39
Controller: Many controllers

Re: C# example throws exception

Postby grovalmitch » 28 Apr 2015, 07:51

More about....C# Exception Handling

Mitch
grovalmitch
 
Posts: 1
Joined: 28 Apr 2015, 07:49
Controller: Mk1


Return to API



Who is online

Users browsing this forum: No registered users and 1 guest