CAN message transfer gets interrupted after sometime

Hi,

We are continuously transmitting 3 CAN messages (socketCAN) at a duration of 10ms .
The CAN signals are getting received till 50s on the CANalyser.
After that the message transmission haults.

Is there a way to clear the buffer OR method to transmit it continuously without any interruption.

Thanks,
Pratosha

We are continuously transmitting 3 CAN messages (socketCAN) at a duration of 10ms .
How do you know you are attempting to transmit at every 10ms?

The CAN signals are getting received till 50s on the CANalyser.
50s (seconds) or 50 ms(milliseconds)?

Can you provide a your transmitting function, please?

Hi David,

How do you know you are attempting to transmit at every 10ms?
We have set a timer to transmit CAN messages every 10ms using pthread concept.

50s (seconds) or 50 ms(milliseconds)?Can you provide a your transmitting function, please?
The code we are using for transmission is given in the link - https://en.wikipedia.org/wiki/SocketCAN .
The 3 messages get transmitted succcessfully at a duration of 10ms for some time( roughly about 50seconds) and then it haults.

Hi, Pratosha.

if you’re using the code in https://en.wikipedia.org/wiki/SocketCAN what part of the code is in your thread?

What are you doing with the return value of the write(…) function?

" and then it haults."
What is halting? You’re application presumably, are you getting a negative number indicating an error? Please be more specific.

Please provide any information relating to the halt (output in the terminal window) and the code in your thread function, if you’re concerned about IP change the variable names.

Hi David,

I am sharing the output on the terminal - When the messages are getting transmitted it says wrote 16 bytes, when it stops the message is too many files open can be seen on the terminal. thats when we stop receiving messages on the CANalyser. I am sharing both the outputs - the CANalyser and terminal one for your reference.

The entire code seen on the link is being used. The code transmits 1 message we are transmitting 4, thats the only difference.
For the timer , the code is written within this function -
void* thread10(void* data){
time_t start = time(0);
// Print every 10 milliseconds for at most, 10000 milliseconds
while( (int)difftime(time(0), start) < 10000 )
{
// code from the link mentioned above
printf(“Wrote %d bytes\n”, nbytes);

	printf("\n\nI AM THREAD 5!");
	printf("\n\n");
	my_sleep(10);
     }

}

The image of the messages received halting at 44seconds on the CANalyser - https://imgur.com/a/7A06k
The image of the CAN terminal - wrote 16bytes( success) wrote -1bytes(halts) - https://imgur.com/a/WYZ77

As per the link https://en.wikipedia.org/wiki/SocketCAN

From your image, I am guessing you are calling the socket and bind function in your 10ms thread? If that is the case, you should only call ‘socket’ and ‘bind’ once, in an initialization function.

If you’re doing this (below), it’s wrong

void thread10(void* data){
...
if((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
		perror("Error while opening socket");
		return -1;
	}

...

if(bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		perror("Error in socket bind");
		return -2;
	}
}

Hi David,

Thank you for the response . It worked :)

Great!