LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

modify sample project for myRIO

Dear Forum Members,

 

I am very new to the LabVIEW and have been working (mainly through help of Google) to modify one of the sample programmes included in LabVIEW 2014 to fit my purpose. I am using myRIO device together with X-CAN module.


Essentially, the  "Sample Projects" that programme that ships with the LabVIEW 2014 works in the following fashion

 

X-CAN_for_myRIO-BlockDiagram.png

2.jpg

This sample project uses dataflow programing that executes the following three functionalities from left to right:

  1. Initialize—Re-initializes all controls and indicators to default values, sets the loop rate for the read/write loop, creates X-CAN session on MXP A connector with a CAN speed of 500 [Kbps] and intializes write/read LEDs .
  2. Read/Write CAN frames—Either reads/writes CAN Frame data from the X-CAN device and updates the on-board X-CAN LEDs. Loop is stopped when the user selects the stop button or an internal loop error occurs.
  3. Close—Closes the X-CAN session and reports any errors to the user.

When I am running this sample project, I can observe the X-CAN on-board LEDs for read/write operations. If in read mode, the raw CAN frame data will be updated in the CAN Frame, mainly the "Identifier", "Payload", and "timestamp" will keep updating according to the frequency I set.

 

I have modified it in the following fashion

 4.jpg

  1. I input the "Unbundle by name" after the "CAN Frame Read"to record the three variables that I would like to record. Can be found at the right bottom part of the above figure.
  2. I then add "Write to Measurement file" and connect those variables with it. Can be found at the right bottom part of the above figure.
  3. I have setup the "Write to Measurement file" properly. I made the file format to be "Excel", set "append to file", and the new file location set to be on my desktop. My settings can be found as below:
  4. 3.jpg
  5. Also, I have added another "Write to Measurement file2" inside the loop to record Identifier.
  6. I then finally generate a sine waveform and a third "Write to Measurement file" at the right top part. I will explain why I did that later.

After running, the raw CAN data is properly shown in Labview, the problem that I'm facing is there is no Excel file created/generated on my desktop. As we can tell, I have added three "Write to Measurement to File" and set all of them to generate an excel file after running. I have even added a most simple one that just record the save wave, and I should expect three Excel files on my desktop, correct? However, there is nothing generated on my deaktop. 

 

I used the little “LAMP BULB” to run my program step by step, and there was no error occurred. And I have monitored the probe window, the exact same value as shown on the front panel of the raw CAN data can be found before the three "Measurement to file", as shown below:write to Mea probe.jpg

 

I have also tried to create a new VI under the Sample Project with just a sine wave with a "Write to Measurement file" and run, but still no Excel file created. I have tried to change the setting to a .txt file instead of Excel one, but nothing created. I have tried to do the same thing in a MyRIO Template, but still nothing created. 

 

My questions are as follow:

 

Am I doing something wrong, why the excel or txt file keep hiding from me? Or I can not modify the sample project? Things work successfully when I simply open my Labview 2014 and create a new VI(not under a Template or Sample Project), there will be a txt or excel file create when I generate a sine wave and connect with the "Write Measurement to file". It seems I can do nothing in the sample project, I have also tried to create a txt and write some text into it, as learnt on Youtube, but still nothing created...

 

 

Any help would be greatly appreciated since this is providing a bottleneck in my project.

 

Thank You

0 Kudos
Message 1 of 10
(4,024 Views)

The primary problem here is that the myRIO has its own file system. The program runs on the myRIO and has no access to your desktop's file system. You need to use a path that exists on the myRIO, then copy the data off the myRIO after the program runs.

 

I can't see your entire program but there are some LabVIEW style issues as well, although they are probably not preventing you from saving data. Try to avoid the use of local variables. The sample program in the first image is bad - the CAN Frame [Read] terminal should be wired directly, in place of the unnecessary local variable.

0 Kudos
Message 2 of 10
(3,981 Views)

Hello Nathand,

 

Thank you so much for your reply!

 

Since I am really new to Labview, could you please be a little more specific on how to add a path at myRIO so that I can save the data I received on my desktop? Is there a tutorial online or help manual?

 

For the issues you've mentioned, is it the original sample project or the one I have modified? To which component should I connect that CAN Frame [Read] ternimal to to aviod this?

 

Appreciate for your help!

 

Kevin


@nathand wrote:

The primary problem here is that the myRIO has its own file system. The program runs on the myRIO and has no access to your desktop's file system. You need to use a path that exists on the myRIO, then copy the data off the myRIO after the program runs.

 

