Jump to content
The simFlight Network Forums
Sign in to follow this  
AurelienF38

Lvar interfacing with arduino and mobilight

Recommended Posts

Hi every body,

 

I'm working to interface the A2A cessna to make a home cockpit.

For the moment, I would like to see what can I do only with simple arduino and mobiflight.

And I have already my first results! 😃

I have interfaced some switches, like battery, alternateur, ... with simple Lua script.

For example, this is my script wich I can drive the battery switch:

battery = ipc.readUB(0x3340)
if battery > 0 then	
ipc.writeLvar("L:Battery1Switch",1)
else
ipc.writeLvar("L:Battery1Switch",0)
end

It works greatly!

Today, I succeeded to drive my first gauge!! 😅 For the RPM, with motor stepper, with Lvar and Lua script! and this script...

while 1 do
Eng1_RPM = ipc.readLvar("L:Eng1_RPM")
ipc.writeSW(0x66c8, Eng1_RPM)
ipc.sleep(100)
end

So, after that, I thought that it would be simple to drive other gauge, on other free offset. But no result for the moment...

I try to drive the IAS gauge, with this script, but it doesn't work... I've tried on many different offset...

while 1 do
IAS = ipc.readLvar("L:AirspeedIndicatedNeedle")
ipc.writeSD(0x9200, IAS)
ipc.sleep(100)
end

Could someone have an idea?

Best regard

Share this post


Link to post
Share on other sites
1 minute ago, AurelienF38 said:

I try to drive the IAS gauge, with this script, but it doesn't work... I've tried on many different offset...


while 1 do
IAS = ipc.readLvar("L:AirspeedIndicatedNeedle")
ipc.writeSD(0x9200, IAS)
ipc.sleep(100)
end

Could someone have an idea

The offsets reserved for users are 66C0 to 66FF. Others, just because they have no assignment listed, are not necessarily free for any unauthorised use.

Do you know what sort of values that L:Var supplies? Have you logged it? Try the Lua logging plug-in supplied for a real-time log.

