Use CAN Library in C# Project

Hello, I would like to use CAN libraries on C# project, but when I tried to use the method, I have this error "Can’t find an Entry Point ‘Imx6Can_Init’ in a Pinvoke DLL ‘TdxAllLibrariesDll.dll’.

I have no problem with a C++ project but I would like to use it in C# project. Can you help me ?

We missed CAN libs when we were building DLL.

Here you can download the updated DLL.

thanks it seems better, but I have a problem with one method “Imx6Can_Read”, it is expecting an IntPtr but I have a tCanBuf structure, I tried the method Marshal.StructureToPtr, to have an IntPtr but it throws “argument null exception”. Can you help me for this issue?

EDIT : I tried this way :
can.tCanBuf canBuf = new can.tCanBuf();
IntPtr ptrBuf = Marshal.AllocHGlobal(Marshal.SizeOf(canBuf));
Marshal.StructureToPtr(canBuf, ptrBuf, false);
but the read method returns 0 (while I’m sending data in CAN bus)

Any idea for my issue ?

If you can send us an example for sending and receiving frames in C#, it would be great, it works in C++, but in C# it does not…

Hi, I did manage to send frames, I just have a problem for reception, Can_Read method returns a positive value, but I have an IntPtr that I have to convert into tCanMsg, but the method Marshal.PtrToStructure throws an argument exception. Can you tell me how can I read this value ?
Thanks for you help.

Ok after some tests, it seems to be ok, I did not use the Marshal.PtrToStructure correctly.

Thanks again for your help.


Two things.
1: Remember to new the “data” array inside the tCanMsg structure
2: Set the dataLen in the structure.

This should work

PS: Change the data array to byte type. Easier to handle the reeived data. Char type is 16 bit. CAN operates with bytes.