Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Does NI-CAN (USB-8473) support programming in C#

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

Message 1 of 8
(8,538 Views)

Serge,

 

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

 

Cheers,

0 Kudos
Message 2 of 8
(8,520 Views)

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.

0 Kudos
Message 3 of 8
(8,507 Views)

Hi Serge,

 

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

 

Cheers,

0 Kudos
Message 4 of 8
(8,491 Views)

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

0 Kudos
Message 5 of 8
(8,455 Views)

Thanks so much for this. Is there a way to save your project to VS 2005 and repost?

 

Thanks again.

0 Kudos
Message 6 of 8
(8,322 Views)

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

 

BR

Eugen Wiebe

 

 

-------------------------------------------------------------------
Eugen Wiebe
Bernstein AG
CLAD - Certified LabView Associate Developer
0 Kudos
Message 7 of 8
(7,886 Views)
Hello, Thanks for the TestCAN1. I am able to Config,Open,Write but unable to Read the transmitted message.Instead,am getting other messages.Kindly guide me regarding this. Thanks in Advance
0 Kudos
Message 8 of 8
(3,052 Views)