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: 

how to write two CAN frames at the exact same time

I have 4 USB 8473 NI CAN transievers. i want to force two of the transievers to transmitt a CAN frame at the exact same time.

 

can i do this. i have been using a common write command and tried using local variables to activate a write. however i had no success. this certainly allows the frame to be written nearly simultanously, maybe half a second delay between the two.

 

thanks for taking the time to read my query.

0 Kudos
Message 1 of 14
(5,895 Views)
You'll need to define at the same time. Because of how CAN arbitration works, you wouldn't be able to write the frames on top of each other. One of the frames will win arbitration and they will be sent serially.

If that's the behavior you want, you can use a single device.

If you're looking to "break" CAN and artificially introduce errors, you probably want to look at a product like Vector CANstress.
0 Kudos
Message 2 of 14
(5,884 Views)

thanks for the reply

 

 

i am basically using the CAN example VI's included in labview i.e. can recieve and can transmit event based as a starting pioint to building a suitable program.

 

how do i define the same time base? is this done in the CAN config block? even if i do this do you still think the arbitration would prevent errors?

 

how about if you set the arbitration id of both to be the same? in the example programs you can specifiy the arbritation id?

 

yes exactly i want to "break" CAN artifically. i want to transmitt frames onto a network and see what will happen. i would like to transmitt two frame at the exact sae time also

 

thanks

brendan

 

 

 

 

 

 

0 Kudos
Message 3 of 14
(5,879 Views)

I think JGruenberg missed the fact that you have multiple hardware.  His statement is correct that you can't send two frames at the "same time" on a single piece or hardware.  The tranceiver hardware has priority built in and won't allow it.

 

But theoretically you can send two messages on two different tranceivers at the "same time".  The problem is synchronization.  Ther 8473 has no synchronization hardware.  The 8473s does, but I've never used it and have no idea what it is used for.

 

If you want to help make a write on two pieces of hardware with as little delay as possible, I'd suggest opening a reference to all 4 pieces of hardware at the start, then in a for loop set to be ran in parallel, write to each of them at the same time.  Now the request to write will go out on different cores of your CPU so the time between them should be minimal, but likely still a few milliseconds apart.

 

Attached is a VI that I haven't tested, but should demonstrate what I mean.

0 Kudos
Message 4 of 14
(5,875 Views)

Hello,

 

thank you very much. when i run the vi i notice that the four CAN0, 1, 2, 3 all index, however no signal enters the CAN write command?

 

so in this case the signals never write? im not sure why the indexed values do not pass into the write loop?

 

i have attached the vi when run throught one cycle.

 

 

 

 

0 Kudos
Message 5 of 14
(5,828 Views)

I think you might be wrong.  When parallel for loops are turned on, probes and debug tools can't function.  Because the for loops are being executed in parallel, what would probing the wire show?  One iteration?  All?  To force the for loop to execute one at a time, you can right click the for loop, choose Configure Iteration Parallelism, then check the box, "Allow Debugging" which forces the for loop to execute one after another.  You should turn this off if you really want to execute in parallel, but for debugging this needs to be on.

0 Kudos
Message 6 of 14
(5,822 Views)

yes you are correct i was able to recieve frames when i disabled the parell operation.

 

i can only seem to recieve frame when i yuse the debug mode. if i run it without debug it just gives errors. i wonder is it too fast when i dont used debug.

 

also i was expecting to see three seperate frames from each of the individuat CAN 8473s, instead i seem to only recieve one frame withe the ID 123

 

in the vi attached i have CAN0 recieving and CAN1, CAN2 and CAN3 transmitting. i would like to see three sepperate frames with ID or 1, 2 and 3 rather than a single frame if ID123?

 

thanks

brendan

 

0 Kudos
Message 7 of 14
(5,814 Views)

@bennyk wrote:

yes you are correct i was able to recieve frames when i disabled the parell operation.

 

i can only seem to recieve frame when i yuse the debug mode. if i run it without debug it just gives errors. i wonder is it too fast when i dont used debug.

 

also i was expecting to see three seperate frames from each of the individuat CAN 8473s, instead i seem to only recieve one frame withe the ID 123

 

in the vi attached i have CAN0 recieving and CAN1, CAN2 and CAN3 transmitting. i would like to see three sepperate frames with ID or 1, 2 and 3 rather than a single frame if ID123? 


It should work when parallel is enabled.  There is likely a collision but if the bus is wired correctly the message that got corrupted would retransmit.

 

Why were you expecting three separate frames for each CAN?  The for loop is set to write one frame for each of the interfaces, and it looks like you read one frame for each.  If you want to write three frames you need to invoke the write function 3 times for each interface.  You can use a single function to write multiple frames, or you can invoke the single write function in another for loop.

0 Kudos
Message 8 of 14
(5,808 Views)

i was expecting three seperate frames for each can becasue i have three physically seperate CAN devices each signified by its own CAN number i.e. 0(recieving)...1(transmitting)....2(transmitting)...3(transmitting)

 

so i would expect that each pience of hardware to transmit a frame at the exact same time and for the reciver to show the three seperate frames. the new vi seems to do this alright, but only when i have debug on. does debug slow down the program from an operating point of view? when i run it with our debug it gives an error.

 

Error -1074388985 occurred at NI-CAN Configure
Network Interface Object
(ncConfigCANNet.vi)

 

the new vi seems to be operating as i expect. i notice a couple of millisecond between the frame. i guess this is the best that can be done? i.e. it cant really simulate collisions of CAN frams.

0 Kudos
Message 9 of 14
(5,791 Views)

You state that you are transmitting on 3, and receiveing on 1.  But in your screenshot I see your read loop is opening 4 CAN ports, are you trying to open CAN0 twice?  This is a good reason to post the code, and not a screenshot of the code.  I can't see what the code is actually doing.  I suspect this is where the error is coming from, you are attemping to configure the CAN0 after CAN0 has started in another part of the code.

0 Kudos
Message 10 of 14
(5,786 Views)