From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems storing communications

Hello everyone,
 
 I am working on a vi, that has to be executed and stoped many times in a bigger program, that has to get CAN communications and store the in a file.
 
 The program works fine, but I have problems storing data. The problem is that everytime the program is executed the receive buffer remains filled... and everytime the program is ran again I got not only new messages, but the old ones too... I that's quite annoying! Smiley Mad
 
 The program runs with nc frames api.
 
 I feel like this may be a very simple question, but I have taken quite a look to this forum before, and I haven't find the answer...
 
 Thank you!
 
 LS
0 Kudos
Message 1 of 3
(3,364 Views)
Hi LS,

There are a couple of ways to avoid the old frames. In your sub VI call ncAction(Reset) on the network interface handle before you perform any reading or writing. The ncAction(Reset) will perform the stop first (and thus clear the read buffers) and then clear all entries from the write queues.
While this should work, a better approach would be to configure the CAN ports in the program that calls your sub VI and have the sub VI start the network interface through ncAction(Start) perform any reading or writing. Once the sub VI is done with the CAN communication, call ncAction(Stop) to prevent any CAN communication. That way, your VI does not receive any frames when it’s not active.

Hope this helps a bit.
-B2k
0 Kudos
Message 2 of 3
(3,355 Views)

Help a bit? It has helped a lot!! Thank you!

I've added a ncAction(start) just before polling the buffer, and a ncAction(Reset) just after the communications desired have been stored, and that seems to work!

And as the ancient proberb says: "if it works, don't touch it". Smiley Happy

So thank you biker2000!

LS

0 Kudos
Message 3 of 3
(3,346 Views)