MessageAvailable event is not triggered

The free CAN Software API (Application Programming Interface) for Windows®
Locked
Gyula.L
Posts: 15
Joined: Fri 18. Oct 2024, 13:05

MessageAvailable event is not triggered

Post by Gyula.L » Fri 10. Jan 2025, 13:46

Hello,

I made a very simple program, which sends a CAN message, and I want to receive it using the MessageAvailable event --> but this won't trigger at all. What is wrong?

Code: Select all

       private void btn_Start_Click(object sender, EventArgs e)
       {
           if (null != worker)
           {
               worker.Stop();
               worker = null;
           }
           worker = new Worker(PcanChannel.Usb01, Bitrate.Pcan500);
           worker.AllowEchoFrames = true; 
           worker.AllowErrorFrames = true;

           // Create Broadcast
           byte[] payload = { 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

           PcanMessage message = new PcanMessage(
               id: 0xB9,
               msgType: MessageType.Echo,
               dlc: 8,
               data: payload);
           worker.AddBroadcast(message, 100);

           // Create event handler
           worker.MessageAvailable += OnMessageAvailable;
           worker.Start();
       }

       private void OnMessageAvailable(object sender, MessageAvailableEventArgs e)
       {
           msgCounter ++;
           label1.Text = msgCounter.ToString(); 
       }
What have I missed?

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

Re: MessageAvailable event is not triggered

Post by K.Wagner » Fri 10. Jan 2025, 14:12

hello,

In order to receive echo frames, you need to configure this for the connected PCAN-Channel over the parameter AllowEchoFrames.

Since you are using the Worker class, you just need to activate the property Worker.AllowEchoFrames.

The MessageType.Echo flag is set by the API, when a message is recognized as an echo (incoming messages only). This flag is not intended to be use for outgoing messages and it is ignored by the API.
Best regards,
Keneth

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

Re: MessageAvailable event is not triggered

Post by K.Wagner » Fri 10. Jan 2025, 14:16

Hello again,

It is also important to know that an ECHO is only received when the message is physically sent. If you have only one channel connected and there is no other CAN node, that receives the message (acknowledge), you won't see any echo either.
Best regards,
Keneth

Gyula.L
Posts: 15
Joined: Fri 18. Oct 2024, 13:05

Re: MessageAvailable event is not triggered

Post by Gyula.L » Fri 10. Jan 2025, 14:39

Hi Keneth,

thanks for your reply.

I do this right after construct a worker:
worker.AllowEchoFrames = true;

I have an ECU connected to the PCAN box, and I trace the CAN communication with another hardware (NI-XNET), where I see the sent frames by Peak and also the ones sent by the ECU. But the event is not fired - also not for the incoming (Rx) messages from the ECU.

Do you have a simple example?

Gyula.L
Posts: 15
Joined: Fri 18. Oct 2024, 13:05

Re: MessageAvailable event is not triggered

Post by Gyula.L » Mon 13. Jan 2025, 12:33

Hi Keneth,

the problem is solved: I re-installed the PCAN driver and now it works.

regards
Gyula

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

Re: MessageAvailable event is not triggered

Post by K.Wagner » Mon 13. Jan 2025, 13:32

Hello,

thanks for the update. Closed.
Best regards,
Keneth

Locked