LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I most simply display and log CAN and analog signals to the same file (~5 to 20Hz)?

I am using a NI-CAN card to read can signals from a machine. At the same time I am reading analog signals from a 3rd party USB device.

 

I can use this basic loop (see attached block diagram - "CAN Init Start to CAN Read to CAN Clear) to get my CAN signals with no problem. They come as a waveform, so I can easily display them in a waveform chart and Write to LVM File. However, my analog signals come from the USB device as individual DBL numbers. If I try to combine the waveform and the analog signals to an array and write it to file I lose the waveform and timing data.

 

My speed needs are not great and synchronization is not critical (.05 seconds is close enough). Should I just write each signal to local variables and form an array that gets written to a spreadsheet file? I also need to display the values on screen as they are acquired.

 

 

0 Kudos
Message 1 of 13
(3,734 Views)

MainDish-

 

            Since the USB device will be aquiring one sample every time, you can build an array using Build Array.vi and shift registers. Now merging the signals is the trickey part. The CAN device passes in data with time stamp info attached and this is how the graphs get their info. I don't know what the USB device passes in header wise, but I would try just merging them together or just displaying them on the same graph before you started scratching your head too much. Check out the attached picture to understand what I meant with the shift registers and build array. Good luck!!

 

0 Kudos
Message 2 of 13
(3,698 Views)

MainDish-

 

               Was my post helpful or are you still working on it? An update would be helpful. Thanks!!

0 Kudos
Message 3 of 13
(3,674 Views)

Actually I'm still struggling with it. I'm not sure what you were trying to show me in terms of using the shift registers to build an array with single analog samples.

 

Here's where I'm at now (see attached file). I haven't tried it just yet. I changed the polymorphic CAN Read VI to take one sample per channel per iteration instead of giving me a waveform. I then take my analog signal (TIn) and add it to that array.

The "Write to Meas File" express VI is in a conditional loop so that I can view the acquisition and then optionally log to file when I flip the toggle switch. I intend to control the approximate frequency of the acquisition by controlling a simple delay timer in the loop.

 

Here's where I suspect that I will have issues with this:

-Express VIs seem to throw everything haywire when they are called every loop

-I'm concerned about the data type conversion going into the Signals input on the "Write to Meas File"

 

 I know there has got to be a better way in general but I am under a real time crunch to get a working app, even 5Hz updates would be okay here.

 

I have a couple of problems that I know I will keep encountering in the future:

A) bringing data together from several types and several devices

B) Acquiring/display data while selectively and efficiently logging to file for an indeterminate number of sample without restarting the application

I often have an application where I need to create a virtual dashboard, or some kind of screen with gauges, readouts, and/or scrolling graphs. That's usually easy enough, but I then also need to be able to selectively log to file. Ideally the logging rate would not have to be the same as the screen update rate (I've never had parallel loops working quite right). Even more ideally the logging could be buffered so that a file is not constantly being accessed and slowing everything down.

 

I appreciate your help so far. Thanks for your interest!

0 Kudos
Message 4 of 13
(3,665 Views)

Actually I'm still struggling with it. I'm not sure what you were trying to show me in terms of using the shift registers to build an array with single analog samples.

 

Here's where I'm at now (see attached file). I haven't tried it just yet. I changed the polymorphic CAN Read VI to take one sample per channel per iteration instead of giving me a waveform. I then take my analog signal (TIn) and add it to that array.

The "Write to Meas File" express VI is in a conditional loop so that I can view the acquisition and then optionally log to file when I flip the toggle switch. I intend to control the approximate frequency of the acquisition by controlling a simple delay timer in the loop.

 

Here's where I suspect that I will have issues with this:

-Express VIs seem to throw everything haywire when they are called every loop

-I'm concerned about the data type conversion going into the Signals input on the "Write to Meas File"

 

 I know there has got to be a better way in general but I am under a real time crunch to get a working app, even 5Hz updates would be okay here.

 

I have a couple of problems that I know I will keep encountering in the future:

A) bringing data together from several types and several devices

B) Acquiring/display data while selectively and efficiently logging to file for an indeterminate number of sample without restarting the application

I often have an application where I need to create a virtual dashboard, or some kind of screen with gauges, readouts, and/or scrolling graphs. That's usually easy enough, but I then also need to be able to selectively log to file. Ideally the logging rate would not have to be the same as the screen update rate (I've never had parallel loops working quite right). Even more ideally the logging could be buffered so that a file is not constantly being accessed and slowing everything down.

 

I appreciate your help so far. Thanks for your interest!

0 Kudos
Message 5 of 13
(3,665 Views)

UPDATE:

 

