Page 1 of 1

DistanceSenor write to file

Posted: Fri Jul 29, 2022 1:06 pm
by jimmerson
Hi,

I'm sorry, this is probably dumb but I'm not programmer.

How can I have DistanceSenor (sonar) dump all data into a file?

Re: DistanceSenor write to file

Posted: Fri Jul 29, 2022 1:11 pm
by jimmerson
Hmm, I have just found the "how to"


https://www.phidgets.com/education/lear ... nsor-data/

Re: DistanceSenor write to file

Posted: Fri Jul 29, 2022 1:19 pm
by jimmerson
Well, not I'm stuck on getting the below code to work with a DST1200_0 sensor.

//Write data to file in CSV format
outfile.WriteLine(temperatureSensor.Temperature.ToString() + "\n");

Re: DistanceSenor write to file

Posted: Fri Jul 29, 2022 1:46 pm
by mparadis
What error message do you get when your program fails?

Re: DistanceSenor write to file

Posted: Fri Jul 29, 2022 1:54 pm
by jimmerson
outfile.WriteLine(DistanceSensor.Distance.ToString() + "\n");

outfile.WriteLine(DistanceSensor.ToString() + "\n"); both get the error "An object reference is required"

Re: DistanceSenor write to file

Posted: Fri Jul 29, 2022 2:13 pm
by jimmerson
Copied ("Distance: " + distanceSensor.Distance + " mm"); from the "Learn" section for the sonar sensor and it works!

I guess it was the capital "D" in the previous code?

This works outfile.WriteLine("Distance: " + distanceSensor.Distance + " mm");

Re: DistanceSenor write to file

Posted: Fri Jul 29, 2022 2:15 pm
by mparadis
Yes, the problem is DistanceSensor (with capital D and S) is the name of the data type of our distance sensors in the phidget22 library. Earlier in your program there should be a line like:

Code: Select all

DistanceSensor insertNameHere = new DistanceSensor
You need to call

Code: Select all

insertNameHere.Distance.toString()
for whatever name you defined on that line.