LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I update CAN messages being transmitted as a periodic waveform?

I am using NI-CAN 1.5 to transmit CAN messages with a CAN Object using the "Transmit Periodic Waveform" communication type. The CAN card I am using is a dual port PXI-8461.

I wish to update the waveform message(s) but am running into problems. I configure the CAN Object with a write buffer size of 2 and then start transmitting 2 messages with one message going out every 500ms. These 2 messages are correctly getting placed on the bus. To update the messages, I successfully stop the CAN Object and attempt to write new data into the write buffer. This is where I am running into problems. The ncWrite VI is failing with an error of 0xBFF62008 (Write Queue Overflow).


Upon fur
ther inspection, I noticed that when I stopped the Object and there was only 1 of 2 messages pending, I could successfully write one time; however, the second write would fail with the same error. If 2 messages were pending, neither write would be successful. I need to be able to update both messages. I thought maybe I could use the ncWait VI to wait for the write queue to empty and then write in 2 new messages; however, this will not work since the ncWait VI never returns before a timeout occurs in "Transmit Periodic Waveform" communication type. Either 2 or 1 messages are always pending so it never sees that the card is ready for new data.


I looked in the Programmer's Reference Manual, and this is the procedure recommended. (A bit different, but I tried it and came up with the same results.) The Reference Manual claims ncWrite replaces the oldest data in the queue on page 3-30, but on page 2-40 it says ncWrite returns an error when called on a full queue.


Does anyone
see anything that I'm doing wrong or have an alternate way to accomplish what I want (note that periodic transmit will not work for my application)? Thanks for your help.
0 Kudos
Message 1 of 3
(2,401 Views)
The "Transmit Periodic Waveform" section (pg 3-30) of the NI-CAN Programmer's Reference states, "Use this configuration to transmit a fixed sequence of CAN data frames over and over, one CAN data frame every period."

The words "fixed sequence" denote that it was not intended to change as the program runs. I appolgize if this was not clear. Any suggestions for improvement to the documentation can be emailed to support@ni.com.


If those two data sets do not change at run-time, they could be merged together. For example, make the buffer the size of both data sets added together. Start by Writing the first element of set one, then the first element of set two, then the second element of set one, then the second element of set two, etc.


Randy Solomonson
Ap
plication Engineer
National Instruments
0 Kudos
Message 2 of 3
(2,401 Views)
If you need to update the data of your waveform, the basic Transmit Periodic type is preferable to Transmit Periodic Waveform. As Randy pointed out, the Transmit Periodic Waveform is limited, in that it doesn't really allow updates.
The attached LLB shows a method that ensures that each "point" of the waveform is transmitted, yet allows the waveform to be updated. It includes a Tranmit and Receive VI, so you can try it port-to-port.
The idea of this example is to use the Write Queue to maximum advantage. It keeps writing data points to the write queue, and when it detects overflow (queue full), it simply re-submits the point. Since this technique does not wait on any CAN states, it buys time for other code (such as another CAN Object, DAQ code, and
so on).
In your case, I'd recommend 2 CAN Objects with Transmit Periodic type, each 500ms each. Each loop, you can write 1 point for each CAN Object, then use a LabVIEW Wait of about 400ms (or do other processing). You won't even need to look for overflow. This should ensure that you always submit a new point before it is transmitted to the bus.
0 Kudos
Message 3 of 3
(2,401 Views)