The application seems to run with no problem and the loop time is within 1ms of my command. However the waveform graph only plots 1 line. (see attached jpg) Should I be using a waveform chart instead?

 

Additionally the output file is not looking right (attached txt). Rather than writing 1 header, 1 comment, then putting the signals in columns with a timestamp in the first column (this was the output when I simply wired a waveform of the CAN signals into the Write to Meas File); it is now putting the data in rows with reapeating 0-18 in the first column (19 signals) and rewriting the comment every time.

 

Any thoughts?

Download All
0 Kudos
Message 6 of 13
(3,661 Views)

MainDish-

 

              I was trying to show you the shift registers and build array to build your USB (you said it was coming in one sample at a time) data together. Because graphs don't have "internal memory" you will need an array to see all of your values at once. The graph rebuilds the view everytime so data that is not built into an array (think of it as a large fiel) and then passed in then you will only see the last value plotted. To view more than one plot, merge the signals using Merge Signals.vi and then pass in the data to the graph. I assume you are using the Write to Measurement File.vi for your file (?). If this is the case then you should have, One Header Only selected to write the comment at the beginning and One Column Only for your X Value Columns. If this is already selected and you are still getting this .txt, then it is something with the way the data passes in (LabVIEW automatically handles the timestamps and if they are bad then we will have to overwrite them). Post your code and a sample of data to read so maybe we might be able to help you more. Thanks!!

0 Kudos
Message 7 of 13
(3,650 Views)

MainDish-

 

            I told you the wrong thing about viewing multiple plots. I thought you wanted to view the signals as one signal which would be the Merge Signals.VI. To view multiple plots on the same graph you have to build a 2D array that shares the same x value element. This is done by passing in the x value into the first element of Build Array.VI and passes in the y value sets into each subsequent elements. I have attached an example showing how to do this. I use Convert From Dynamic Data.VI to convert the dynamic data output of the Simulate Signal to a 1D array single channel. When I pass this into the build array, the build array automatically breaks up the x and y values and treats the x values as the first element. Because this is done, I can then pass the 1D array of doubles from the random number generator into the second element no problem. When you view the graph you can see both plots are shown and they share the x axis. I built the VI in LabVIEW 8.0. Check it out and let me know if this is what you had in mind or if I am completely off. Cheers!!

0 Kudos
Message 8 of 13
(3,641 Views)

I somewhat understand the shift register usage here to build an array, however is there an array being stored in memory that keeps growing indefinitely?

 

 

I tried a few things in this one - perhaps too many things. For now I've left the waveform chart disconnected as I am still struggling with the log files.

 

-I used the shift register to build an array of EGT values (temperature from TIn.vi). I should then be able to combine that with my array of CAN signals to display on the chart, right? Shouldn't I also have to build an array of consecutive CAN signals?

 

-I have a 1D array display to show the current values on screen. I add my EGT value to the end of the CAN values and display it there. If I use the previously constructed EGT array the combination is 2D and cannot display, so I have to add only a single value.

 

-my logfile is still listing the signals as rows, not columns, with a new header each time. I did have the "Write to Meas File" function setup as you said. I am now trying to build an array of values for time elapsed from the moment the "Log" switch is flipped. If I used that as the first element in a combination with the data array will the "Write" function interpret that properly as the X values?

 

Thanks again.

0 Kudos
Message 9 of 13
(3,631 Views)

MainDish-

 

             You are trying to combing the 1 sample from the CAN with the 1 sample of temp. which results in a 1D array. A 1D array will just graph as one plot. What you need to do is build a 1D array of temp data (which you are doing at the top) and a 1D array of CAN data (which is being done for you but since you are only sampling one at a time this array is useless). If you only want to sample one at a time then build up an array like you are with the temp. values and shift registers. If you use build array now to combine both 1D arrays then you will have a 2D array (put the CAN array as the first element in the build array to use the time values) that will graph both plots when passed into a graph. It is also not good LabVIEW coding practice to have express VIs (Write to Measurement File) contained within a while loop (bad memory usage). Instead use you LOG boolean control to stop the while loop (If true then stop loop kind of thing), then wire your two 1D arrays to a build array to get all the values that have been built up to a 2D array. You can now use the Transpose 2D array to switch the rows and columns (a problem you are having) and pass the resulting data into your Write to Measurement File. I think you will find this overall a more efficient way of doing things. I have added some pictures showing you a trick on how to make Build Array and shift registers work a little better (I show you the area where I talking about and the better way of adding a build array to get a 1D array first). Can you also post the TIn.VI? I don't have it some I can't see this one VI. Hope this helps!!

0 Kudos
Message 10 of 13
(3,616 Views)