Darren Posted November 9, 2007 Share Posted November 9, 2007 I recently found some code (I think in the DAQFactory Express help files - can't find it now) to read two columns of data from a file and put the results into V channels with associated time. I modified this code to get data from 8 different columns of a .csv file and create a V.channel for each column. It worked fine, I was using this to create graphs from data I had captured with my Labjack combined with data I was gathering using other applications having first manipulated the data into a single .csv file using a spreadsheet. I then decided it was about time I checked for updates for DAQFactory Express and the Labjack software, installed them, now the data is not getting read correctly. I'm getting the correct time and then the 10 digit DAQFactory time for most values after 18 rows of this I get one with Nan then the one with the correct value then 18 with DAQF time then 1 with correct value then one with time the 18 DAF time etc. etc. etc. . The .csv files do have some blank values but not in a 20 or 40 row pattern I'm doing this without the labjack connected.... Whats happening..... Here is the sequence I use to read the data Private.hFile = File.Open("c:\Documents and Settings\Darren1\My Documents\vegoil\Logs\Labjack Logs\glowplug\special\GP-cold-drive.csv",1,0,0,1) V.Cyl4GP.ClearHistory() V.Coolant_Temp.ClearHistory() V.Cyl4IQ.ClearHistory() V.DF_Mark.ClearHistory() V.IQ.ClearHistory() V.rpm.ClearHistory() V.VAG_Mark.ClearHistory() Private.strIn = File.Read(Private.hFile) while (1) Private.strIn = File.Read(Private.hFile) if (Private.strIn == "") break endif Private.x = StrToDouble(Parse(Private.strIn,1,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.Cyl4GP.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,2,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.DF_Mark.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,3,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.VAG_Mark.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,4,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.rpm.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,5,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.IQ.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,6,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.Coolant_Temp.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,7,",")) Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) V.Cyl4IQ.AddValue(Private.x) endwhile File,Close(Private.hFile) After looking about to try and find out why this would be happening I noticed that I could use Read.FileDelim but could not find a good example of this in use. I'm new to coding and this is all a steep learning curve although I am (was) making gradual progress adding buttons to the graphing page to tune the way the data was displayed etc. Link to comment Share on other sites More sharing options...
AzeoTech Posted November 12, 2007 Share Posted November 12, 2007 Can you post a sample: ie. the .ctl document and a sample text file, so we can see it in action. Then we can also show you exactly how to do it with readdelim() which is certainly easier. Link to comment Share on other sites More sharing options...
Darren Posted November 23, 2007 Author Share Posted November 23, 2007 Thank you for your attention. I've attached my files. datainput.ctl Link to comment Share on other sites More sharing options...
AzeoTech Posted November 28, 2007 Share Posted November 28, 2007 I'm not exactly sure why its happening, but doing private.x.time = parse(..) is messing up your values. Presumably, instead of putting it in the time portion, its putting it in the main portion. The solution is actually the preferred way of writing this code anyway. In your script, you are parsing the string for time 6 times, one for each value, even though the time is the same. Instead you should parse once at the beginning: Private.hFile = File.Open("c:\Documents and Settings\Darren1\My Documents\vegoil\Logs\Labjack Logs\glowplug\special\GP-cold-drive.csv",1,0,0,1) V.Cyl4GP.ClearHistory() V.Coolant_Temp.ClearHistory() V.Cyl4IQ.ClearHistory() V.DF_Mark.ClearHistory() V.IQ.ClearHistory() V.rpm.ClearHistory() V.VAG_Mark.ClearHistory() Private.strIn = File.Read(Private.hFile) while (1) Private.strIn = File.Read(Private.hFile) if (Private.strIn == "") break endif Private.x.Time = StrToDouble(Parse(Private.strIn,0,",")) Private.x = StrToDouble(Parse(Private.strIn,1,",")) V.Cyl4GP.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,2,",")) V.DF_Mark.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,3,",")) V.VAG_Mark.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,4,",")) V.rpm.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,5,",")) V.IQ.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,6,",")) V.Coolant_Temp.AddValue(Private.x) Private.x = StrToDouble(Parse(Private.strIn,7,",")) V.Cyl4IQ.AddValue(Private.x) endwhile File.Close(Private.hFile) Also note that you had a comma in File.Close() Finally, you should probably move away from using private. notation. It makes the script less readable and why we allow you to declare variables now: Private hFile = File.Open("c:\Documents and Settings\Darren1\My Documents\vegoil\Logs\Labjack Logs\glowplug\special\GP-cold-drive.csv",1,0,0,1) V.Cyl4GP.ClearHistory() V.Coolant_Temp.ClearHistory() V.Cyl4IQ.ClearHistory() V.DF_Mark.ClearHistory() V.IQ.ClearHistory() V.rpm.ClearHistory() V.VAG_Mark.ClearHistory() private x Private strIn = File.Read(hFile) while (1) strIn = File.Read(hFile) if (strIn == "") break endif x.Time = StrToDouble(Parse(strIn,0,",")) x = StrToDouble(Parse(strIn,1,",")) V.Cyl4GP.AddValue(Private.x) x = StrToDouble(Parse(strIn,2,",")) V.DF_Mark.AddValue(Private.x) x = StrToDouble(Parse(strIn,3,",")) V.VAG_Mark.AddValue(Private.x) x = StrToDouble(Parse(strIn,4,",")) V.rpm.AddValue(Private.x) x = StrToDouble(Parse(strIn,5,",")) V.IQ.AddValue(Private.x) x = StrToDouble(Parse(strIn,6,",")) V.Coolant_Temp.AddValue(Private.x) x = StrToDouble(Parse(strIn,7,",")) V.Cyl4IQ.AddValue(x) endwhile File.Close(hFile) Link to comment Share on other sites More sharing options...
Darren Posted December 2, 2007 Author Share Posted December 2, 2007 Tried the new code. I'm getting an error - C1097 - string operator found where number expected line 13 which is - if (strIn == "") Link to comment Share on other sites More sharing options...
AzeoTech Posted December 3, 2007 Share Posted December 3, 2007 Oops, there is a period (or the word string) missing in this line: Private strIn = File.Read(hFile) It should be either: Private.strIn = File.Read(hFile) or Private string strIn = File.Read(hFile) The second way is the more modern way, but the first works just as well. The clue is that the error says that its looking for number where a string was found. Since "" is obviously a string, the compiler must think the other thing, "strIn", is a number, which we know is wrong, so we look at the declaration and see that it is not declared as a string. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.