Using schedule function problem

The free LIN software API (Application Programming Interface) for Windows® (only for usage with the PCAN-USB Pro CAN/LIN interface)
Post Reply
T.Lance
Posts: 3
Joined: Mon 14. Mar 2022, 09:40

Using schedule function problem

Post by T.Lance » Mon 14. Mar 2022, 10:35

Hi there, I want to send message via LIN using schedule table. I would like to know the order of using the API.
Current sequence as following. (P.S. I use the same Frame Id in each function.)
LIN_SetFrameEntry() -> LIN_SetSchedule() -> LIN_UpdateByteArray() -> LIN_StartSchedule()
But the data I sent is not updated. Am I using the wrong order?

M.Riedl
Software Development
Software Development
Posts: 34
Joined: Wed 22. Sep 2010, 13:28

Re: Using schedule function problem

Post by M.Riedl » Mon 14. Mar 2022, 11:49

Hi,

Yes, after LIN_StartSchedule you should call LIN_UpdateByteArray, not before.
Because LIN_StartSchedule initializes the data of the LIN frame.
You can also define the initialization data of the frame with the InitialData of the TLINFrameEntry.

Regards
M.Riedl

T.Lance
Posts: 3
Joined: Mon 14. Mar 2022, 09:40

Re: Using schedule function problem

Post by T.Lance » Tue 15. Mar 2022, 03:50

Thank for your answer. I am not setting the TLINFrameEntry.Flags. So when I set this parameter to FRAME_FLAG_RESPONSE_ENABLE. I can update the data.

But I have another question. I use the function LIN_SetSchedule and LIN_StartSchedule. LIN_SetSchedule as following.
I set iSlotCount = 3, but only two frame entry are scheduled. The frame ID are 00h and 12h.

Code: Select all

TLINScheduleSlot mySlot[8] ;
mySlot[0].Delay = 1000;
mySlot[0].Type = sltUnconditional ;
mySlot[0].CountResolve = 0x00;
mySlot[0].FrameId[0] = 0x12 ;
mySlot[0].FrameId[1] = 0x22 ;
mySlot[0].FrameId[2] = 0x33 ;
TLINError res = LIN_SetSchedule(client, hardware, 0, mySlot, 3);
Please help me.
Maybe you can give me the sample code to use schedule function or polling transmit data via LIN to device.

M.Riedl
Software Development
Software Development
Posts: 34
Joined: Wed 22. Sep 2010, 13:28

Re: Using schedule function problem

Post by M.Riedl » Tue 15. Mar 2022, 16:05

Hi,

I think you misunderstood something.
The slot entry's FrameId array property can only be fully used if the Type is set to sltSporadic.
If you decide to use normal unconditional slots (Type = sltUnconditional), you can only use the first element of the FrameId array.
Before that you need to configure the corresponding frame IDs (0x11, 0x22, 0x33) with the LIN_SetFrameEntry function.

Here a C# sample code:

Code: Select all

var entry = new Peak.Lin.TLINFrameEntry();

// Get and configure frame ID 0x12
entry.FrameId = 0x12;
if (Peak.Lin.PLinApi.GetFrameEntry(hHw, ref entry) == Peak.Lin.TLINError.errOK)
{
    entry.Direction = Peak.Lin.TLINDirection.dirPublisher;
    entry.ChecksumType = Peak.Lin.TLINChecksumType.cstEnhanced;
    entry.Length = 2;
    entry.Flags = Peak.Lin.PLinApi.FRAME_FLAG_RESPONSE_ENABLE;
    //Optionally set the initialization data
    //entry.InitialData[0] = 0x01;
    //entry.InitialData[1] = 0x02;
    Peak.Lin.PLinApi.SetFrameEntry(hClient, hHw, ref entry);
}
// Repeat it for ID 0x22
entry.FrameId = 0x22;
if (Peak.Lin.PLinApi.GetFrameEntry(hHw, ref entry) == Peak.Lin.TLINError.errOK)
{
    // Here configure ID 0x22
}
// Repeat it for ID 0x33
entry.FrameId = 0x33;
if (Peak.Lin.PLinApi.GetFrameEntry(hHw, ref entry) == Peak.Lin.TLINError.errOK)
{
    // Here configure ID 0x33
}

var slots = new Peak.Lin.TLINScheduleSlot[3];

// Configure first slot
slots[0] = new Peak.Lin.TLINScheduleSlot();
slots[0].Type = Peak.Lin.TLINSlotType.sltUnconditional;
slots[0].FrameId = new byte[8];
slots[0].FrameId[0] = 0x12;
slots[0].Delay = 1000;
slots[0].CountResolve = 0;

// Configure second slot
slots[1] = new Peak.Lin.TLINScheduleSlot();
slots[1].Type = Peak.Lin.TLINSlotType.sltUnconditional;
slots[1].FrameId = new byte[8];
slots[1].FrameId[0] = 0x22;
// Here configure the rest

// Configure third slot
slots[2] = new Peak.Lin.TLINScheduleSlot();
slots[2].Type = Peak.Lin.TLINSlotType.sltUnconditional;
slots[2].FrameId = new byte[8];
slots[2].FrameId[0] = 0x33;
// Here configure the rest

if (Peak.Lin.PLinApi.SetSchedule(hClient, hHw, 0, slots, 3) == Peak.Lin.TLINError.errOK)
    Peak.Lin.PLinApi.StartSchedule(hClient, hHw, 0);

For further information see also the PLIN API Documentation and the following topics:
  • Getting Started -> Configuring the Hardware -> Programming a LIN Advanced-Master
  • Getting Started -> The LIN Frame Entry
  • Getting Started -> The LIN Schedule Slot
Regards
M.Riedl

T.Lance
Posts: 3
Joined: Mon 14. Mar 2022, 09:40

Re: Using schedule function problem

Post by T.Lance » Wed 16. Mar 2022, 03:09

Thank you M.Riedl. As you said, I misunderstood about slot entry. It is working now.
Thank you for your kind help.

Post Reply