Page 169
only upload fifty datalog values at a time. If you have larger datalog, it must be uploaded in pieces.
The relevant Spirit.ocx function is UploadDatalog, which takes a starting index and a length. The first (zero-th) item of the datalog contains the length of the datalog. It's the first thing
SaveDatalog reads:
data = .UploadDatalog(0, 1)
length = data(2, 0) -1
The actual data length is one less than the reported length, because the zeroth item is not a data point.
The data returned from UploadDatalog is an array. Each datalog item is represented by three numbers. The first two numbers indicate the source and number of the value; source and number
have exactly the same meaning here as they do for Poll. The third number is the actual value stored in the datalog.
SaveDatalog writes the source, number, and value for each datalog item out to a text file. Each line of the text file represents one item from the datalog. On each line, the source, number, and
value of the item are separated by commas. This example interprets the source of each value, then converts it to a descriptive string before writing it out to the file. The output file will look
something like this (depending, of course, on the contents of the datalog):
Variable, 1, 2
Timer, 0, 543
Variable, 2, 8
Variable, 8, 368
Sensor value, 1, 33
Watch, 0, 7
A plain text file of comma-separated values is usually pretty easy to import into a spreadsheet or statistical analysis program. You can use your robot to gather data, use this example program to
upload it to your PC, and then use some other program to analyze or graph the data. Some people have built optical scanners based on RIS using these techniques.
The example is comprised of three parts. The SaveDatalog subroutine does most of the work. It uses the min function to calculate a minimum and the getTypeString function to convert
the datalog item source number to a descriptive string:
Sub SaveDatalog(filname As String)
Dim data As Variant
Dim index, length, stepSize As Integer
Dim line As String
With DummySpiritForm.Spirit1
Page 170
' Open the output file.
out = FreeFile
open filename For Output As #out
.InitComm
' First get item zero, which describes the length of the datalog.
data = .UploadDatalog(0, 1)
length = data(2, 0) - 1
' Now upload 50 items at a time.
index = 0
While (index < length)
' Find the smaller of the remaining items or 50.
stepSize = min(length - index, 50)