delay in receive event

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
yesweCAN
Posts: 14
Joined: Tue 25. Jul 2023, 14:34

delay in receive event

Post by yesweCAN » Mon 7. Aug 2023, 18:24

Hi,
In the CAN reading thread there is a loop which is waiting the Receive event.
I don't understand why there is a delay in the event ? , does it means that the event is generated only when the delay is passed ?

Thanks

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: delay in receive event

Post by PEAK-Support » Tue 8. Aug 2023, 08:25

As we do not know which sample you are talking about, it is hart to say.
But using the Windows Event could be used for

- wait infinity until event is triggered
- wait for xx ms

The first version is used when you run a own simply receiving thread, the second one is using when you have a high layer protocol where you have "time outs"
For example sending a CAN Frame to the Bus - and need to get a reply from a other node within xx ms.

See PCAN-Basic Parameter Documentation page 49+
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

yesweCAN
Posts: 14
Joined: Tue 25. Jul 2023, 14:34

Re: delay in receive event

Post by yesweCAN » Tue 8. Aug 2023, 08:27

Hi,
Sorry I'm talking about the c# GUI sample that read and write to CAN.

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: delay in receive event

Post by PEAK-Support » Tue 8. Aug 2023, 09:03

OK - here the part (it is from the C++ BB sample) of the Thread:

Code: Select all

DWORD TForm1::CANReadThreadFunc()
{
    TPCANStatus stsResult;
    DWORD result, dwTemp;

    // Sets the handle of the Receive-Event.
    //
    stsResult = m_objPCANBasic->SetValue(m_PcanHandle, PCAN_RECEIVE_EVENT ,&m_hEvent, sizeof(m_hEvent));

    // If it fails, a error message is shown
    //
    if (stsResult != PCAN_ERROR_OK)
    {
        ::MessageBox(NULL, GetFormatedError(stsResult).c_str(), "Error!",MB_ICONERROR);
        return 1;
    }

    // While this mode is selected
    //
    while(rdbEvent->Checked)
    {
        //Wait for CAN Data...
        result = WaitForSingleObject(m_hEvent, INFINITE);

        if (result == WAIT_OBJECT_0)
            ReadMessages();
    }

    // Resets the Event-handle configuration
    //
    dwTemp = 0;
    m_objPCANBasic->SetValue(m_PcanHandle, PCAN_RECEIVE_EVENT ,&dwTemp, sizeof(dwTemp));

    return 0;
As you could see - it use the "Infinite" Value

Code: Select all

 //Wait for CAN Data...
         result = WaitForSingleObject(m_hEvent, INFINITE);
In C# /.Net it s handles like this

Code: Select all

while (rdbEvent.Checked)
            {
                // Waiting for Receive-Event
                // 
                if (m_ReceiveEvent.WaitOne(50))
                    // Process Receive-Event using .NET Invoke function
                    // in order to interact with Winforms UI (calling the 
                    // function ReadMessages)
                    // 
                    this.Invoke(m_ReadDelegate);
            }            
The Receive Event is here encapsulate in the -Net Framework (Namespace: System.Threading) see Windows .NET Specification for more info.
We need to use the Invoke function to interact with the User Interface.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

yesweCAN
Posts: 14
Joined: Tue 25. Jul 2023, 14:34

Re: delay in receive event

Post by yesweCAN » Tue 8. Aug 2023, 09:51

What is the meaning of the 50 in the c# sample.
I understand that the loop wait 50ms between each reading.

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: delay in receive event

Post by PEAK-Support » Tue 8. Aug 2023, 09:58

No it wait max. 50 ms if no Event comes up. But if a Event comes in within this 50ms it goes directly to the Read Function, if no event is triggered it calls every 50ms the read function
(for Status Messages etc. and to interact with the UI, not for real CAN Frames ) If CAN Messages come for example every 1 ms the Event is triggered every 1mS and do not wait the 50 ms.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

yesweCAN
Posts: 14
Joined: Tue 25. Jul 2023, 14:34

Re: delay in receive event

Post by yesweCAN » Tue 8. Aug 2023, 10:03

Ok perfect thanks for this explanation.
I love your PCI board it works perfectly, and your sample are very usefull. :D

Post Reply