DistanceSenor write to file

Supporting Visual Studio on Windows
Post Reply
jimmerson
Phidgetsian
Posts: 5
Joined: Fri Jul 29, 2022 1:00 pm
Contact:

DistanceSenor write to file

Post 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?
jimmerson
Phidgetsian
Posts: 5
Joined: Fri Jul 29, 2022 1:00 pm
Contact:

Re: DistanceSenor write to file

Post by jimmerson »

Hmm, I have just found the "how to"


https://www.phidgets.com/education/lear ... nsor-data/
jimmerson
Phidgetsian
Posts: 5
Joined: Fri Jul 29, 2022 1:00 pm
Contact:

Re: DistanceSenor write to file

Post 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");
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: DistanceSenor write to file

Post by mparadis »

What error message do you get when your program fails?
jimmerson
Phidgetsian
Posts: 5
Joined: Fri Jul 29, 2022 1:00 pm
Contact:

Re: DistanceSenor write to file

Post by jimmerson »

outfile.WriteLine(DistanceSensor.Distance.ToString() + "\n");

outfile.WriteLine(DistanceSensor.ToString() + "\n"); both get the error "An object reference is required"
jimmerson
Phidgetsian
Posts: 5
Joined: Fri Jul 29, 2022 1:00 pm
Contact:

Re: DistanceSenor write to file

Post 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");
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: DistanceSenor write to file

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests