Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the same CAN interface as write and read

Solved!
Go to solution

Hello.

 

Can I use the same CAN interface for read and write?

For example:

I am sending CAN frame using CAN1 to my MCU.

IF MCU acknowledged the receiving command it immediately sends echo command back and it has different ID than send command.

I was trying to use CAN1 to output frame and then reconfigure CAN1 to frame in queued and get the echo frame back.

But it seems I was always missing it. The "frame CAN" vi kept timing out.

When I used the splitter on the CAN output of my MCU I configured CAN1 for frame out and CAN2 for frame in, and I was able to catch the echo frame.

I think it takes 100ms for the echo frame to be sent out after command has been received. Does it takes longer for NI PXI-8513 to reconfigure? Can I even do it, or I have to use the splitter?

I wad hopping to use one interface for read and write. 

 

Thank you

0 Kudos
Message 1 of 9
(6,330 Views)

See my response on your other thread, but basically you need to create the input and output sessions at the beginning. Then, during your main "loop", you would perform your reads/writes as necessary. Don't keep 'reconfiguring' as that is ripe for losing data .

0 Kudos
Message 2 of 9
(6,322 Views)

Thanks. I'll try to change the program and let you know if it helped.

I actually tried to configure in the same loop two sessions for the same interface (CAN1).

I used Loopback example, just changed interface and frame inputs. But I never could read my echo frame. Data was always empty.

I'll try one more time anyway.

NI-XNET_read_and_write.png

 

0 Kudos
Message 3 of 9
(6,315 Views)

If you want to see the echoed frame, you need to enable the echo transmission property (I don't recall the exact name). You also will need a real listener on the bus as well as CAN requires two nodes. You can somewhat get around that by enabling the single-shot transmission property, but that isn't exactly perfect.

0 Kudos
Message 4 of 9
(6,313 Views)

HI,

 

It seems echo property only monitors if transmited frame was echoed. In my case echoed frame has different ID.

I'll try to call NI today and see if they can clerify it better. I will update.

 

 

0 Kudos
Message 5 of 9
(6,311 Views)
Solution
Accepted by topic author Rus_K

Ok. I misread your notion of echo. I now understand. Sorry.  The code you posted seems reasonable.

 

1) Do you have termination on or off for the session?

2) What baud rate? You may add a baud rate parameter to the property node to be explicit.

3) I don't recall the VI name, but you may add a Get Comm State after the read. This will give you some information about the bus - if any errors were detected, etc. That may be useful to help debug.

 

0 Kudos
Message 6 of 9
(6,308 Views)

HI,

 

I am not sure what is going on, but it seems Iam making stupid mistake somewhere I cannot see where.

I was able to make one vi to send and recieve frames using the same interface. No errors, works everytime.

When I put inside a main loop, it gives me an error:

 

Error -1074384742 occurred at XNET Create Session (Frame Output Queued).vi:5330001

Possible reason(s):

NI-XNET: (Hex 0xBFF6309A) The interface has already been opened with different cluster settings than the ones specified for this session. Solution: make sure that the cluster settings agree for the interface, or use a different interface.

 

Error happens inside CAN_Output_and_IN_R1, when it tries to create session for frame out.

Once error happens, I cannot write anymore even with subvi. I have to open and close labview to clear an error.

 

When Vi works I get session nmber 1 for frame in and session 2 for frame out.

When it stops workin, frame in still gets session 1, but session out alway 0.

 

I need help with it. ALredy spend too mach time on it.

THank you

0 Kudos
Message 7 of 9
(6,303 Views)

I didn't look at your code (I don't have LV installed), but make sure you don't open or close the interface (i.e., sessions) within the loop. Just do the writes and reads.

0 Kudos
Message 8 of 9
(6,299 Views)

Just figure out.

Yep, it was stupid. I have two databases that have the same signals.

I was trying to configure one iterface from two different databases.

One I set to the same databese, no more errors

0 Kudos
Message 9 of 9
(6,298 Views)