Jump to content
The simFlight Network Forums

Recommended Posts

Hello, I am trying to extract variables from the P3DV4 and store them on a CSV. The given example works great for me. But when I try to write the code myself it doesn't work. Moreover, when I just copy paste the code with varied parameters I still get some error. I have attached the error below along with the code. Please do help me out.

CODE--------------------------------------------------------------------------------------------------------------------------------------------

-- "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("FSrecord.csv","a+"))

-- write the CSV column headings
f:write("\r\vs,mach,bank,BHP,ff,weight,alt,ias,tas,gs\n")

--  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

mach = ipc.readUW(0x11C6) -- mach number
vs = ipc.readSW(0x842)  -- vertical speed
bank = ipc.readSD(0x057C) -- bank angle
bhp = ipc.readDBL(0x3820) -- Brake horse power
ff = ipc.readDBL(0x0918) -- fuel flow in pounds per hour
fw = ipc.readUD(0x1264) -- fuel quantity in gallons
alt = ipc.readSD(0x3324) --altimeter reading in feet
ias = ipc.readUD(0x02BC) --indicated airspeed
--tas = ipc.readUD(0x02B8) --true airspeed
--gs = ipc.readUD(0x02B4) --groundspeed
----------------------conversion-----------------------
mach = mach / 20480
vs = vs * -3.28084
bank = bank * 360/ (4294967296) --conversion seems wrong
bhp = bhp / 570
fw = fw * 6.17
ias = ias / 128


-- 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("%d,%.3f,%.2f,%.2f,%.2f,%.2f,%d,%d\n",vs,mach,bank,bhp,ff,fw,alt,ias))
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
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------ERROR-------------------------------------------------

********* LUA: "parameters test1" Log [from FSUIPC version 5.103] *********
   886422 System time = 23/06/2019 08:16:21, Simulator time = 14:05:16 (19:05Z)
   886422 LUA: beginning "G:\P3Dv4\New folder\Modules\parameters test1.lua"
   886422 *** LUA Error: G:\P3Dv4\New folder\Modules\parameters test1.lua:1: unexpected symbol near 'ï'
   886422 >>> Thread forced exit (ipc.exit or os.exit) <<<
   886422 System time = 23/06/2019 08:16:21, Simulator time = 14:05:16 (19:05Z)
********* LUA execution terminated: Log Closed *********
*************************************__________________________________________************************************

 

Thanks in advance

 

 

Share this post


Link to post
Share on other sites
4 hours ago, Dinesh said:

Moreover, when I just copy paste the code with varied parameters I still get some error.

After a quick look the code above "seems" to be good - not tested.
It looks like your text editor is making the error, introducing an illegal character. (line1) Make sure your text editor is in english & ANSI or UTF-8 encoding.

4 hours ago, Dinesh said:

886422 *** LUA Error: G:\P3Dv4\New folder\Modules\parameters test1.lua:1: unexpected symbol near 'ï'

Roman

Share this post


Link to post
Share on other sites

Can you suggest any good text editor for LUA scripting? currently, I am using notepad and store it with UTF8 encoding 

Share this post


Link to post
Share on other sites

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

×

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.