PCAN-USB receive message using EVENT, Triggered while msgs

USB to CAN Interface
Post Reply
highouse
Posts: 5
Joined: Fri 15. Dec 2017, 09:39

PCAN-USB receive message using EVENT, Triggered while msgs

Post by highouse » Thu 21. Dec 2017, 15:07

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

highouse
Posts: 5
Joined: Fri 15. Dec 2017, 09:39

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

Post by highouse » Thu 21. Dec 2017, 16:13

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.
Last edited by highouse on Fri 22. Dec 2017, 02:52, edited 1 time in total.

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

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

Post by M.Maidhof » Thu 21. Dec 2017, 17:23

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

highouse
Posts: 5
Joined: Fri 15. Dec 2017, 09:39

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

Post by highouse » Fri 22. Dec 2017, 09:45

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..

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

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

Post by K.Wagner » Fri 22. Dec 2017, 11:33

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 13575 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 13575 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.
Best regards,
Keneth

highouse
Posts: 5
Joined: Fri 15. Dec 2017, 09:39

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

Post by highouse » Sat 23. Dec 2017, 03:02

pcan.png
pcan.png (47.72 KiB) Viewed 13572 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.

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

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

Post by K.Wagner » Tue 2. Jan 2018, 10:12

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?
Best regards,
Keneth

afingerhut
Posts: 1
Joined: Mon 25. Feb 2019, 12:26

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

Post by afingerhut » Mon 25. Feb 2019, 12:47

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."

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

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

Post by M.Maidhof » Mon 25. Feb 2019, 15:44

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

Post Reply