C & C++ examples for API [v0.3]

C & C++ examples for API [v0.3]

Postby Moonglow » 11 Jul 2013, 13:36

Hello,
It is a C wrapper over PlanetCNC API.

api_c_wrapper - project for freeware Pelles C compiler.
api_c_wrapper.zip
Pelles C project
(5.38 KiB) Downloaded 467 times

vs2012_stub - project for VisualStudio 2012 from M$
vs2012_stub.zip
VisualStudio 2012 project
(6.8 KiB) Downloaded 481 times


This project show how you can use this wrapper... it works fine but not fully tested. If you have any questions feel free to ask :idea:

*update 18.07.2013
C++ GUI example ( with events, using #import derective, clean as possible )
screeenshot.png
C++ GUI example screenshot
screeenshot.png (9.94 KiB) Viewed 6721 times

Source code ( Release dir has builded version ):
cncapi_wrapper_cpp.zip
C++ GUI example ( build on VisualStudio 2012 )
(65.91 KiB) Downloaded 487 times


*update 20.07.2013
api_c_wrapper_v0.3.zip
Updated version of C wrapper, now with events!
(28.18 KiB) Downloaded 383 times
( you can control axis with W, A, S, D keys, Q - exit, project files for Pelles C compiler include, prebuilded version too )

p.s: do not forget to free allocated strings and objects if they not used anymore :idea:

FAQ
Q: I get message "com onject was not corectly registred"
A: In this case you must registry your COM object manualy ( go to CNCUSBControllerAPI.dll dir ):
Code: Select all
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe CNCUSBControllerAPI.dll /codebase

Q: Hm... events not working ( position not updated in my samples )
A: I have two solutions for it...
1. You can simply change:
Code: Select all
CoInitialize( NULL  );

to this:
Code: Select all
CoInitializeEx( NULL, COINIT_MULTITHREADED );

And all be OK.... BUT... you will get message about failed to register DragDrop event... it is becourse you mix MTA model with STA, but you can ignore it and use.
2. Better way it is use universal marshaller oleaut32.dll, and you need add ProxyStubClsid entries to each IID to registry ( use my registry file for that ):
fix_entries.reg.zip
FIX OnUpdate event
(506 Bytes) Downloaded 287 times
Moonglow
 
Posts: 104
Joined: 11 Jan 2012, 04:45
Controller: Many controllers

Re: C & C++ examples for API [v0.3]

Postby TegoKelly » 31 Mar 2015, 14:49

Tried both executables but they crash immediately.
TegoKelly
 
Posts: 12
Joined: 23 Sep 2014, 15:26
Controller: Mk2/4

Re: C & C++ examples for API [v0.3]

Postby Moonglow » 02 Apr 2015, 10:10

TegoKelly wrote:Tried both executables but they crash immediately.


If you want to compile C++ samples you need got latest CNCUSBControllerAPI.tlb from CNC Software installation dir and replace old one from source dir, next you need to recompile project and all be OK... with C samples i just has not time to fix problem cause Andrej does not provide backward compatibility ;) He just change Interface virtual table and broke my C samples... :roll: Btw my C samples has handwritten method virtual table and C++ samples generate it from TLB, that's why you can prefer C++ version or rewrite C version methods table.

p.s: XHC Bind is also broken if someone use it )
Moonglow
 
Posts: 104
Joined: 11 Jan 2012, 04:45
Controller: Many controllers

Re: C & C++ examples for API [v0.3]

Postby TegoKelly » 03 Apr 2015, 13:13

THANK YOU !!
I haven't been able to get the C# code to compile but I'd prefer to work in c or C++ anyway.
TegoKelly
 
Posts: 12
Joined: 23 Sep 2014, 15:26
Controller: Mk2/4

Re: C & C++ examples for API [v0.3]

Postby meir57 » 31 Aug 2015, 10:59

" Q: I get message "com onject was not corectly registred"
A: In this case you must registry your COM object manualy ( go to CNCUSBControllerAPI.dll dir ):
CODE: SELECT ALL
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe CNCUSBControllerAPI.dll /codebase"


I did the same as written above, when I create instant I got the same problem.the component did not found
what to do ? any advise ? thanks
meir57
 
Posts: 2
Joined: 13 Aug 2015, 10:05
Controller: Mk3

Re: C & C++ examples for API [v0.3]

Postby Moonglow » 02 Sep 2015, 14:53

Please provide me output of that command. By default all must be OK.
Moonglow
 
Posts: 104
Joined: 11 Jan 2012, 04:45
Controller: Many controllers

Re: C & C++ examples for API [v0.3]

Postby ddelarze » 14 Apr 2016, 17:50

I am using C++ code for console application based on your sample.
But after a cuple off GetPosition, the retrieved coodrs are same.
When i use Events for know coords (using a console application) only a few event are triggered, after 5 o 6 stops.
ddelarze
 
Posts: 3
Joined: 14 Apr 2016, 17:45

Re: C & C++ examples for API [v0.3]

Postby ddelarze » 14 Apr 2016, 19:00

I am doing a console C++ application, i based my code in samples.
After a few get_Position the API show same values.
I also try whit Event sample, but after 4-6 event triggered it s stop to active OnUpdate Event.
ddelarze
 
Posts: 3
Joined: 14 Apr 2016, 17:45


Return to API



Who is online

Users browsing this forum: No registered users and 1 guest