delay in receive event
delay in receive event
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
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
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: delay in receive event
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+
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
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: delay in receive event
Hi,
Sorry I'm talking about the c# GUI sample that read and write to CAN.
Sorry I'm talking about the c# GUI sample that read and write to CAN.
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: delay in receive event
OK - here the part (it is from the C++ BB sample) of the Thread:
As you could see - it use the "Infinite" Value
In C# /.Net it s handles like this
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.
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;
Code: Select all
//Wait for CAN Data...
result = WaitForSingleObject(m_hEvent, INFINITE);
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);
}
We need to use the Invoke function to interact with the User Interface.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: delay in receive event
What is the meaning of the 50 in the c# sample.
I understand that the loop wait 50ms between each reading.
I understand that the loop wait 50ms between each reading.
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: delay in receive event
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.
(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
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: delay in receive event
Ok perfect thanks for this explanation.
I love your PCI board it works perfectly, and your sample are very usefull.
I love your PCI board it works perfectly, and your sample are very usefull.
