Can-bus imx6 dotnet c# no sample code WINCE

We are trying to get the new TdxAllLibraryDll.dll working in C#. We have opened the port and we have a message appearing on our CAN monitor software, but we are unsure how to use the CAN-Write and CAN_Read functions.

We are using the can.tCanMsg structure to build our CAN message. Our sample code is as follows:

    public static void Write(int CANPort, Char[] message, UInt32 messageID)
    {
        can.tCanMsg canMessage = new can.tCanMsg();
        canMessage.data = message;
        canMessage.dataLen = 8;
        canMessage.id = messageID;
        

        if (CANPort == 1 && canPort1 != IntPtr.Zero)
        {
            GCHandle handle1 = GCHandle.Alloc(canMessage);
            IntPtr ptrMessage = (IntPtr) handle1;

            uint ret = can.Can_Write(canPort1, ptrMessage, 1);

            handle1.Free();
        }
   }

The version of the DLL is 2.0.0.3858.

Please help.

Got the Write working with:

       public static void Write(int CANPort, Char[] message, UInt32 messageID)
       {
        can.tCanMsg canMsg = new can.tCanMsg();
        canMsg.data = message;
        canMsg.dataLen = 8;
        canMsg.id = messageID;

        IntPtr ptrBuf = Marshal.AllocHGlobal(Marshal.SizeOf(canMsg)); 
        Marshal.StructureToPtr(canMsg, ptrBuf, false);

        if (CANPort == 1 && canPort1 != IntPtr.Zero)
        {
            uint ret = can.Can_Write(canPort1, ptrBuf, 1);
        }

        if (CANPort == 2 && canPort2 != IntPtr.Zero)
        {
            uint ret = can.Can_Write(canPort2, ptrBuf, 1);
        }
        }

Dear @nickwalt
I’m glad you found the solution yourself. Don’t hesitate to get back in case you experience further issues.