Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello there.

I want that the actual altitude of my aircraft is written to a line in a txt file, and the file should be permanently updated. So i've changed the "record to csv.lua" file into like this

 


-- "Record to CSV" example data logging LUA plug-in, by Pete Dowson, September 2008

-- Open an exisitng "FSrecord.csv" file to append to, or create it if it doesn't exist
-- It will go into the Modules folder because I've not included a full path (like "C:\....")
-- By using "assert" you get an error message if this fails

f = assert(io.open("alt.txt","w"))


--  note the elapsed mSecs count now so can provide relative mSec timing column
time0 = ipc.elapsedtime()

-- Loop until our Flag 0 is set (by assigned FSUIPC control)
while not ipc.testflag(0) do

-- Set the timestamp for this loop
time = ipc.elapsedtime() - time0

-- Read all the data we want from FSUIPC
lat, lon, alt, pitch, bank, hdgT = ipc.readStruct(0x0560,"3DD", "2SD", "1UD")

-- now convert them all from FS units into those we normally recognise

alt = alt * 3.28084 / (65536 * 65536)


-- but only log this time IF we aren't in an FS menu, or loading scenery
-- (check the "ready-to-fly" flag word at 3364)
-- and provided we are not paused (flagged at 0264)


if (ipc.readUW(0x3364) == 0) and (ipc.readUW(0x0264) == 0) then

   -- write a CSV line to the open file
   f:write(string.format("%.1f\n",
	alt))
end

-- 20 times per second, roughly (allow 2 mSecs overhead)
ipc.sleep(48)

end

-- tidy up at end ...
f:write("\n")
f:close()

-- end of example program

This works perfectly fine...

But now the output in the "alt.txt" is for example:

21.8
21.8
21.8
21.8
21.8
21.8
21.8
21.8
21.8
21.8
21.8
21.8
21.8

i want just one line that should be updated, and not a ton of new lines. is there a way to manage this? and where should i change the script to let it do this?

 

thanks :)

Posted
10 minutes ago, gnusmas said:

i want just one line that should be updated, and not a ton of new lines. is there a way to manage this? and where should i change the script to let it do this?

You'd need to re-create the file every time, doing the open, write and close all together.

Pete

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.