Get the last record in a CSV file
Posted: Monday 28th December 2020 4:45pm
Hello,
Boy am I happy I found Gambas3 and this forum
After programming VB6 and VB.net for many years, moved to Python for many of the control and MQTT "internet of things" projects that I have.
I also run Linux, which limited me from good GUI applications. Until now.
Gambas is awesome, light, fast, and perfect for building GUI applications.
I run into some snags with the slight nuance differences in the BASIC syntax but that's not a big issue.
The current project is the building of a GUI dashboard to display various parameters in a greenhouse.
Light, Temperature, pumps on/off.
Currently am struggling with a CSV file and was hoping to find a few members with some experience with what I'm trying to do.
One of the greenhouse sensors publishes data to a .csv file.
The text format is: date, time, temperature (with no header headings).
Like this....
27/12/2020,18:23:33,13.62
27/12/2020,18:23:49,13.62
27/12/2020,18:24:04,13.62
27/12/2020,18:24:20,13.62
I was planning to use the CsvFile library from the internal gb.util
but I can't find any documentation on how to use it.
I have included the cb.lib in my project and coded the Opening of my file like this....
===============================
Public myCSVfile As CsvFile
' Load file
myCSVfile = New CsvFile(Application.Path & "/" & "Greehouse_Sensor_Data.txt")
Do Until myCSVfile.Eof
< SOME CODE HERE>
Loop
The goal of this project is to grab the last line (specifically the last temperature reading) in the csv file.
The file gets updated every 15 seconds, but I just need to grab the last temperature reading every 10 minutes or so in order
to check it against alert/alarm settings.
Simply put:
How do I grab the last data item in a CSV file regardless of the number of records in the file?
It is not important to me whether or not the the CsvFile / gb.util method is used as long as I can read the last data point in the file.
thanks kindly
Boy am I happy I found Gambas3 and this forum
After programming VB6 and VB.net for many years, moved to Python for many of the control and MQTT "internet of things" projects that I have.
I also run Linux, which limited me from good GUI applications. Until now.
Gambas is awesome, light, fast, and perfect for building GUI applications.
I run into some snags with the slight nuance differences in the BASIC syntax but that's not a big issue.
The current project is the building of a GUI dashboard to display various parameters in a greenhouse.
Light, Temperature, pumps on/off.
Currently am struggling with a CSV file and was hoping to find a few members with some experience with what I'm trying to do.
One of the greenhouse sensors publishes data to a .csv file.
The text format is: date, time, temperature (with no header headings).
Like this....
27/12/2020,18:23:33,13.62
27/12/2020,18:23:49,13.62
27/12/2020,18:24:04,13.62
27/12/2020,18:24:20,13.62
I was planning to use the CsvFile library from the internal gb.util
but I can't find any documentation on how to use it.
I have included the cb.lib in my project and coded the Opening of my file like this....
===============================
Public myCSVfile As CsvFile
' Load file
myCSVfile = New CsvFile(Application.Path & "/" & "Greehouse_Sensor_Data.txt")
Do Until myCSVfile.Eof
< SOME CODE HERE>
Loop
The goal of this project is to grab the last line (specifically the last temperature reading) in the csv file.
The file gets updated every 15 seconds, but I just need to grab the last temperature reading every 10 minutes or so in order
to check it against alert/alarm settings.
Simply put:
How do I grab the last data item in a CSV file regardless of the number of records in the file?
It is not important to me whether or not the the CsvFile / gb.util method is used as long as I can read the last data point in the file.
thanks kindly