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: 

Write and read CAN frames from same VI

Solved!
Go to solution

Hi All,

 

I am trying to write some frames on CAN1 interface and read on CAN2 interface but it does not read all the frames when I try to write and read from the same vi. Does anybody know if XNET allows to write and read form the same vi?

 

However if I separate the write and read and run 2 vi's asynchronously (like in the examples) I can read all the frames I write.

 

See the attachment of the code below

 

 

0 Kudos
Message 1 of 4
(2,718 Views)

Hi jkerrigan12,

 

You should be able to write and read from the same VI.  For you implementation however, I would recommend building from the "CAN Frame Input Stream" and "CAN Frame Output Stream" examples.  These can be found in LabVIEW's example finder. 

Trevor H.
Technical Support Engineer
National Instruments
0 Kudos
Message 2 of 4
(2,683 Views)

So I did some more testing and to get it to work I need to first start the session manually, then add a small delay after the session starts, and then read the frames. Otherwise I need to read 2 times in order to read all the frames that were written (I am assuming based on this behavior that the session needs time to start up).

 

Is it normal that the session needs time to start before I should begin to read from the bus?

 

 

0 Kudos
Message 3 of 4
(2,676 Views)
Solution
Accepted by topic author jkerrigan12

Check out the "CAN Frame Input Output Same Port.vi" shipping example for guidance on how to read and write from the same port. It is located in the the Hardware I/O -> CAN -> NI-XNET -> Intro to sessions -> Multiple Sessions folder. 

 

You shouldn't need a delay between session creation and session start. For CAN and LIN, the session state model transitions the interface into the running state almost instantly when the Read or Write VIs are called. Can you post a updated picture or snippet of your current code?

Jeff L
National Instruments
0 Kudos
Message 4 of 4
(2,651 Views)