LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continous writing to external text file

Solved!
Go to solution

I'm trying to build a VI in labVIEW that will feed a decimal value based on a binary input into a case structure. The case structure will output a string value depending on the decimal input. The problem I am having is writing the string value to a text file that will continue to write while the Vi is continously running.

0 Kudos
Message 1 of 10
(3,771 Views)
Solution
Accepted by topic author FNG_1683

Here are some suggestions (you'll learn a lot more if you try to do these yourself, rather than my providing you a ready-made "solution").

  • You have 8 Boolean controls.  Consider making an Array (size 😎 of Boolean Controls (among other things, this helps group them nicely for you).
  • If you look on the Boolean Palette, you'll see an "Array to Number" function.  Guess what this does if you "feed" it an array of 8 Booleans ...  You can eliminate a lot of code by doing this.
  • Your numbers are all integers, so it doesn't make sense to save them as Doubles.
  • You have a While Loop configured here.  What do you think controls how fast it runs?  Do you care?  Do you want it to run "as fast as possible"?  Do you want it to run at a fixed speed (say, one loop per second)?  Do you want it to run "when something happens"?
  • One Good Thing you've done is recognize that the Logging Task has three parts -- Open (done once), Write (done as often as needed), and Close (done once).  You've also correctly positioned the relevant functions before, inside, and after the While loop.  I'm not 100% certain it matters in this particular case, but usually when one does this and has a While Loop operating on the same "variable" repeatedly, the wire is put in a Shift Register instead of a pair of tunnels.  Even if it isn't necessary here, it would be a good change to make, as it will be necessary in other instances.

I haven't actually tried running your code, but don't see anything terribly wrong with it.  Try making some of the changes I've suggested (which should allow you to dramatically shrink the size of your VI).  Pay particular attention to the "Speed" question.  If you need to re-post your "improved" VI (and thanks for posting this one), you might describe a little better "the problem I am having" -- what does it do, or what doesn't it do?

 

Bob Schor

Message 2 of 10
(3,756 Views)

Thanks for the quick response!

 

The sensors are to represent an actual photo-interuptor sensor which will be connected through a myRio. Since I dont have the actual physical sensor I was trying to design digital representation for the each of the interuptors. The grand scheme of the project is to develop a VI that will read an 8-hole punch tape and decode the message into a text file. The guide sensor determines if the tape being fed is off track. That was the only reason I was trying to avoid the array was so I could swap the sensors booleans indicators out with digital outputs from the myRio.

 

The main issue with my VI the way it is now it will only output whichever case is currently active as opposed to writing out any changes while running.

 

David Lambert

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

@FNG_1683 wrote:

Thanks for the quick response!

 

The sensors are to represent an actual photo-interuptor sensor which will be connected through a myRio. Since I dont have the actual physical sensor I was trying to design digital representation for the each of the interuptors. The grand scheme of the project is to develop a VI that will read an 8-hole punch tape and decode the message into a text file. The guide sensor determines if the tape being fed is off track. That was the only reason I was trying to avoid the array was so I could swap the sensors booleans indicators out with digital outputs from the myRio.

 

Are there really 9 sensors, 8 for the 8 holes in the tape and a nineth for a "guide sensor"?  Or are you deriving the "guide sensor" reading from 8 photo-interruptors?

 

In any case, I hope you see the virtue of creating an 8-bit Boolean control into which you wire 8 1-bit sensors (using the Array-to-Number function I mentioned).  If you have 8 digital outputs from your myRIO, and an 8-bit Boolean Array, you simply use Build Array, wire the 8 digital outputs into 8 elements of Build Array (which gives you ... let's see ... an 8-element Boolean Array).

 

The main issue with my VI the way it is now it will only output whichever case is currently active as opposed to writing out any changes while running.

 

David,  I'm sorry to say I don't have any idea what you mean by that last sentence.  Maybe you could write a narrative (in English, no code required) of what you want this thing to do.  For example, it could be something like "Every second, tell me the value of all 8 Boolean lines", or "Tell me the value of all 8 Boolean lines right now, and update this whenever any one or more of them changes, also telling me how much time has elapsed since the last change, or since I started recording".


Bob Schor

Message 4 of 10
(3,731 Views)

There will be 9 sensors according to the instructor. 8 to read the tape message and one for the guide/track sensor.

 

I will play around with some of the array suggestion you've given. I'm somewhat of a newb when it comes to the array functions but i'm sure with the help dialog boxes I can piece it together.

 

The goal of the VI is to read the punch tape via the sensors and write the results to a text file. I will definetly throw a wait timer in there too slow down the loop a little.

 

I've attached a file that describes the layout of the punch tape.

 

David Lambert

 

I

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

OMG!  You really meant Punch Tape!  This is a great project -- you definitely should use my 8-bit "punch reader" with a one-bit "tape sensor".  I've actually used Paper Tape, so I know the "trick" that makes decoding it a piece of cake.  I'm trying to remember the speed at which tape chattered through the reader -- the mechanical readers ("teletype") were about 10 characters per second, but the "fast" ones might have been 100 characters per second.

 

You've got most of what you need for this Project.  Take a look at the picture you sent me, see if you find any interesting patterns in it.  See if you can "find a rule".

 

Bob Schor

Message 6 of 10
(3,690 Views)

No luck with the rule and sadly I dont think we will get to have some hands on with an actual punch tape reader. The way my professor keeps talking makes it sound like this is mostly theory, but I was excited to build a circuit that would mimic the reader.

 

For the issue with the text output I was forgetting to put in a set position after the "open file", so each output was just overriding the last.

 

Check out the latest VI.

 

Also, thanks again for your help with this.

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

After the mid 1970's, you would be hard pressed to find a paper tape reader ...  I see that you ignored most of my suggestions, probably just as well.

 

Bob Schor

Message 8 of 10
(3,651 Views)

@Bob_Schor wrote:

After the mid 1970's, you would be hard pressed to find a paper tape reader


I recently (4-5 years ago) worked with a paper tape type writer.  The tape was used by a special tape reader for putting encrypted codes into an RF reciever that could blow up a rocket if it went off course.  The lab manager was trying to throw it away one day (possibly the only time he ever tried to throw anything away).  I had to step up to keep it.  Since I was the one trying to get rid of old junk, you could say our roles were reversed.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 10
(3,638 Views)

I doubt we would have used a real but it would of been nice to get to build a circuit that shared it's functionality.

 

Thanks again for all your help!

 

Was unaware of the kudos thing, pretty new to the forums.

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