Welcome to Cockpitbuilders.com. Please login or sign up.

March 28, 2024, 02:41:48 AM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
122 Guests, 0 Users
Members
Stats
  • Total Posts: 59,639
  • Total Topics: 7,853
  • Online today: 130
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 122
Total: 122

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

IPCREADY.LUA EXPLAINED!

Started by Trevor Hale, April 08, 2015, 03:32:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Trevor Hale

This file gets put into your FSUIPC MODULES DIRECTORY.

Once FSX is Loaded and FSUIPC Starts, this file runs.

Lets look at the bottom of the code.


Quote

-- Arduino Gauges/Servos
event.offset (0x0be0, "UD", "call_flaps") -- aircraft Flaps
event.offset (0x02c8, "SD", "call_vertical") -- aircraft Vertical Speed
event.offset (0x0be0, "UD", "call_flaps") -- aircraft Flaps
event.offset (0x0b7c, "UD", "call_lfuel") -- aircraft Left Fuel

event.offset (0x0b94, "UD", "call_rfuel") -- aircraft Right Fuel

event.offset (0x0bc2, "SW", "call_trim") -- aircraft Trim
event.offset (0x0e8c, "SW", "call_oat") -- aircraft Outside Air Temp


these lines of code specify the "FSUIPC OFFSETS" I am looking for in FSX to change.

event.offset (Means that I am looking for an offset change)
0x (means Offset Location in HEX)
0E8C (Is the OFFSET ADDERSS taken from this list -->  http://737ngsim.co.uk/wp-content/uploads/2012/12/FSUIPC4-Offsets-Status.pdf)
S (means Signed bit "Could be a + or a - Value)
W (Means WORD which is a representation of 16 Bits which is the size of the offset from this list "2nd column" --> -->  http://737ngsim.co.uk/wp-content/uploads/2012/12/FSUIPC4-Offsets-Status.pdf)

call_oat (means when the offset changes go to the "Function Block" in the program called call_oat)

Are you with me so far?  Good.

Now we will look at the easy part of the code...

Quote
-- Open Seial Port and connect to Arduino
speed = 115200
handshake = 0
serial_wait = 100
inited = 0
states = {}
dev = com.open("COM3", speed, handshake) -- Change Port Number for your Arduino
if dev == 0 then
    ipc.display("Could not open device port")
    ipc.exit()
end

-- Finish Serial Connect

This just works, its humble jumble..  it basically just tells the LUA Script where the ardino is.
Just change the COM3 to Com1, Com2, Com4 or whatever comp port your arduino is connected to.

Lastly Look at the meat of the CODE

Quote
function call_oat (offset, value)
    value = (value/256)
    ipc.log ("writes com = ?c"..string.format("%04d", value).. "\n")
    com.write (dev, "?c" .. string.format("%04d", value) .. "\n")
    ipc.sleep(serial_wait)
end

function call_oat (offset, value)   "Think of this as the title of the function block that runs when that offset changes. (Remember above we said to come here?)"
value = (value/256) "this means whatever value the offset changed to, divide it by 256 and go on."
ipc.log ("writes com = ?c"..string.format("%04d", value).. "\n") " basically is humble jumble for when this offset changes write the value to fsuipc.log so I can watch if it is working - HOWEVER I USE THE ?c as a trigger for my Arduino program to know when I am sending outside Air Temperature Value"

com.write (dev, "?c" .. string.format("%04d", value) .. "\n") Same thing as above only this is what it is sending to the COM PORT (ARDUINO) again the ?c in my arduino code means OUTSIDE AIR TEMP

ipc.sleep(serial_wait) " Means give the com port a break, it gets tired (Serial_wait) was defined at 100 in the Serial port setup we did above which means 100 mili seconds."

end "means I can go on to the next offset that changes.

Thats it, that is my lua code explained.  now if you have specific questions, I can try to answer them.




I attached my LUA Code to this post also for ease of explanation.  NOW, This is 1/2 of the code...  I will detail the arduino code in a different post.  remember, this just sends the data to the com port.  In the Arduino, that code needs to tell your gauge what to do with that code when it gets the message.


And if you don't know WHAT FSUIPC IS or DOES.  You need to do a lot of reading, because until you understand that..  this is still not going to be of any help to you.[/quote]
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

pcpilotmd80

Hey Trev, I hope you didn't do that just for me Jk haha!, thanks for detail explaination, starting to make sence thanks for help, so is cold beer!

Mike

RayS


...what's this "FSCIUPD" thingy you speak of?  ::)
Ray Sotkiewicz

Trevor Hale

LOL @ Ray thats funny..  I have no idea :)

Mike, Yes I did, and I will try to get time to do the same thing for my Arduino code also..  But things are very busy right now.

I will try.

Trev
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

Ed

Thanks for posting that explanation. Quite helpful.  I understand most of it but am new to Arduino. Was gifted an Uno recently so dabbling into the Arduino sketch coding. Want to use it for displaying seven segment displays in an NGX FSX environment.

The Lua code you list...is  that similar to a 'sketch' code or does one have to download another program to run Lua code? I'm currently digging into the Links2FS interface and playing around with small sketches .

Ed
P3D5.3HF2, 3 x W10 PC's, FSUIPC 6.19 ,WideFS, Prosim737 V3 ,ASP3D, Vpilot, GSXL2, Pro-ATC/X, RAAS Pro, AIG Traffic, ,PFPX, TopCat, SimSounds,  http://www.737ngxca.com/

Trevor Hale

Hi Ed.

This lua COde just runs in the fsuipc directory when fsx loads. The idea is it extracts the data from flightsim and just sends it to a serial port.

The arduino code is different and hence must be written to capture the data coming into the serial port from the lua program.

You really just need FSUIPC in order for the lua program to work.

Trev
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

Ed

Hi Trevor,

Thanks for the reply. Will take a look about for the  Lua script module and see if I can make heads or tails of it.


P3D5.3HF2, 3 x W10 PC's, FSUIPC 6.19 ,WideFS, Prosim737 V3 ,ASP3D, Vpilot, GSXL2, Pro-ATC/X, RAAS Pro, AIG Traffic, ,PFPX, TopCat, SimSounds,  http://www.737ngxca.com/

Ed

Hi Trevor,

Couple more questions . Where can I get the Lua script and the Linda editor? I thought it comes packaged with the Registered Version of FSUIPC.. but on initial glances I dont see it. Can you point me in the right direction please.
P3D5.3HF2, 3 x W10 PC's, FSUIPC 6.19 ,WideFS, Prosim737 V3 ,ASP3D, Vpilot, GSXL2, Pro-ATC/X, RAAS Pro, AIG Traffic, ,PFPX, TopCat, SimSounds,  http://www.737ngxca.com/

Trevor Hale

Hi the Lua script is an attachment to my first post. And I didn't use Linda for it. I downloaded a generic editor called notepad ++

Trev
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate