JohnyQuick Posted June 7, 2011 Share Posted June 7, 2011 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 More sharing options...
AzeoTech Posted June 7, 2011 Share Posted June 7, 2011 Can you please copy and paste your current script? Link to comment Share on other sites More sharing options...
JohnyQuick Posted June 8, 2011 Author Share Posted June 8, 2011 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 break endif // 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) endwhile // Closes the file File.Close(FileHandle) 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 More sharing options...
AzeoTech Posted June 8, 2011 Share Posted June 8, 2011 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 More sharing options...
JohnyQuick Posted June 8, 2011 Author Share Posted June 8, 2011 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. while(1) Private FileHandle = File.Open("C:\PacificSystems\file.txt",0,1,1,1) // Format string Private string strText = FormatTime(XY1.Time[0]) + "," +\ DoubletoStr(XY1[0]) // Write data to text file File.Write(FileHandle,strText) // Close the file File.Close(FileHandle) delay(30) endwhile 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]) + "," +\ DoubletoStr(XY20]) 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 More sharing options...
AzeoTech Posted June 8, 2011 Share Posted June 8, 2011 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 More sharing options...
JohnyQuick Posted June 10, 2011 Author Share Posted June 10, 2011 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. Thanks. Link to comment Share on other sites More sharing options...
AzeoTech Posted June 10, 2011 Share Posted June 10, 2011 Sure. Its just a matter of tracking everything. In fact, I'm guessing it will be simpler to do in code than try to explain it in words, as I'm not particularly clear what you are trying to do. Link to comment Share on other sites More sharing options...
JohnyQuick Posted June 10, 2011 Author Share Posted June 10, 2011 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, While(1) X[3][2]=Y X[3][1]=Z delay(1) endwhile And the sequence populates the array with the numbers I need like so, {{0,0,0},{Z,0,0},{Y,0,0},{0,Y,Z}} 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 More sharing options...
AzeoTech Posted June 10, 2011 Share Posted June 10, 2011 Indexing is always from 0. To get: {{0,0},{Y,Z}} you'd do: X[1][0] = Y X[1][1] = Z To do it in a loop where it adds to the end, you can do: index = 1 while (1) X[index][0] = Y X[index][1] = Z delay(1) endwhile Link to comment Share on other sites More sharing options...
JohnyQuick Posted June 13, 2011 Author Share Posted June 13, 2011 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. LD[0][2][2]=a[0] LD[0][2][1]=b[0] LD[0][2][1]=c[0] a,b and c are channels which makes this {{{0,0,0},{0,0,0}{a,b,c}}} 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, {a,0,0} 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 More sharing options...
AzeoTech Posted June 13, 2011 Share Posted June 13, 2011 By adding a value, you mean to the beginning of the array? Well, its actually just AddValue(), just like channels: myVar.AddValue({1,2,3}) 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: {{0,0,0},{0,0,0},{0,0,0},{0,0,5}} 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.