Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use LabView to simultaneously transmit & receive viewed on LabView?

I need to know how I can use LabView and a PCI-CAN card to simultaneously transmit a message on the CAN bus and receive a reply from the CAN device on the bus all viewed in Labview. I tried to use one vi to transmit and another to receive at the same time but both vi's would not run at the same time. If it can be done is there a way I can have a section to input the message and a section that shows the reply on the same vi window. Please let me know and if there is an example that shows how to do this it would be great. I searched all of the examples I found and I couldn't find one that helped.
0 Kudos
Message 1 of 9
(5,033 Views)
have you looked at this example?

CAN send and receive using NICAN frames

If the link above does not work, search the NI website for "CAN send and receive using NICAN frames" It is in third party example code section.
0 Kudos
Message 2 of 9
(5,025 Views)
Thanks for the example it helps but I'm still a little troubled. I need to simultaneously transmit and receive. For example how can I send a message and then read that same message using the example transmit/receive in labview using a one port PCI-CAN card. Ideally what I am trying to set up is a diagnostic test. I need to send a specific message to the bus and read the reply from one of the known CAN nodes.
0 Kudos
Message 3 of 9
(5,014 Views)
The key concept you need to understand is the CAN buffers, the example has 2 buffers, 1 for CAN transmit, and the other for CAN receive.
That is what this example is for, it allows you to Programatically write a CAN message, then programatically call the CAN read to read a response to your CAN message USING THE SAME BUS.
So what you need to do is make a VI similar to the example that configures 1 CAN port to have BOTH a CAN receive buffer AND a transmit buffer. Then, once you use the CAN transmit VI to load a message into the transmit buffer, the PCI card will transmit it as soon as the hardware is ready. If the hardware receives a response from your device, it will put the received CAN message in the CAN receive buffer. That message response will be there in the buffer, and you read it out using a CAN read VI.
In a real CAN application the buffers are really fast, you can send and receive multiple CAN messages at 1 to 2 millisecond repetition rates, if you use the buffers. I just used a front panel switch to allow you to see what is going on in the code, your actual application will probably switch back and forth between the CAN receive and CAN transmit depending on what you need.

Hope this helps, please feel free to ask if you are confused.
0 Kudos
Message 4 of 9
(5,008 Views)
Okay I'm still a little lost. For starters I don't think I am sending any message when I use the write vi. Is there a way I can use labview to see if a message I just transmitted has successfully been sent or see the message?
0 Kudos
Message 5 of 9
(4,991 Views)
Not on the same port, the Labview code can not share the bus, it has to have exclusive access. If you have a 2 port CAN card, you could send on one, and read the message you sent, or hook other equipment up to the bus and talk to it.
0 Kudos
Message 6 of 9
(4,997 Views)
Hi Farmington

If you have a "Series 2" CAN card, you could enable the self-reception mode that echoes every successfully transmitted message back and if it went out well, you will find it in the read queue on the same port.
To enable self-reception, configure the Network Interface to NOT 'Start On Open', call ncConfig, call ncOpen, the call ncSetAttribute for the Self-Reception attribute and set it to '1'. Then call ncAction (Start) to start the port.

In general:
  • Make sure that you use the right physical layer. There are multiple physical layers for CAN (i.e. High-Speed, Low-Speed and Single-Wire) and they are not electrically compatible (different termination, etc.).
  • Make sure that you use the right baud rate that matches the baudrate of your other devices
  • Some NI CAN cards (e.g. "Series 1 low-speed") and some devices on the CAN bus require the CAN bus to carry a supply voltage on V+
-B2k
0 Kudos
Message 7 of 9
(4,977 Views)
How do I set the AttrId in the ncSetAttribute.vi so I can use the self reception? The manual only explains what it does and what the AttrValue should be but doesn't give the AttrId that corresponds to self-reception.
0 Kudos
Message 8 of 9
(4,968 Views)
Hi Farmington

Hover with your mouse over the AttrID terminal of the ncSetAttr VI, right-click and select Create » Constant. Then select the attribute from the list.

-B2k
0 Kudos
Message 9 of 9
(4,956 Views)