01-18-2013 09:16 AM
Hi there, I am developing software in C#, which supposed to test electronic devices (production of electronic manufacturing company), to ensure quality and functionality.
My system consist of many NI devices, mainly Digital and Analog I/O, of them belong to DAQmx-group, and support programming in C#.
Recently I added to the system CAN device USB-8473, which belong to NI-CAN-group (using my own terminology).
Question is: Does NI-CAN provide support (classes, libraries, dll's, etc) for programming in C#?
Thank you in advance
01-21-2013 05:38 PM
Please see section starting on pg 5-1: http://www.ni.com/pdf/manuals/370289k.pdf. This will describe all the languages that are supported with the NI CAN drivers that will be used to control the 8473. It also mentions that other languages can call the nican.dll
01-22-2013 09:15 AM
Hi Chris, thanks for fast reply,
yes, sure, I read this section of manual, just was thinking, this manual is from mid-2010, and meanwhile updated version of NI-CAN might be available, compatible with last generation of .NET, but it seems it is not.
One more question: your Nican.dll is C++, unmanaged code library. To use it in .NET, particularly in C#, there must be some code which describe functions and variables packaged in this dll, to provide translation (conversion) of functions and variables types, from C++ types to C# types, which would be very helpful for .NET programmers in using this dll. Something like:
[DllImport("Nican.dll" , CallingConvention = CallingConvention.Cdecl)]
public static extern int ncGetHardwareInfo(uint CardIndex, uint PortIndex, uint AttrId, uint AttrSize, ref uint Attr);
//instead of NCTYPE_STATUS _NCFUNC_ ncGetHardwareInfo(NCTYPE_UINT32 CardIndex, NCTYPE_UINT32 PortIndex, NCTYPE_ATTRID AttrId, .......
public const int NICAN_ERROR_BASE = (int)(0xBFF62000); // instead of #define NICAN_ERROR_BASE (NCTYPE_STATUS)(0xBFF62000)
public const int CanErrFunctionTimeout = (NICAN_ERROR_BASE | 0x001); // instead of #define CanErrFunctionTimeout (NICAN_ERROR_BASE | 0x001)
If you have code with this kind of conversion, would be very nice to have a link to that.
Thank you for your help.
01-23-2013 09:34 AM
We do not have a wrapper written, but it looks like others in the community have written some: http://forums.ni.com/t5/Automotive-and-Embedded-Networks/C-Wrapper-for-NI-CAN/m-p/975776 and https://decibel.ni.com/content/docs/DOC-20307.
Also, this looks like it might be useful for automating the process of creating a wrapper: http://digital.ni.com/public.nsf/allkb/27177DA13C6ED0AE86257362006A68B0
01-28-2013 04:15 PM
Hi there, spent few days working on C# wrapper and now share it with you guys.
So, attached project is NI-CAN wrapper in C#, Visual Studio 2010, for Frame API only, device: USB-8473(no sync)
Have a nice day
02-27-2013 12:59 AM
Thanks so much for this. Is there a way to save your project to VS 2005 and repost?
06-21-2013 07:09 AM - edited 06-21-2013 07:33 AM
Thank you very much for the CANTest1.
I have also made some converion to C# (by this tool: Link, was little bit tricky).
(see attached file, but be careful with the arguments ! compare to TestCAN1)
The best way to develop such a C# library is:
1. Create C# dll with the interop / PInvoke code
2. Compare with LabView sample code from (e.g) "C:\Programme\National Instruments\LabVIEW 2012\examples\nican\Frame - Basic.llb"
3. develop library step by step
11-19-2016 02:29 AM