Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

NI CAN - reading less no. of frames than the sensor sends

Hello,

 

I am reading a sensor data using NI CAN frame API. Sensor sends data every 10ms. It means, my software should read 100 values/second. In my software I am reading faster than the sensors sends i.e. while loop is executing every 5ms. But I am getting random no. of sensor data (always less than 100) per second.

 

please have a look at the code in the attached pic.

 

 

thanks in advance

0 Kudos
Message 1 of 10
(6,632 Views)

NICANconfig.JPGsorry, here is the attachment

0 Kudos
Message 2 of 10
(6,629 Views)

General comments:  

 

Use XNET API not NI-CAN API if your hardware supports it.

Post VIs not pictures, you wouldn't post a screenshot of text code for other languages.

 

Specific comments:

 

This is not running on real-time it is running on a non-deterministic operating system.  Good luck getting a while loop that always executes in 5ms dispite what Windows is doing.  Do you have anti-virus running?  Any other programs open?  Any other Windows services running?  Do you have a network adapter? Is Windows caching some search data? Even is a UI being displayed?  Well then you have no way of knowing what good that timing is.

 

The good news is it doesn't matter.  The CAN hardware has a buffer and if you go and read your frames once a second, then your frames will be pilled up in a queue and you read them all at once.  So increase your delay on the loop rate it doesn't matter, you're not going to miss any frames unless your buffer is full and for that to happen you'll likely need to not read CAN maybe once a minute or so.

0 Kudos
Message 3 of 10
(6,614 Views)

Hi Hoovahh,

 

I tested my software and found that I am getting 100 frames/second but when I write this data in a text file, the no. of frames written in a file are sometimes 100/second or less than 100 (random values). please have a look on attached VI

0 Kudos
Message 4 of 10
(6,599 Views)

hey I am sorry....I am trying to attach VI but th VI is not being uploaded.............don't know whats the proble.....thats why I posted image previously

0 Kudos
Message 5 of 10
(6,598 Views)

Hello swap15,

 

try to pack your vi in a .zip file

 

how do you know that you have 100 frames ?

it sounds for me as if you lost frames when you write them in a text file is that right ?

 

Regards

Andi

0 Kudos
Message 6 of 10
(6,566 Views)

Hi Andi.

 

I cant attach zip file also 😞

 

I know that the sensor is sending message every 10ms (100 messages/second).

Yes, you are right ....my software is reading all the frames but when I write in text file, I am missing some messages.

0 Kudos
Message 7 of 10
(6,518 Views)

Hello swap15,

 

programm a short vi where you only read and write the files and try to solve it step by step.

Maybe you got some effect in your programm which you don't mentioned yet.

 

Regards

 

Stefan

0 Kudos
Message 8 of 10
(6,490 Views)

Hi Britzelm,

 

I tried .......My software is reading all the messages but I  am not getting all the values when I log the data. In my data logger I dont have any loop and it executes all the time when main reading loop executes

 

 

 

regards,

swap

0 Kudos
Message 9 of 10
(6,436 Views)

Hi swap15,

 

could you post your example program ?

If you could not upload your vi send a screenshot

 

Regards,

 

Stefan

0 Kudos
Message 10 of 10
(6,430 Views)