Create Schedule Table with PLin-API

Windows® Compatible Software for Displaying LIN Messages
Locked
nuno
Posts: 6
Joined: Thu 30. Dec 2010, 11:20

Create Schedule Table with PLin-API

Post by nuno » Mon 14. Mar 2011, 18:03

Hello,

I'm having trouble while creating a schedule table with the PLin-API
The client is registered and the hardware is connected, but I keep getting this error:

System.Runtime.InteropServices.MarshalDirectiveException

This is my code:

Code: Select all

      Peak.Lin.TLINScheduleSlot t;
      t = new Peak.Lin.TLINScheduleSlot();
      t.Delay = 10;
      t.Type = Peak.Lin.TLINSlotType.sltUnconditional;
      t.FrameId = new Byte[8];    
      t.FrameId[0] = (byte)0x0b;
      
      Peak.Lin.PLinApi.SetSchedule(m_hClient, m_hHw, 0, ref t, 10);
      Peak.Lin.PLinApi.StartSchedule(m_hClient, m_hHw, 0);
Thanks for you help.

K.Wagner
Software Development
Software Development
Posts: 852
Joined: Wed 22. Sep 2010, 13:36

Re: Create Schedule Table with PLin-API

Post by K.Wagner » Tue 15. Mar 2011, 09:04

Hello nuno,

There is an error on the .NET declaration of the function SetSchedule. The Problem is the marshaling of the array that contains the schedule slots.

For C#, please change this definition In the PLinApi.cs file:

Code: Select all

       [DllImport("plinapi.dll", EntryPoint = "LIN_SetSchedule")]
        public static extern TLINError SetSchedule(
            HLINCLIENT hClient,
            HLINHW hHw,
            int iScheduleNumber,
            [MarshalAs(UnmanagedType.LPArray)]
            [In, Out] TLINScheduleSlot pSchedule,
            int iSlotCount);
for this other:

Code: Select all

        [DllImport("plinapi.dll", EntryPoint = "LIN_SetSchedule")]
        public static extern TLINError SetSchedule(
            HLINCLIENT hClient,
            HLINHW hHw,
            int iScheduleNumber,
            [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)]
            [In, Out]TLINScheduleSlot[] pSchedule,
            int iSlotCount);
That should solve the problem. You have now to change your code in order to give an array of slots to the function:

Code: Select all

      Peak.Lin.TLINScheduleSlot[] t;
      t = new Peak.Lin.TLINScheduleSlot[10];
      t[0].Delay = 10;
      t[0].Type = Peak.Lin.TLINSlotType.sltUnconditional;
      t[0].FrameId = new Byte[8];    
      t[0].FrameId[0] = (byte)0x0b;
      
      Peak.Lin.PLinApi.SetSchedule(m_hClient, m_hHw, 0, t, 10);
      Peak.Lin.PLinApi.StartSchedule(m_hClient, m_hHw, 0); 
Now your code should work. Thank you for reporting this.
Best regards,
Keneth

nuno
Posts: 6
Joined: Thu 30. Dec 2010, 11:20

Re: Create Schedule Table with PLin-API

Post by nuno » Tue 15. Mar 2011, 10:41

Thank you. It is working now.

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1330
Joined: Fri 10. Sep 2010, 19:34

Re: Create Schedule Table with PLin-API

Post by U.Wilhelm » Sun 28. Aug 2011, 11:25

Problem solved -- Thread closed
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

Locked