Read a file and set 2 outputs?

Recommended Posts

Help please,

I have my sequence almost word for word from the example in the help file

section 9.10.2.

My sequence will read the file, but it is only setting one output, I need the other ouput.

The sequence runs, just no second output channel.

The file is comma delimited ascii from a logging set

For some reason I can't upload it

Could you help please? :)

Link to comment
Share on other sites

I got it to work today, after I recopied from the DF Help manual.

A couple of things though. The first line, for the file name, if I access a DF logging file, I don't put a .txt

extension, or otherwise the sequence won't run.

So, if I have a file with 3, 4,5, numbers in it, that I use/manipulate,

could I set the 3rd output channel go something like,

DIM3 = StrToDouble(Parse(strIn,3,",")) ?

Like this:

// Opens the file sets the variable FileHandle
Private FileHandle = File.Open("C:\PacificSystems\file",1,0,0,1)
Private string strIn
while (1)
// read a line
strIn = File.Read(FileHandle)
// This checks for an empty string
if(strIn == "")
// Breaks out if empty string
// This code Parses the String and sets the output channel
DIM1 = StrToDouble(Parse(strIn,1,","))
DIM2 = StrToDouble(Parse(strIn,2,","))
DIM3 = StrToDouble(Parse(strIn,3,",")) 
// Reads 1 second at a time
delay (1)
// Closes the file

Also, Can you recommend any books on File manipulation, as this seems to be the solution for the"hard" mudlogging problems? I took a Fortran class, many years ago, and that is helping some.

Also, the Help doesn't explain how to append a file, which is something I need to do to get better organized,

so a book recomendation would help me. The DF help on Files is only about 15 pages out of 400 something.

Got my transducer up and going with LABJACK today, and got it going, but I probably need to step down a range, or up the volts in to get it to SPAN enough. But the precision resister worked great, and it converted 4-20 MA to Volts very nicely.

I'm very satisfied with DF, so far, and I still have 7 free days left. Also Impressed with the LABJACK. I was

skeptical of using USB drivers, but it works fine, so far.

Thanks for your Help. :)

Link to comment
Share on other sites

First, and it may be from cutting and pasting, but watch your indentation.

Next, yes, you can just use parse with different indices to get other values. You might also consider using the ReadDelim() function instead of the loop.

As for books on file manipulation, no I can't recommend any. Its not really a topic I've read up on in a long time. File manipulation is largely unchanged in 40+ years.

Append a file? Just set the 4th parameter in the open to 1: 0,1,1,1 for write, append, text.

The DF help assumes that you have some basic understanding of File I/O. If it went into detail on these basics that are covered in other books, the manual would be 4000 pages instead of 400. Anyhow, I guess my one recommendation for file I/O books is to look for one that is old, not a newer book. New books don't really cover low level stuff because Windows hides so much of it.

Link to comment
Share on other sites

OK, that makes sense. Unchanged in 40 years, I can run with that.

Anyway, what I want to do is open my file, read it, then if something is true, delete that line/record from the file. I understant the(1,0,1,1) part, that it opens the ascii text file ,reads it and appends it, but how do

I do the actual modify of the file? How do I get rid of a line/record, and then the save/append part is taken care of with the (1,0,1,1) part.? Before the file gets closed.

Also, another question about writing to a file.


Private FileHandle = File.Open("C:\PacificSystems\file.txt",0,1,1,1)

// Format string

Private string strText = FormatTime(XY1.Time[0]) + "," +\


// Write data to text file


// Close the file




This is also straight from the DF Help.

So my question is, if I want to write more than one channel to my file. Do I just repeat the lines?

Private string strText = FormatTime(XY2Time[0]) + "," +\


I want my numbers to be on the same line, like so,

time, XY1, XY2, XY3, etc.

Another ?, if you don't mind. Can I use the File.Delete(file) on a DF logging file? seems to show a SHARE.EXE not loaded error. But with file .txt files the function works fine.

Thanks for the help.

Link to comment
Share on other sites

Modifying an existing file is actually largely impossible because you don't have fixed length records. You basically have to read the entire file in, modify it in memory, then rewrite it. This is, as I said, a 40+ year old problem when writing ascii delimited files (vs fixed field files).

To add another row, you want to add to the end of the first private string strText line:

Private string strText = FormatTime(XY1.Time[0]) + "," +\

DoubletoStr(XY1.[0]]) + "," + DoubletoStr(XY2.[0]])

You can't delete a DF logging file if its currently being used (even if the logging set is not running). You have to tell the logging set to log to a different file with the logging set running, and then you can delete it. The whole "share.exe" thing is an old MS DOS error message that for some reason Windows still generates when you try and delete or edit a file that is locked.

Link to comment
Share on other sites

Ok, of course, that would make it too easy.

How about this though,

I open my file, then I check it of the numbers I need, If is is a number I want, I open another file, and write

to that one, since I can't re write to my already open file.

And I write, or don't write to that, someother file, as the conditions get met, or not.

Then the next time I open "file" it will be , the new file. Call it file1

I check the numbers in the new file, and as conditions get met, or not, I write to yet another, unopened file, and so on and so forth. File1, File2, File 3, File(n)

Each time opening the latest file version of my checked numbers. Untill the file(n) returns an empty string.

And opens instead, the original "file", and starts all over again.

So, then the question is: Is there a way to do that, so that the sequence knows to open file, the first time,

then say file1, the next time, instead of the original file, and then the next time file2, and so on??

And then, at the end, if file(n) is empty, it will open the original file all over again and start over??

I will have to think about this some more. There must be a count or something that can do that.

Thanks for your help.


Link to comment
Share on other sites

Thanks, but I was barking up the wrong tree.

I've decided my "problem" needs to be solved with variables.

I have a variable set up in globals like so,

global X = [Y][Z], where Y and Z are channels.

Then my sequence goes like so,






And the sequence populates the array with the numbers I need like so,


So heres another question. The {0,Y,Z} part of the array, is the part I need to check,compare with another

channel. I don't understand, why the second and 3rd parts of the array, go the way they did. Why is that?

Also is the 0 in {0,Y,Z} the equivalent of time?

All I really need is like so. How would I do that?

{{0,0},{Y,Z},{Y,Z}, etc.}}

I don't understand the

{Z,0,0} and {Y,0,0} part of the variable array I made. Could you explain a little about why it does that.

Link to comment
Share on other sites

Thanks for the help,

My problem is "almost" solved. :)

I did it using 3 variable arrays. I subtract one array from another to create my 3rd array.

when the difference of one of the rows is zero. I get the value for the Holy Grail. Well close to it anyway.

So, my questions now are these.

How do I "add value" to a variable array? So far I have this.




a,b and c are channels

which makes this


But I need to add value, so the variable has history. How do I do that?

Then, my other question is if I have an variable array with history, and somewhere in the history is this,


How do I get from the array all the a's , where the other rows are zero?

And then set up another variable whith history, just for that, those a's?

Thanks again.

Link to comment
Share on other sites

By adding a value, you mean to the beginning of the array? Well, its actually just AddValue(), just like channels:


Note that addvalue always works in the first (rows) dimension.

If you want to add to the end, just index past the end. Unlike other languages, DAQFactory automatically fills the array with 0's (or empty strings if a string array) to make the right size, so:

private x

x[3][2] = 5

? x

will display:


As to your second question, you'll likely want to use the filter() function, though it will be a little trickier if you have a multidimensional array (since filter() works in rows). Otherwise you might just have to create a loop and find it manually, then move the values to another variable.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.