CAN bus errors

I am seeing an occasional ‘missed’ CanController_MessageReceived event. When I am expecting to receive a message on the CAN bus (in response to a request) I do not see the event. If I send another request, the event gives me the data from the previous request. This is on TinyCLR 2.0 preview 5.
Running the same thing on the TinyCLR 1.0, it works perfectly. It appears there is a problem with the CAN controller.

Added issue https://github.com/ghi-electronics/TinyCLR-Libraries/issues/562

Thanks. Hopefully, a fix will be available in preview 7 ??.

What is the best way to dynamically recover from this situation ?

You are saying you are receiving all messages correctly but there event is not fired, correct? If you loop and read will you have any problems?

1 Like

Did you try in a loop? I was told that we see planning on redoing CAN in next preview so it wouldn’t make sense to try to fix now and change in 2 weeks.

It does appear to be stress related. When I receive multiple packets for a request, the event for the last packet does not happen. I slowed down the rate of making requests and that helped reduce the missing events. I also tried reducing how often I refresh the screen which helps also. However, the missing events still happen.

So there are no missing messages? You are selling all messages but sometimes you have messages pending but no events?

Might be useful to post the read code in the message received handler.

Not remember exactly but ~1500-2000 events in a second is OK. More than that may lost, even with Gpio Interrupt. If event is complex then may less.

Is there a fix in Preview 6. I didn’t see any reference to this issue in release notes

As mentioned earlier, we are adding CAN FD next release so it wouldn’t make sense to do any work in this one.

Your way did not answer our question on missing messages if you are not using events. The more info you provide the faster we can help.

Lost message and lost event are different.

So try to poll if more than 1000 msg /sec, or just count message in event, use other thread to read msg.

If parse ID, DateTime, Data, WriteLine…… all in the event then I don’t think it can handle fast enough. The example code we provided in doc just an example for simple case.

I will move as much as I can to foreground thread and do only data collection on receive event. Hope it works.

Please let us know. It makes a big difference if the problem is in missing messages or missing events.

I think it is missing events. After I recover from the missing event, I send another request. On the subsequent message received event the data read is the remainder of the previous request. The next event is from the previous message, and so on.

Can you for now then rely on continuous reading? CAN is right on the top of the list.

Any other feedback is appreciated as we are redoing CAN altogether.

There are a couple things I will try. Let you know what happens.

1 Like

Put only saving of received data in messagereceived event. Put all parsing and processing of content in foreground thread. Still missing an event

1 Like

How heavy send / receive in your system?

In normal operation, it will send 25-35 messages (requests) per second. Many of the responses are more than 8 bytes so will receive multiple messages per request

I have successfully implemented a work around where I ignore message_received events and continuously poll for data. The poll for read ends:

  1. at the receipt of the end-of-message flag in the data
    or
  2. timeout