I can't see your entire program but there are some LabVIEW style issues as well, although they are probably not preventing you from saving data. Try to avoid the use of local variables. The sample program in the first image is bad - the CAN Frame [Read] terminal should be wired directly, in place of the unnecessary local variable.


 

0 Kudos
Message 3 of 10
(3,975 Views)

Here's one example of saving data to the myRIO: https://decibel.ni.com/content/docs/DOC-34907

 

In the first image in your original post, the terminal for CAN Frame [read] is sitting, unused, at the top. Meanwhile, there's a local variable for that terminal inside the loop. Remove the local variable, connect the terminal directly.

 

In the other images I can't see enough of the code to know exactly what's happening. There's definitely a problem in one of them because you are writing to the measurement file outside the loop, meaning it will write only one measurement. In a later image it looks like you added multiple loops, one for the CAN data and another for logging. I'm guessing you could make that a single loop but maybe you have some need for them to be separate. A local variable is not an ideal way to pass data between loops; a functional global variable, queue, or notifier is better.

0 Kudos
Message 4 of 10
(3,971 Views)

Thanks for the help, I will check that link and try to work it out.

 

So are you saying I should do the bolow change of the original sample project? Because the first figure I posted was acquired from Labview 2014 directly, I did not make any change...

 

X-CAN Original.jpg

 

 

I have also take a snapshot of my modified one. Eventually, I would like to use a loop because I want to keep recording the data from my vehicle. I did not use the loop in my original post is because I tried a lot of tests on how to create a .txt or Excel file on my desktop, maybe that makes you a little confused...

 

Modified X-CAN.jpg

 

Are there any other changes I need to made in order to work properly? I have attached my VI. Really appreciate it!

Download All
0 Kudos
Message 5 of 10
(3,963 Views)

Yes, that's the change I was suggesting.

 

Is there some reason the logging needs to be in a separate loop? Otherwise I would put everything in the same loop. Right now, you have the logging and the receiving frames running at different rates (actually, you aren't controlling the logging loop rate at all) so you'll log the same frame over and over until the next update. That's probably not what you want.

 

I'm still on an older version of LabVIEW (2012) so I can't look at your VI.

0 Kudos
Message 6 of 10
(3,959 Views)
Are you suggesting I should do this way? Move everthing of Measurement into the loop and keep collecting data?
Modified X-CAN2.jpg
@nathand wrote:

Yes, that's the change I was suggesting.

 

Is there some reason the logging needs to be in a separate loop? Otherwise I would put everything in the same loop. Right now, you have the logging and the receiving frames running at different rates (actually, you aren't controlling the logging loop rate at all) so you'll log the same frame over and over until the next update. That's probably not what you want.

 

I'm still on an older version of LabVIEW (2012) so I can't look at your VI.


 

0 Kudos
Message 7 of 10
(3,949 Views)

Yes - but again, I don't know what your overall goal here is, I can't look at the code, I don't know what's going on in the True case, and I don't have any familiarity with the specific CAN functions you're using. However, if your goal is to log CAN frames as they arrive, then it probably makes more sense to keep it it one loop.

 

I do wonder why the Read (F)/Write (T) boolean is outside the loop, and why there are three unused front-panel terminals above the loop.

0 Kudos
Message 8 of 10
(3,945 Views)

The true case is nothing but "CAN Frame Write", as shown below. And yes I have the same feeling why there are three unused terminals above the loop, as well as the boolean thing. They are just the sample project in the Labview 2014 myRIO.

 

I tried to test the CAN write function but I can not figure out how it works. Anyway, my goal till now is just to log the raw CAN frame data. And thank you so much for your kindly help. I will keep trying to work on this.

 

123.jpg


@nathand wrote:

Yes - but again, I don't know what your overall goal here is, I can't look at the code, I don't know what's going on in the True case, and I don't have any familiarity with the specific CAN functions you're using. However, if your goal is to log CAN frames as they arrive, then it probably makes more sense to keep it it one loop.

 

I do wonder why the Read (F)/Write (T) boolean is outside the loop, and why there are three unused front-panel terminals above the loop.


 

0 Kudos
Message 9 of 10
(3,938 Views)

Some guesses: the CAN Frame [Write] terminal should get moved into the loop, replacing the local variable. The Read and Write terminals should get connected to two boolean wires that feed the shift registers. And the Read/Write selector should get moved inside the loop, so that changing the value while the code is running will change the mode (and maybe you want it to have a latching mechanical action, if you only want to write one frame each time that button is pressed).

 

Looks like that example is either sloppy or not completely finished - maybe there's documentation with it explaning how they expected it to be used? Sometimes the NI examples are unfortunately not actually good examples of LabVIEW coding.

0 Kudos
Message 10 of 10
(3,936 Views)