Page 1 of 1

PCAN-USB receive message using EVENT, Triggered while msgs

Posted: Thu 21. Dec 2017, 15:07
by highouse
I am using PCAN-USB device under Windows 10 x64, and I want to use EVENT to get msgs.
API CAN_Initialize CAN_SetValue both succeed, but WaitForSingleObject always get trigger while no message received. Here is my code. Could you help me with it please?

Code: Select all

void* canReceiveLoop(void* arg)
{
    TPCANStatus status;
    CAN_HANDLE handle = (CAN_HANDLE)arg;
    HANDLE hEvent;
    TPCANMsg peakMsg;

    hEvent = CreateEvent(NULL, FALSE, FALSE, L"ReceiveEvent");

    status = CAN_SetValue(handle, PCAN_RECEIVE_EVENT, &hEvent, sizeof(HANDLE));
    if (status != PCAN_ERROR_OK) {
        char strMsg[256];
        CAN_GetErrorText(status, 0, strMsg);
        MSG_ERROR("%s",strMsg);
        return NULL;
    }

    while (1) {
        if ( WAIT_OBJECT_0 == WaitForSingleObject(hEvent, INFINITE)) {
			ResetEvent(hEvent);
                        CAN_Read(handle, &peakMsg, NULL)
        }
    }

    return NULL;
}
CAN_Read Bus error: an error counter reached the 'heavy'/'warning' limit

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Thu 21. Dec 2017, 16:13
by highouse
In this topic find
http://www.peak-system.com/forum/viewto ... ?f=14&t=35
a Busheavy can occur when you want to send a CAN-message and no other CAN-node is able to send a acknowlegde frame (wrong baudrate, CAN-bus not connected, no CAN-termination, a CAN-bus system with only one CAN-node etc.)
In my situation, I DO send CAN-message and there is no CAN-node online. What can I do to avoid this while I must send CAN-messages in case of no CAN-node connected.

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Thu 21. Dec 2017, 17:23
by M.Maidhof
Hi,

a CAN bus system must have at least two active CAN nodes, otherwise there will be no acknowledge bit set and the CAN sender will run into an ack error. It is like having a phone an no one to call :D

regards

Michael

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Fri 22. Dec 2017, 09:45
by highouse
M.Maidhof wrote:Hi,

a CAN bus system must have at least two active CAN nodes, otherwise there will be no acknowledge bit set and the CAN sender will run into an ack error. It is like having a phone an no one to call :D

regards

Michael
Hi,
I understand that if there is only one active node, CAN sender will run into error(bus heavy). Here is my confus:
I do really send one message in the beginning, and I got Bus Heavy ERROR, but after that I never send any message again while

Code: Select all

if ( WAIT_OBJECT_0 == WaitForSingleObject(hEvent, INFINITE)) 
get trigger over and over again, and bus heavy error sticks there. Why that happens..

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Fri 22. Dec 2017, 11:33
by K.Wagner
Hello,

first of all, you are creating an auto-reset event, so you don't need to call ResetEvent() on your handle.

The status message is generated normally one or two times after you send a message in an open CAN bus. After that, no status error are created (even if you keep sending), until a hardware reset is done.

From my point of view only two things can be happening:
  • That from your code, calls to SetEven or PulseEvent are being issued, causing in this way wrong signals.
  • That you have activated the reception of Error messages, which means, you will keep receiving error messages while the CAN controller is in error state.

Please check this behavior with our test project. For this:
  1. Start debugging the C++ project (PCANBasicExample.sln)
  2. Set a Breakpoint in the line where the event is signaled (file "PCANBasicExampleDlg.cpp", line number 3333)
  3. Start debugging...
    PCAN-BAsic - Visual Studio Sample Project
    PCAN-BAsic - Visual Studio Sample Project
    VS1.PNG (74.68 KiB) Viewed 13597 times
  4. Connect your CAN channel
  5. Change the reading mode to "Reading Using Event"
  6. Send a message by clicking the "Write" button, in the "Write Messages" area.
    PCAN-Basic Application - Connection
    PCAN-Basic Application - Connection
    PCB1.PNG (29.43 KiB) Viewed 13597 times
  7. The breakpoint should be triggered. Keep your program running, e.g. by clicking the menu command Menu/Debug/Continue
  8. The breakpoint should be triggered again. Keep your program running, e.g. by clicking the menu command Menu/Debug/Continue
  9. Now, the breakpoint should not be triggered anymore, even by clicking again the "write" button
If the behavior of this test is as expected, then you need to review your code.

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Sat 23. Dec 2017, 03:02
by highouse
pcan.png
pcan.png (47.72 KiB) Viewed 13594 times
Unfortunately, I followed your steps, but I really got the error that

Code: Select all

		if (result == WAIT_OBJECT_0)
			ReadMessages();
be triggered again and again.

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Tue 2. Jan 2018, 10:12
by K.Wagner
Hello,

actually, there is no logic reason why this breakpoint is triggered repeatedly, if there is no messages in the queue and the event being used is an auto-reset event, as is is the case in the sample project. Note that the event is signaled direct from the device driver. If you followed the test steps with the sample project well, then we are seeing here a malfunction of the driver or something is working wrong on your computer.

Please check that you have installed the latest version of the device driver and PCAN-Basic. You can see the current versions in the history site of each component: Checking the versions on your system can be done by using the PEAK-Hardware control panel applet. Note that the applet only shows PCANBasic files that are located in Windows\System32 and/or Windows\SysWOW64. If you use a PCANBasic file within your project, then you can see its version in the "Details" tab of the file properties.

By the way, which operating system do you use? platform?

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Mon 25. Feb 2019, 12:47
by afingerhut
I have exactly the same problem.

My platform is Windows 10 / 64 Bit. Im am developing in C#.
Drivers and sdk are up to date.

The CAN-Bus is not connected to a partner, so when reading by

Code: Select all

PCANBasic.Read(m_PcanHandle, out CANMsg, out CANTimeStamp);
i get the expected error result: PCAN_ERROR_BUSHEAVY. That's Ok

But why is the PCAN_RECEIVE_EVENT triggered.

The behaviour can also be reproduced in the "PcanBasicExample."

Re: PCAN-USB receive message using EVENT, Triggered while ms

Posted: Mon 25. Feb 2019, 15:44
by M.Maidhof
Hi,

when using a PCAN-USB, a status messages will be triggered every second when the device is in error state. So please check the message you will receive by the event for the status bit. It just tells you the busheavy state, due to the missing ack from another CAN node.

regards

Michael