Have you double-checked your coding at the other end, in the Arduino or Mobiflight (which I don't know).

Pete

 

Share this post


Link to post
Share on other sites

Thank you Pete.

I start to see more clearly, I started again from the beginning today.

I used the offsets you told me.

So, first, I checked the Lvar list in real time. This is a part of it:

3528031 LUA.1: L:Eng1_RPM=1616.0072558023

For the RPM, we have 14 figures, only positive. So, logically, it's on a 16bit, and usigned, so it will be "writeUW" in the script.

I tried with this code, on offset 66c0. And it's ok!!🤩

while 1 do
RPM = ipc.readLvar("L:Eng1_RPM")
ipc.writeUW(0x66c0, RPM)
ipc.sleep(100)
end

 

after, I tried, like yesterday with the IAS gauge. i checked the Lvar value:

3524953 LUA.1: L:AirspeedIndicatedNeedle=86.544639078253

Idem, for the airspeed, we have 14 figures, always positive. So, logically => 16bit, unisgned.

So I tried with offset 66c8,

while 1 do
IAS = ipc.readLvar("L:AirspeedIndicatedNeedle")
ipc.writeUW(0x66c8, IAS)
ipc.sleep(100)
end

But it doesn't work... After, I tried with other offset (66C1, 66C2, 66FF,...) always same thing.

But, to bsure that my script is good, I tried to delete the RPM script in offset 66c0, to put the airspeed in offset 66c0, and... that's work!! 

 

So my problem now is only from the offset. I'm not sure I understand everything about offset... Could you give me a little help? 

Thank a lot,

best regard

Share this post


Link to post
Share on other sites
1 hour ago, AurelienF38 said:

Idem, for the airspeed, we have 14 figures, always positive. So, logically => 16bit, unisgned.

But 14 decimal digits, where each digit can go from 0 to 9. A 16-bit word has 16 binary digits, with each digit going only from 0 to 1. 

So the range of numbers your 16-bit Unsigned Word (UW) can handle is 0-65535.

I am pretty sure that your value of 86.54463907825 will be written as 86 or maybe 87 (I don't remember if it is rounded, but probably).

So, what is your Arduino or whatever expecting to read? Maybe it wants the double floating point format which 86.54463907825 would suit? For that you use 8 bytes and ipc.writeDBL. Or perhaps it needs a 32-bit floating point value, in which case use ipc.writeFLT. You need to know what the receiver is expecting!

"Offsets" are just places in memory, where stuff like data can be stored.  Nothing magic. They don't do any work. In your case they are just being used as postboxes.

Pete

 

 

Share this post


Link to post
Share on other sites

Oh sorry... I mixed every thing between decimal and binary!!...

 

Yes you are right, speed value is rounded. 

Mobiflight use the rounded value, so for the speed, 0 to ~ 200 knots wich gives in decimal 0 to 11001000 so 8 bit, unsigned.

 

So if I use the offset 66c0, for the airspeed gauge, wich use 8 bit=1 byte, the next free offset should be... 66c0 + 1 byte =  66c1= the next free offset wich can be use.

That's all right?

 

Thank you,

Aurelien

Share this post


Link to post
Share on other sites

Hi Pete,

I have progressed!

First, I modified the script, for IAS, 8 bit, so ipc.writeUB, on offset 66c0. Test: all right, it works.

Next, I added the script for RPM, 16 bit, so ipc.writeUW, on offset 66c1; Test: negatif. Always ok for the IAS, but no value receive for the RPM.

This is the script:

-- test battery
battery = ipc.readUB(0x3340)
if battery > 0 then	
ipc.writeLvar("L:Battery1Switch",1)
else
ipc.writeLvar("L:Battery1Switch",0)
end


-- test IAS
while 1 do
IAS = ipc.readLvar("L:AirspeedIndicatedNeedle")
ipc.writeUB(0x66c0, IAS)
ipc.sleep(100)
end


-- test RPM 
while 1 do
RPM = ipc.readLvar("L:Eng1_RPM")
ipc.writeUW(0x66c1, RPM)
ipc.sleep(100)
end

 

So I decided to switch the positions of these scripts: and that is the problem!!: now, I haved value for RPM on 66c1, but no for IAS on 66c0!

the script:

-- test battery
battery = ipc.readUB(0x3340)
if battery > 0 then	
ipc.writeLvar("L:Battery1Switch",1)
else
ipc.writeLvar("L:Battery1Switch",0)
end

-- test RPM 
while 1 do
RPM = ipc.readLvar("L:Eng1_RPM")
ipc.writeUW(0x66c1, RPM)
ipc.sleep(100)
end

-- test IAS
while 1 do
IAS = ipc.readLvar("L:AirspeedIndicatedNeedle")
ipc.writeUB(0x66c0, IAS)
ipc.sleep(100)
end

So I have understood that only the first script is reading in the script!

After, I have tried to do 2 script .lua:

on first for battery (3340) and IAS (66c0)

on second for alternator (3344) and RPM (66c1)  => and now, it works for the two gauges i same time! Because there is on 2 differents script!

 

Do you know if it's possible to write theses script on the same .lua text? Maybe I forgot something between the two script?

 

Thank you for your help,

Aurelien

Share this post


Link to post
Share on other sites

In your scripts you have infinite loops, so the first loop, eg

Quote

-- test RPM 
while 1 do
    RPM = ipc.readLvar("L:Eng1_RPM")
    ipc.writeUW(0x66c1, RPM)
    ipc.sleep(100)
end

will never end, and so the second loop (while) will never be reached. Thats why they work in separate scripts but not together. If you want them in one script, you could try a single loop, e.g. something like

-- test RPM and IAS
while 1 do
    RPM = ipc.readLvar("L:Eng1_RPM")
    ipc.writeUW(0x66c1, RPM)
    ipc.sleep(50)
    IAS = ipc.readLvar("L:AirspeedIndicatedNeedle")
    ipc.writeUB(0x66c0, IAS)
    ipc.sleep(50)
end

Better still, look into using the  'event.lvar()' libarary function and have two functions that get called only when the lvar changes (see the FSUIPC Lua Library.pdf, page 26).

Cheers,

John

 

Share this post


Link to post
Share on other sites

Thank you, 

 

 

I had just found the mistake! I had the idea to be one as you suggested, and it works! ... Now I will look with "event.Lvar ()" function

 

Regards,

Aurelien

Share this post


Link to post
Share on other sites

Hi John,

I tried to use the library "event.Lvar()" but there is nothing when Lvar change, even if I switch some thing like battery.

I tried with this code:

while 1 do
    RPM = event.Lvar("L:Eng1_RPM")
    ipc.writeUW(0x66c1, RPM)
    ipc.sleep(100)
    IAS = event.Lvar("L:AirspeedIndicatedNeedle")
    ipc.writeUB(0x66c0, IAS)
    ipc.sleep(100)
end

thank you,

Regards

Aurelien

Share this post


Link to post
Share on other sites
1 hour ago, AurelienF38 said:

tried to use the library "event.Lvar()" but there is nothing when Lvar change, even if I switch some thing like battery.

You need to specify which LVar you want the event to trap. It doesn't keep scanning all of them just in case! That would slow your system right down!

Pete

 

 

Share this post


Link to post
Share on other sites

Sorry Pete but I dont' understand;

I made it very clear the Lvar between the () after "event.Lvar". 

If I understand correctly, it is not enough to just replace ipc.readLvar by event.Lvar?

I tried with "function", with thirs code, but it doesn't work

function(Eng1_RPM, value)
event.Lvar("L:Eng1_RPM", 100, Eng1_RPM)
ipc.writeUW(0x66c0, Eng1_RPM)
end

 

Share this post


Link to post
Share on other sites

It's OK, I finded the good script and removed everything before.

This is my script; and it's loaded as soon as RPM value change! thanks!

function RPM (Lvarname,value)
	ipc.writeUW(0x66C0,value)
end

RPM ("Eng1_RPM",ipc.readLvar("Eng1_RPM"))

event.Lvar("Eng1_RPM",100,"RPM")

😉

Share this post


Link to post
Share on other sites

I still have a problem...

The code is ok, and work great for RPM.

So I put a second Lvar, on the same script:

-- definition des fonctions
function RPM (Lvarname,value)
	ipc.writeUW(0x66C0,value)
end

function VSI (Lvarname,value)
	ipc.writeSW(0x66C3,value)
end

-- lecture des Lvar
RPM ("L:Eng1_RPM",ipc.readLvar("L:Eng1_RPM"))
VSI ("L:VerticalSpeed",ipc.readLvar("L:VerticalSpeed"))

-- surveillance des changements de valeur
event.Lvar("L:Eng1_RPM",100,"RPM")
event.Lvar("L:VerticalSpeed",100,"VSI")

but there is no value for vertical speed...

I tried to do one separate script for vertical speed, but it doesn't work too... it's weird.

Do you have any idea?

Thank you

Aurelien

Share this post


Link to post
Share on other sites
2 hours ago, AurelienF38 said:

tried with "function", with thirs code, but it doesn't work


function(Eng1_RPM, value)
event.Lvar("L:Eng1_RPM", 100, Eng1_RPM)
ipc.writeUW(0x66c0, Eng1_RPM)
end

That's because the Lua syntax is all wrong. Please do refer to the Lua library document when using this facility.  Even if you "found" a working example elsewhere since, i need to point out the errors in this short script:

function(Eng1_RPM, value)

-- The correect syntax, as clearly documented is (for a function named, say "RPM1")
function RPM1(name,value)

event.Lvar("L:Eng1_RPM", 100, Eng1_RPM)

 -- First, placed in the function, it will only do anything when the function is called. But how can it be when there's no event for it?.
-- Second, the function name (the one being called) is a string and needs "...". So:
event.Lvar("L:Eng1_RPM", 100, "RPM1")
-- but placed at the end of the script

ipc.writeUW(0x66c0, Eng1_RPM)

-- The value returned you've called value. The Eng1_RPM would be replaced by the name of the LVar, as a string (i.e. "Eng1_RPM").

Please do not try to "wing it". Refer to the documentation!  That is what it is for. It would save both of us a lot of time!

Also, when testing a Lua plug-in, when it doesn't work CHECK THE FSUIPC log file. If there are errors stopping it running (as in this case) this will be logged.

29 minutes ago, AurelienF38 said:

there is no value for vertical speed...

I tried to do one separate script for vertical speed, but it doesn't work too... it's weird.

Do you have any idea?

Does the Lvar monitring plug-in provided in the Lua example plug-ins ZIP show proper values for that LVar name? That's your check.

Also, as just stated always check the Log for errors.

Pete

 

Share this post


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

That's because the Lua syntax is all wrong. Please do refer to the Lua library document when using this facility.  Even if you "found" a working example elsewhere since, i need to point out the errors in this sho script:

function(Eng1_RPM, value)

-- The correect syntax, as clearly documented is (for a function named, say "RPM1")
function RPM1(name,value)

event.Lvar("L:Eng1_RPM", 100, Eng1_RPM)

 -- First, placed in the function, it will only do anything when the function is called. But how can it be when there's no event for it?.
-- Second, the function name (the one being called) is a string and needs "...". So:
event.Lvar("L:Eng1_RPM", 100, "RPM1")
-- but placed at the end of the script

ipc.writeUW(0x66c0, Eng1_RPM)

-- The value returned you've called value. The Eng1_RPM would be replaced by the name of the LVar, as a string (i.e. "Eng1_RPM").

Please do not try to "wing it". Refer to the documentation!  That is what it is for. It would save both of us a lot of time!

Also, when testing a Lua plug-in, when it doesn't work CHECK THE FSUIPC log file. If there are errors stopping it running (as in this case) this will be logged.

Does the Lvar monitring plug-in provided in the Lua example plug-ins ZIP show proper values for that LVar name? That's your check.

Also, as just stated always check the Log for errors.

Pete

 

I understand that my first script was all wrong. That's why I had search to correct this, and I have find a good script few minutes later.

Excuse me to had put my wrong script directly before to find an answer...
 

I don't understand what you mean with the lvar monitoring pulg-in? If your question is: does Lvar "L:VerticalSpeed" is the good Lvar for vertical speed, yes it is. Anyway, it work with my first script "while 1 do ... ipc.readLvar...end"

This script woked perfectly before, but now, it does not work anymore... 😣

function RPM (Lvarname,value)
	ipc.writeUW(0x66C0,value)
end

RPM ("Eng1_RPM",ipc.readLvar("Eng1_RPM"))

event.Lvar("Eng1_RPM",100,"RPM")

I had check tho Log, but there is no errors visibly...

********* FSUIPC5, Version 5.15 (27th November 2018) by Pete Dowson *********
Running inside Prepar3D v4
Module base=7FFC52C50000
Windows 10 Home 64 Bit reported as Build 17134, Release ID: 1803 (OS 10.0)
Prepar3D.exe version = 4.3.29.25520
Reading options from "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\FSUIPC5.ini"
Checking the Registrations now ...
User Name="Aurelien ..."
User Addr="aurelien@..."
FSUIPC5 Key is provided
WIDEFS7 not user registered, or expired
       16 System time = 09/02/2019 16:50:15
       16 FLT path = "C:\Users\fryau\Documents\Prepar3D v4 Files\"
       16 Using DialogMode
       16 FS path = "C:\Program Files\Lockheed Martin\Prepar3D v4\"
      109 ---------------------- Joystick Device Scan -----------------------
      125 Product= T.16000M
      125    Manufacturer= Thrustmaster
      125    Vendor=044F, Product=B10A (Version 5.0)
      156    GUIDs returned for product: VID_044F&PID_B10A:
      156       GUID= {A07D8400-0B8F-11E9-8001-444553540000}
      156       Details: Btns=16, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R255,U0,V0,X16383,Y16383,Z255
      156 -------------------------------------------------------------------
      172 Device acquired for use:
      172    Joystick ID = 0 (Registry okay)
      172    0=T.16000M
      172    0.GUID={A07D8400-0B8F-11E9-8001-444553540000}
      172 -------------------------------------------------------------------
      188 LogOptions=00000000 00000001
      188 -------------------------------------------------------------------
      188 SimConnect_Open succeeded: waiting to check version okay
      188 Opened separate AI Traffic client okay
      188 ### PDKmodeHelper callback registered!
     2516 Running in "Lockheed Martin® Prepar3D® v4", Version: 4.3.29.25520 (SimConnect: 4.3.0.0)
     2516 Initialising SimConnect data requests now
     2516 FSUIPC Menu entry added
     2516 ... Using Prepar3D with Academic License
     2531 C:\Users\fryau\AppData\Local\Lockheed Martin\Prepar3D v4\Prepar3D_Default.fxml
     2531 C:\Program Files\Lockheed Martin\Prepar3D v4\SimObjects\Airplanes\IRIS Raptor Driver\Raptor.air
    12594 C:\Users\fryau\Documents\Prepar3D v4 Add-ons\A2A\SimObjects\Airplanes\A2A_C172\C172.air
    12625 ### The user object is 'A2A C172R F-GOAP'
    12625 ### Mode is NORMAL
    12938 ### Mode: PAUSE on
    41891 Loading Complete ...
    41922 ### Mode is NORMAL
    42969 User Aircraft ID 1 supplied, now being used
    42969 Aircraft loaded: running normally now ...
    43859 System time = 09/02/2019 16:50:59, Simulator time = 16:50:20 (22:50Z)
    43859 Aircraft="A2A C172R F-GOAP"
    49859 -------------------- Starting everything now ----------------------

 

Share this post


Link to post
Share on other sites
43 minutes ago, AurelienF38 said:

I understand that my first script was all wrong. That's why I had search to correct this, and I have find a good script few minutes later.

Excuse me to had put my wrong script directly before to find an answer...

No, that was good. I thought it would help you, in future or further ventues into Lua plug-ins, to know WHY it was wrong, that was all. sorry if this insulted you!

44 minutes ago, AurelienF38 said:

I don't understand what you mean with the lvar monitoring pulg-in?

If you look in the FSUIPC documents subfolder (where all the odcumentation is, by the way, in case you ever want to look at it),  you will find a ZIP file called something like example lua plug-ins. There's one inside that called "log lvar". If you run that you will get a display on screen of the changes in the LVars associated with your current add-on aircraft.

49 minutes ago, AurelienF38 said:

If your question is: does Lvar "L:VerticalSpeed" is the good Lvar for vertical speed, yes it is. Anyway, it work with my first script "while 1 do ... ipc.readLvar...end"

You never showed me one for the vertical speed.

52 minutes ago, AurelienF38 said:

This script woked perfectly before, but now, it does not work anymore... 😣


function RPM (Lvarname,value)
	ipc.writeUW(0x66C0,value)
end

RPM ("Eng1_RPM",ipc.readLvar("Eng1_RPM"))

event.Lvar("Eng1_RPM",100,"RPM")

I had check tho Log, but there is no errors visibly...

Well, you've changed something else then. Use the plug-in I mentioned to check the LVars and their changes. It's by far the best way to see what is going on.

The log section you posted ends with

    49859 -------------------- Starting everything now ----------------------

Nothing is running before that line in any case, so why post it?

Pete

 

 

Share this post


Link to post
Share on other sites

Thanks Pete,

 

So, yes I have found the Log Lvar.lua, anyway I have define ctrl+F2 for log lua log Lvar and ctrl+F3 for lua kill all to stop the log.

When I use these, I have this file: (I cut the middle, this is all the Lvar as you know, thas why I did not put it just before. I put the begining and the end, unless you want it entirely?) 

FSUIPC5 Key is provided
WIDEFS7 not user registered, or expired
        0 System time = 09/02/2019 19:14:12
        0 FLT path = "C:\Users\fryau\Documents\Prepar3D v4 Files\"
       16 Using DialogMode
       16 FS path = "C:\Program Files\Lockheed Martin\Prepar3D v4\"
      110 ---------------------- Joystick Device Scan -----------------------
      110 Product= T.16000M
      110    Manufacturer= Thrustmaster
      110    Vendor=044F, Product=B10A (Version 5.0)
      125    GUIDs returned for product: VID_044F&PID_B10A:
      125       GUID= {A07D8400-0B8F-11E9-8001-444553540000}
      125       Details: Btns=16, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R255,U0,V0,X16383,Y16383,Z255
      125 -------------------------------------------------------------------
      125 Device acquired for use:
      125    Joystick ID = 0 (Registry okay)
      125    0=T.16000M
      125    0.GUID={A07D8400-0B8F-11E9-8001-444553540000}
      125 -------------------------------------------------------------------
      157 LogOptions=00000000 00000001
      157 -------------------------------------------------------------------
      157 SimConnect_Open succeeded: waiting to check version okay
      157 Opened separate AI Traffic client okay
      157 ### PDKmodeHelper callback registered!
     1735 Running in "Lockheed Martin® Prepar3D® v4", Version: 4.3.29.25520 (SimConnect: 4.3.0.0)
     1735 Initialising SimConnect data requests now
     1735 FSUIPC Menu entry added
     1750 ... Using Prepar3D with Academic License
     1766 C:\Users\fryau\AppData\Local\Lockheed Martin\Prepar3D v4\Prepar3D_Default.fxml
     1766 C:\Program Files\Lockheed Martin\Prepar3D v4\SimObjects\Airplanes\IRIS Raptor Driver\Raptor.air
    17657 C:\Users\fryau\Documents\Prepar3D v4 Add-ons\A2A\SimObjects\Airplanes\A2A_C172\C172.air
    17672 ### The user object is 'A2A C172R F-GOAP'
    17672 ### Mode is NORMAL
    17954 ### Mode: PAUSE on
    46329 Loading Complete ...
    46375 ### Mode is NORMAL
    47594 Aircraft loaded: running normally now ...
    47641 User Aircraft ID 1 supplied, now being used
    48282 System time = 09/02/2019 19:15:00, Simulator time = 11:30:28 (17:30Z)
    48282 Aircraft="A2A C172R F-GOAP"
    54266 -------------------- Starting everything now ----------------------
    55469 Advanced Weather Interface Enabled
    72313 LUA.0: L:vis_WingLeft_TieDown=0
    72313 LUA.0: L:vis_WingRight_TieDown=0
    72313 LUA.0: L:SteamAmount=0
    72313 LUA.0: L:C172Manual=0
    72329 LUA.0: L:FloodLight2Switch=0
    72329 LUA.0: L:FloodLight1Switch=0
    72329 LUA.0: L:GpsOnSwitch=0
    72329 LUA.0: L:AvionicsConfiguration=0
    72329 LUA.0: L:AvionicsElecPower=0
    72329 LUA.0: L:RXP.GNS.WAAS.430.1.POWER=0
    72329 LUA.0: L:RXP.GNS.WAAS.530.1.POWER=0
    72329 LUA.0: L:kma26Nav1Switch=0
    72344 LUA.0: L:kma26Nav2Switch=0
    72344 LUA.0: L:kma26MkrSwitch=0
    72344 LUA.0: L:kma26DmeSwitch=0
    72344 LUA.0: L:kma26AdfSwitch=0
    72344 LUA.0: L:ElecPower=0
    72344 LUA.0: L:Ballpen1vis=1
    72344 LUA.0: L:Ballpen2vis=1
    72344 LUA.0: L:Headphones=0
    72360 LUA.0: L:Steam2Amount=0
    72360 LUA.0: L:PedestalLightSwitch=0
    72360 LUA.0: L:PanelLightSwitch=0
    72360 LUA.0: L:Units=0
(...)
110657 LUA.0: L:LeftBrakePressureGauge=0.00054656377354295
   110688 LUA.0: L:BrakesLeft=0.00054656377354295
   110719 LUA.0: L:RightBrakePressureGauge=0.00027281664088725
   110750 LUA.0: L:BrakesRight=0.00027281664088725
   110782 LUA.0: L:Eng1_Boost=15.949740466501
   110829 LUA.0: L:SuctionPressure=2.3864507716101
   110860 LUA.0: L:Eng1_RPMGauge=610.1352041422
   110891 LUA.0: L:Eng1_FuelPressureGauge=11.926985450414
   110922 LUA.0: L:Eng1_FuelPressure=11.926985450414
   110954 LUA.0: L:InclinometerBall=-0.0001004292963701
   110985 LUA.0: L:SystemCondSelect=7
   111032 LUA.0: L:SystemCondValue=0
   111063 LUA.0: L:Eng1_Hydraulic_Pump_1_cond=0.94995082692357
   111094 LUA.0: L:Eng1_OilPressureGauge=61.499939421486
   111672 LUA: "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\log lvars.lua": killed
   112110 LUA: "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua": killed

On this, the only thing that I notice that intrigues me, it's only 

   111672 LUA: "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\log lvars.lua": killed
   112110 LUA: "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua": killed

while my script with the event.Lvar() function is on a folder name "RPM.lua" in module folder, as C172.Lua

and while my FSUIPC.ini folder has

[LuaFiles]
1=C172
2=log lvars
3=RPM

 

all rest off the lua log file seems normal...

Share this post


Link to post
Share on other sites

I don't know why, but I have somethig like this now in the FSUIPC5.log folder, and I think this is want you expect Pete! 

FSUIPC5 Key is provided
WIDEFS7 not user registered, or expired
   265922 System time = 09/02/2019 21:04:23, Simulator time = 11:31:05 (17:31Z)
   265922 FLT path = "C:\Users\fryau\Documents\Prepar3D v4 Files\"
[Continuation log requested by user]
Running inside Prepar3D v4 on Windows 10
Module base=7FFC4E7E0000
   284281 LUA.0: beginning "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua"
   284281 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:2
   284281 LUA.0: Global: ipcPARAM = 1
   284297 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:3
   284297 LUA.0: Global: battery = 1
   284297 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:4
   284313 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:10
   284328 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:11
   284328 LUA.0: Global: generator = 0
   284328 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:14
   284360 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:21
   284360 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:22
   284360 LUA.0: Global: IAS = 0.010000006788308
   284391 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:23
   284453 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:26
   284453 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:27
   284453 LUA.0: Global: VSI = -4.4963158860615e-05
   284485 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:28
   284547 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:31
   284547 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:32
   284547 LUA.0: Global: TurnFlag = 1
   284547 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:33
   284625 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:36
   284625 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:37
   284625 LUA.0: Global: Fuel_L = 12.731631501994
   284656 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:38
   284719 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:41
   284719 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:42
   284719 LUA.0: Global: Fuel_R = 18.753874975092
   284719 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:43
   284781 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:46
   284781 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:47
   284781 LUA.0: Global: EGT = 506.74032891438
   284781 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:48
   284860 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:21
   284860 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:22
(...)
1633297 LUA.1: beginning "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\RPM.lua"
  1633297 *** LUA Error: C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\RPM.lua:7: unexpected symbol near 'ï'

There is an error effectively. "unexpected symbol near 'ï'

This is my script, I searched a lot but I do not see where there can be an error ... especially since this script was working this morning ...

function RPM (Lvarname,value)
	ipc.writeUW(0x66C0,value)
end

RPM ("Eng1_RPM",ipc.readLvar("Eng1_RPM"))

event.Lvar("Eng1_RPM",100,"RPM")

Thank you for your help,

Aurelien

Share this post


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

On this, the only thing that I notice that intrigues me, it's only 

   111672 LUA: "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\log lvars.lua": killed
   112110 LUA: "C:\Program Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua": killed

while my script with the event.Lvar() function is on a folder name "RPM.lua" in module folder, as C172.Lua

and while my FSUIPC.ini folder has

[LuaFiles]
1=C172
2=log lvars
3=RPM

all rest off the lua log file seems normal...

This part I don't understand:

"while my script with the event.Lvar() function is on a folder name "RPM.lua" in module folder, as C172.Lua"

Why have you named a folder "RPM.lua"?  Such a folder name doesn't make a lot of sense, and FSUIPC won't look for lua plug-ins in such a folder unless you change the path for ALL lua files by adding the parameter LuaPath=<path to lua files> to the [LuaFiles] section of the INI (with the path you wish to use instead of Modules), which you have not done.
  
And you evidently do have a C172.lua file in the Modules folder, possibly without your extra code for the VSI?

2 hours ago, AurelienF38 said:

I don't know why, but I have somethig like this now in the FSUIPC5.log folder, and I think this is want you expect Pete! 

You have enabled Lua logging in the Logging options. That traces through every step. We were only looking for errors in the script which would be reported in ay case

However, now that you have enabled the logging, we see these entries:

2 hours ago, AurelienF38 said:

284453 LUA.0: Global: VSI = -4.4963158860615e-05
284485 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:28
284547 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:31
284547 LUA.0: ...m Files\Lockheed Martin\Prepar3D v4\Modules\C172.lua:32

so it seems after all that the C172.lua in the MODULES folder (NOT the RPM.lua folder as you stated) does contain the VSI code, and a value (-4 in this case) was returned.

The 28, 31 and 32 are line numbers in your lua program.  Now that is more lines than in the last Lua you posted here, so I can't look at those, but you can, and you know now that they were executed and did have the value.

2 hours ago, AurelienF38 said:

There is an error effectively. "unexpected symbol near 'ï'

This is my script, I searched a lot but I do not see where there can be an error ... especially since this script was working this morning ...


function RPM (Lvarname,value)
	ipc.writeUW(0x66C0,value)
end

RPM ("Eng1_RPM",ipc.readLvar("Eng1_RPM"))

event.Lvar("Eng1_RPM",100,"RPM")

Thank you for your help,

You have an unprintable character, that one represented by ï in the log, which is non-ASCII (It's part of the Windows implemented extensions to ASCII, using the 8th bit -- ASCII only uses 7 of the 8 bits in a byte. Lua only handles straight ASCII.

Best to delete that line completely and re-enter it, taking care with the keyboard. Those characters (special ones and those with accents) can be entered with various keyboard press combinations or sequences.

However, you were asking about VSI which was mainly what I was responding to.

When you are writing to offsets you can easily check that the values you expect are being written there by using the "monitor" options in FSUIPC Logging. See the right-hand side. You can monitor up to 4 values at a time. Just enter the offset (just the 66C3 part, not the 0x), and the type (in this case S16, a signed 16-bit or "Word"). Then below select normal log to see the vlaues in the log, or FS window for a display on screen as it changes.

If the values in the offset are correct, then look at your Arduino programming!

Pete

 

Share this post


Link to post
Share on other sites

Hi Pete,

I will try to answer your questions:

/ I had a RPM.Lua folder because yesterday, my script "event.Lvar" for RPM worked only on a separate folder.

/ For the ï character, I had rewrited the script, many times, change his name (C172gauges instead of RMP.lua), but nothing work...

/ I had check the value in the offset, and there was correct.

Now, it's worse... the C172gauges script is not used by FSUIPC. it does not appear in the log file, however, he is mentioned in the FSUIPC.ini...

 

I ask google concerning the error "unexpected symbol near 'ï' ", it could come from the text editor, wich could put hidden special characters. I use Notepad++, and the coding use is UTF-8 (without BOM).

 

All this makes me waste a lot of time...and your tim too..., while finally the script with the form "while 1 do ... ipc.readLvar, ipc.write..." work perfectly...

How is the use of "event" better for you? Because, interfacing a cessna, I finally have not a lot of variable to interface, it would not be enough with this form of script? There is some "limits"?

 

thank you for your help. Sorry if I'm stuck. It's incomprehensible for me, but it worked yesterday morning, but it's impossible to redo this "event.Lvar"

 

Aurelien

Share this post


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

I had a RPM.Lua folder because yesterday, my script "event.Lvar" for RPM worked only on a separate folder.

Without telling FSUIPC to load from that folder it wouldn't have run -- unless you explicity loaded it from that folder using an ipc.runlua function in a Lua which was loaded from the Modules folder!

4 hours ago, AurelienF38 said:

I had check the value in the offset, and there was correct.

It that case it is evidently a problem with your Arduino programming.

4 hours ago, AurelienF38 said:

Now, it's worse... the C172gauges script is not used by FSUIPC.

That is a different script from any other you've mentioned or shown.

4 hours ago, AurelienF38 said:

it does not appear in the log file, however, he is mentioned in the FSUIPC.ini...

The LuaFiles section lists all Lua files which have ever been seen in the Modules folder. It doesn't mean it is still there or that you are running it!

4 hours ago, AurelienF38 said:

How is the use of "event" better for you?

It isn't better for me. It is just more sensible as then the processor is not wasting time executing your script, but simply sitting waiting for the LVars to change. And the suggestion is very sensible. Most of the best and most relicable scripts these days use events for that reason. But it was a later addition to the Lua facilities in FSUIPC, which is why there are examples of both still abounding.

I actually think since then you've been confusing yourelf and me posting contradictory messages many times. The VSI one for instance was never mentioned before you said it didn't work any more, and then this iall the wrong assumptions you make ad repeat like that concerning folders and script names.

I don't need to  try to help any more -- just don't post! 😉

 

Pete

 

Share this post


Link to post
Share on other sites

 

I completely agree with you, Pete, I stubborn this weekend and accumulated mistakes.

After a 48-hour break, I leaned over the problem, and I started all over again. It's good, tonight, my event.lvar scripts work, for all the gauges of the cessna cockpit. 😉

The only thing that does not happen is the launch of the script independently. To do this, I assigned a switch.

Thank you for your time.

 

Aurelien

Share this post


Link to post
Share on other sites
47 minutes ago, AurelienF38 said:

After a 48-hour break, I leaned over the problem, and I started all over again. It's good, tonight, my event.lvar scripts work, for all the gauges of the cessna cockpit. 😉

Good. well done.

47 minutes ago, AurelienF38 said:

The only thing that does not happen is the launch of the script independently. To do this, I assigned a switch.

If you want the Lua to be launched with the start of FSUIPC you need to add the section to the FSUIPC INI file:

[Auto]
1=Lua <name of your lua file>

Or you can have an ipcReady.lua file in the modules folder whhich containas the line:

ipc.runlua("<name of your lua file>")

ipcReady.lua is executed automatically when FSUIPC detects that the Sim is "ready to fly".

Pete

 

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
Sign in to follow this  

×

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.