Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

CAN loopback using RTSI programming

Hi,
 
I have 2 port CAN card from NI which can be programmed with RTSI extension. In my application, the first thing i need to do is a loopback test of the 2 ports.
 
- 2 messages with different arb id's have to be sent on the port configured as TX.
- The transmission of one message should activate the transmission of other message on the same port with the help of RTSI lines. ( RTSI 1 would be looped back with RTSI 3).
 
- These messages transmitted onb TX port should be captured on the RX port.
 
I tried to work on this but could not get the results. Can somebody help me in this regard??
 
Regards,
Siddu
 
LabView 7.0, 6.1
0 Kudos
Message 1 of 13
(6,286 Views)
Hi Siddu,

Please take a look at the following discussion forum.

http://forums.ni.com/ni/board/message?board.id=170&message.id=114442

they discuss the same thing you're working on, and that might be a good start.

Regards,
Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 2 of 13
(6,280 Views)

Hi Matt,

I have actually followed the examples and tried working on the code.

Attached is the code.

But it works only when i use the 'highlight' option and run the code.

Else it gives an error. Also in the code as you can notice, i am transmitting messages with different data but same ARB id and receiving on the other port. But actually i want to transmit 2 message with different ARB id's.

The transmission of one message should activate the transmission of second message. I tried working on that but could not get the results.

It would be of great help if you can change the code and help me out.

Regards,

Siddu

LabView 5.1, 6.1, 7.0

0 Kudos
Message 3 of 13
(6,264 Views)
Hi Siddu,

Try running the example I'm attaching. It's 2 seperate VIs that will send and receive data on those 2 ports. See if you can run these two at the same time and see the data going back and forth. If this works, it may be on how you're trying to connect your RTSI cable up. How are you connecting the RTSI up? What error message are you getting when you don't run in highlighted mode?

Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 4 of 13
(6,246 Views)
Matt,
 
Can you give the code in a lower version. I am using 6.1 and 7.0 versions.
 
Regards,
Siddu
0 Kudos
Message 5 of 13
(6,232 Views)
Here you go,

-Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 6 of 13
(6,225 Views)
Hi Siddu,

There are two restrictions that apply to cases like this that can make it pretty ‘tricky’ if the transmission needs to happen on the same CAN port:
1. You can’t configure two CAN Objects with the same arbitration ID for the same port (doesn’t matter for your use case).
2. When you configure the Network Interface to ‘Transmit a CAN Frame on RTSI Input’, (any) frames will only be transmit when there is a RTSI pulse.
That obviously leaves CAN Objects for the transmission. For the receiving side however, there are only very (very) few cases where it is useful to use CAN Objects instead of the Network Interface.

However, I’m not 100% sure, if I understand your need to (hardware) trigger the second frame. Assuming that you don’t generate any other CAN traffic, when you write both frames with ncWriteNet.vi (or ncWriteObj.vi) into the output buffer of the CAN card, the card will transmit the second frame as soon as it successfully transmitted the first frame. Thus, why the need for the RTSI trigger pulse?

BTW: The ncWrite VIs complete when LabVIEW passed the data to write to the CAN card – NOT when the card successfully transmitted the frames. If you call ncClose right after calling ncWrite, the ncClose might stop the CAN card before the remaining frame(s) are written to the bus. Therefore, it’s always a good idea to use ncWaitForState (Write_Success, 0x2) before closing handles. This could be the reason why your VI only works when ‘highlight execution’ is turned on (as there is enough time between the ncWrite and the ncClose calls).

Your VI (NI CAN Loopback Test RTSI.vi) also generates an error, but as the error cluster is not wired through, one doesn't see it right away:
1. ncConfig ("CAN1", 8, {0x80000006,0x80000007,...}, {0x00000001,0x0007A120,...})
Status: 0 (VI_SUCCESS)
2. ncConfig ("CAN0", 8, {0x80000006,0x80000007,...}, {0x00000001,0x0007A120,...})
Status: 0 (VI_SUCCESS)
3. ncConfig ("CAN0::STD5", 12, {0x8000000F,0x80000013,...}, {0x000003E8,0x00000000,...})
Status: 0 (VI_SUCCESS)
4.  ncOpenObject ("CAN0::STD5", 41419424)
Status: 0 (VI_SUCCESS)
5.  ncWrite (41419424, 8, "........")
Status: 0 (VI_SUCCESS)
6.  ncCloseObject (41419424)
Status: 0 (VI_SUCCESS)
7.  ncConfig ("CAN1::STD5", 7, {0x8000000F,0x80000013,...}, {0x00002710,0x0000000A,...})
Status: 0 (VI_SUCCESS)
8.  ncConfig ("CAN0::STD5", 12, {0x8000000F,0x80000013,...}, {0x000003E8,0x00000000,...})
Status: 0 (VI_SUCCESS)
9.  ncOpenObject ("CAN1::STD5", 41419424)
Status: 0 (VI_SUCCESS)
> 10.  ncOpenObject ("CAN0::STD5", 0)
> Status: 0xBFF6211D
> 11.  ncWaitForState (41419424, 17, 20000, 18)
> Status: 0xBFF62021
12.  ncCloseObject (41419424)
Status: 0 (VI_SUCCESS)
> 13.  ncCloseObject (0)
> Status: 0xBFF62024


The problem here is, that the second ncOpenObject (for CAN0::STD5) fails (error code: 0xBFF6211D). The reason for that is that when the port (CAN0) was never opened directly, closing the only CAN Object on that port (fucntion call #6) will stop the port and reset its configuration. Thus when you try to open an object again, the above error occurs.

-B2k
0 Kudos
Message 7 of 13
(6,112 Views)

Hi Matt,

The code attached in your previous reply works fine. But it does not configure the RTSI aspect anywhere. Actually in my setup i have a CAN card with RTSI extension and 2 of the lines 1 & 3 are connected through a jumper. So i have to check the functionality and the connections of the card before i actually run my application.

So i want to configure 2 msgs with different arb id's on the 1st port. As soon as i transmit one msg i have to send a pulse on RTSI 1. The transmission of 2nd msg should start as soon as a pulse is received on RTSI 3. And both the msgs should be captured at the other port which would be looped back externally to the Tx port.

It would be of great help if you can include this part of application in your code.

Thanks & Regards,

Siddu

0 Kudos
Message 8 of 13
(6,207 Views)
I'm going to ask the same thing Biker does, why do you want to send two messages like this? NI-CAN will automatically send the second message as soon as the first one is done. I think that using the jumper on the RTSI pins is going to complicate things in this process. Check out the information B2K posted, it's very useful and all correct.

-Matt S.

LabVIEW Integration Engineer with experience in LabVIEW Real-Time, LabVIEW FPGA, DAQ, Machine Vision, as well as C/C++. CLAD, working on CLD and CLA.
0 Kudos
Message 9 of 13
(6,203 Views)

Matt,

It is just that i want to validate my setup before i use it for the actual application. So i run this loopback kind of test which validates the CAN card and the jumper connection across the 2 RTSI lines.

Regards,

Siddu

0 Kudos
Message 10 of 13
(6,199 Views)