Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am doing my MSc project and I am having a problem driving my CAN bus using C#.

I am using this ARM based HMI and the supported BSP source files for Windows CE 6.0 coming from the manufacturer's webpage:
http://www.technexion.com/index.php/products/hmi/th-0735w[^]

There is a CAN bus example written in C++ which I have successfully tested. I have designed my application using C# and I want to include CAN bus in my application. I don't know how to link C# with CAN bus drivers. I have several .dll files and I think the omap_can.dll is the one associated with the CAN bus drivers.

I am referring to this manual (CAN Driver section) for invoking the CAN driver because TechNexion does not provide any documentation:
http://processors.wiki.ti.com/index.php/WinCE-BSP_ARM-A8_User_Guide#CAN_Setup_and_Demo[^]

I searched how to use invoke online but I am doing something wrong in my code. The application p/invoke which generates the code does not open the omap_can.dll, so I have to type it properly on my own.

The Dependency Walker application that I used to see the contents of omap_can.dll gives the message "Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module." and allows me to view the functions (slightly different names as opposed to the ARM guide):
CAN_Close
CAN_Deinit
CAN_Init
CAN_IOControl
CAN_Open
CAN_PowerDown
CAN_PowerUp

I can also see that the omap_can.dll is linked with the cedk.dll, coredll.dll and fpcrt.dll.

I really need to understand what I am doing because I almost try random solutions.

I was attempt to call a function "CAN_Init" using C#. Here is my code (it compiles in Visual Studio 2005, but crashes when used on the device):

C#
namespace HMIShell
{
    public partial class HMIShell : Form
    {
        [DllImport("\\Storage Card\\omap_can.dll")]
        public static extern void CAN_Init(); // I am not sure about this line

        public HMIShell()
        {
            InitializeComponent(); // Automatically generated method for windows forms
            CAN_Init(); // This part fails
        }


Thank you in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900