Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello,

i need help with programming a LUA Plugin for my VRI MCP and Project Magenta MCP.

The Problem is the PM MCP displays not the SPEED, HDG and ALT Values from the VRI MCP.

When i turn the SPD knob on the VRI MCP the display on the VRI MCP shows .. lets say 150, but the PM MCP Displays 100.

The Values are not equal every time.

The example LUA for the Speed seems to be working, but i need help for the other, HDG and ALT Values.

Can anyone help?

thanks

flusie

Posted

a basic question: Must i restart the FS if i take any changes in the LUA script file?

At the Moment i have added 2 new Filters:

[VRInsight.FMER]
Lua=VRI_SetMach
DriverWrites=Filter
WrFilter.1=SPD?
WrFilter.2=SPDOF
WrFilter.3=SPDON
WrFilter.4=HDG?
DriverReads=Filter
[b]RdFilter.1=SPD?+
RdFilter.2=HDG?+[/b]

and added this lines to the VRI_SetMach.lua file

function settofs(handle, str)
	-- need to check only for SPDnnn+/- and send speed or mach to FS
	speed = tonumber(string.match(str, "SPD(%d%d%d)"))
	if speed ~= nil then
			if machmode then
					speed = speed * 655.36
					ipc.writeUD(0x7e8, speed)
			else
					ipc.writeUW(0x7e2, speed)
			end
	end

	-- need to check only for HDGnnn+/- and send HDG to FS
	hdg = tonumber(string.match(str, "HDG(%d%d%d)"))
	if hdg ~= nil then
			hdg = hdg * 655.36 / 3.60
			ipc.writeUD(0x7CC, hdg)

	end	
	ipc.log("HDG=" .. hdg)
end

setmchmode(0x7e4, ipc.readUD(0x7e4))
setspdmode(0x7dc, ipc.readUD(0x7dc))

event.offset(0x7e2, "UW", "setspeed")
event.offset(0x7e8, "UD", "setmach")
event.offset(0x7e4, "UD", "setmchmode")
event.offset(0x7dc, "UD", "setspdmode")

event.offset(0x7CC, "UW", "setHDG")
event.VRIread(dev, "settofs")

is this the correct way?

flusie

Posted
a basic question: Must i restart the FS if i take any changes in the LUA script file?

Yes, in the normal form, because the Lua file is designed to get its COM port numbers supplied by the automatic loading dictated by the [VRInsight ...] section in the INI. This won't happen if it is being run by, for example, assignment to a key press.

But for development and testing you can do what I do. Define the VRIdriver and VRIdevice values in the program. If you look near the beginning of the VRU_SetMach.lua supplied in the examples you will see this:

if VRImodel == nil then
   -- Set known ports if testing with Lua not loaded automatically
   VRIdriver = "COM2"
   VRIdevice = "COM5"
end

In my case the COM ports were 2 and 5. You'll need to set these for your setup. The VRImodel value is nil if the Lua is started manually, so these are set automatically. Program a keypress or button to run the Lua program and just re-run it each time you make a change you want to test.

At the Moment i have added 2 new Filters:

...

and added this lines to the VRI_SetMach.lua file

Before we go further I notice you are using FS autopilot offsets. They aren't correct for the Project Magenta MCP. You'll need to go to the PM website and get the list of PM offsets. This will be the case for speed, mach, heading, altitude and V/S. You'll only use FS offsets for the two course displays (OBS1 and OBS2).

Otherwise you look like you are getting the hange of things. Check out the PM stuff and by all means come back if you get stuck.

Regards

Pete

Posted

Hello,

ok, i will check the PM Offsets.

But one question until i can go forward:

I need to update only SPD, HDG and ALT. Can i do this with only one LUA-File or must i take 3 different files with 3 different filters?

I have attached the files if you want take a quick view on it.

The Filer for the both files are inside the lua files on top.

Is this notation correct to load the both files?

[VRInsight.FMER]
Lua=MCP_HDG
DriverWrites=Filter
WrFilter.1=HDG?
DriverReads=Filter
RdFilter.1=HDG?+
Lua=MCP_SPD
DriverWrites=Filter
WrFilter.1=SPD?
DriverReads=Filter
RdFilter.1=SPD?+

Thanks for the Help

Matthias

MyTest.rar

Posted
H

I need to update only SPD, HDG and ALT. Can i do this with only one LUA-File or must i take 3 different files with 3 different filters?

The one Lua. There are no facilities to have more than one automatically run from each [VRInsight ...] device section, though the Lua being run could start other Lua plugins if it needed to -- but i don't see the point. They wouldn't inherit access to the COM devices.

Is this notation correct to load the both files?

No. You cannot do it. surely you must have tried it and found this out? Just do everything in the one Lua program.

Incidentally, the FSUIPC INI file is like all Windows INI and CFG files -- each parameter line has a unique identifier left of the "=". I don't know what Windows does when there are more -- it might ignore the later ones, or the later ones might override the earlier ones. The FS CFG files have the same restriction.

Regards

Pete

Posted

Hello,

ok, so i need only one event in the LUA File for any event from the MCP:


function setMCP_TO_PM(handle, str)
	-- need to check only for SPDnnn+/- and send speed or mach to PM
	speed = tonumber(string.match(str, "SPD(%d%d%d)"))
	if speed ~= nil then
		speed = speed * 655.36
		ipc.writeUD(0x7e8, speed)
	end
end

event.VRIread(dev, "setMCP_TO_PM")

And this are the 3 PM Offsets for me:

5406

2

MCP/FCU IAS Set (Write)

5408

2

MCP/FCU Heading Set (Write)

540A

2

MCP/FCU Altitude Set (Write)

so i have to change this line

ipc.writeUD(0x7e8, speed)

to this

ipc.writeUD(5406, speed)

Am i right here?

Sorry, but for the one i need a litle bit more help

Thanks

Matthias

Posted

Sorry,

can you please explain how the LUA file must show if i want to test it outside of the FSX?

I have tried this test file

-- test_1.lua


if VRImodel == nil then
   -- Set known ports if testing with Lua not loaded automatically
   VRIdriver = "COM2"
   VRIdevice = "COM5"
end

speed = 115200 -- is this the same for all VRI devices?
handshake = 0  -- No handshake
minsize = 8
maxsize = 8    -- VRI seems to use fixed length blocks of 8 bytes

hdg_1 = "HDG123+"
hdg_2 = "HDG124++"

dev = com.open(VRIdevice, speed, handshake)

if dev == 0 then
   ipc.log("Could not open VRIdevice port")
   ipc.exit()
end

print(hdg_1)
nbr = tonumber(string.match(hdg_1, "HDG(%d%d%d)"))
print("nbr: " .. nbr)
str = string.format("HDG%03d", nbr)
print("str: " .. str)

io.read()

but i earn an error in Line 18

"lua: test_1.lua:18: attempt to index global 'com' (a nil value)"

Matthias

Posted

ok, so i need only one event in the LUA File for any event from the MCP

Yes, but you also want an event for each offset which you want to update your displays with. See the "VRI_Setmach" plug-in example. There are events there for all the FS offsets which affect the speed display. You'd need to change those for PM and add ones for heading, altitude, and V/S.

And this are the 3 PM Offsets for me:

5406

2

MCP/FCU IAS Set (Write)

5408

2

MCP/FCU Heading Set (Write)

540A

2

MCP/FCU Altitude Set (Write)

Yes, and 540E for Mach. The mach or IAS mode would have to be read from PM too. Not sure where off-hand.

These offset would be for setting the values (i.e. writing to PM). For reading the values in order to update the MCP display you need to read 04E0, 04E2 etc, as documented in the PM list. So, for Events to update your displays you use the 04xx values, for setting the MCP you use the 54xx values.

Also, though it doesn't say so against 540A, I think the altitude is in 100's of feet as it is for 04E4 (and the V/S, in 04E6 and 540C).

so i have to change this line

ipc.writeUD(0x7e8, speed)

to this

ipc.writeUD(5406, speed)

No, not 5406, 0x5406. All the offsets listed in the PM document are hexadecimal, as they are in my lists.

Regards

Pete

Posted

Ahhh, ok, thanks, i will test it outside of the FS.

At the moment i must restart the FSX for every Code changes to test.

Pls. Can you explain how the test file must show if i want to use it outside of the FS?

( as i write in the last post)

So it is easyer for me to test with the events and offsets.

Thanks

a lot

Matthias

Posted
Ahhh, ok, thanks, i will test it outside of the FS.

How? you cannot do that! It is entirely dependent upon FSUIPC and FS data!

At the moment i must restart the FSX for every Code changes to test.

Because you've not used those additional Lua lines I pointed out, the ones already in the VRI_SetMach example? You only had to change the COM port numbers to match those you are using.

Pls. Can you explain how the test file must show if i want to use it outside of the FS?

( as i write in the last post)

You can't. Just assign a button or keypress to run it, and use that to rerun it after each change. There's no need to keep restarting FS! I did explain all this a while back in this thread -- did you miss it?

Pete

Posted

Hello,

i dont know if understand correct, sorry.

You can't. Just assign a button or keypress to run it, and use that to rerun it after each change. There's no need to keep restarting FS! I did explain all this a while back in this thread -- did you miss it?

You mean i can take any changes in the LUA file and save it ( FSX is running ) and after that i push the SPD or HDG Knob on the MCP again and the changes take effect?

Understand i correct?

I mean not.

I have read in your documentation about LUA Plugins "LUA Plugins for VRInsight Devices.pdf"

All this part is doing is allowing me to run the plug-in separately, without the automatic loading in FSUIPC INI. I assigned one keypress to "Lua VRI_SetMach" and another to "LuaKill VRI_SetMach" so I could run tests and keep changing it till it worked properly (yes, things don't always work properly first time!).

Thats what i trying to do.

Right click on the "test_1.lua" File and then select Edit Script.

The LUA SCITe opens. Then i want to start the Script from here.

Matthias

Posted

You mean i can take any changes in the LUA file and save it ( FSX is running ) and after that i push the SPD or HDG Knob on the MCP again and the changes take effect?

Understand i correct?

No. you have to get the Lua program to re-run. To do that simply assign any keypress or joystick button to that Lua program, so you can re-run it any time by pressing the button or keypress!

All Lua programs show up as assignable in the FSUIPC assignment drop downs -- that's the whole point, and the normal way they are ryun!

All this part is doing is allowing me to run the plug-in separately, without the automatic loading in FSUIPC INI. I assigned one keypress to "Lua VRI_SetMach" and another to "LuaKill VRI_SetMach" so I could run tests and keep changing it till it worked properly (yes, things don't always work properly first time!).

Thats what i trying to do.

So what is stopping you?

Right click on the "test_1.lua" File and then select Edit Script.

The LUA SCITe opens. Then i want to start the Script from here.

There's no editor in FSUIPC. The plug-ins can only run in FSUIPC. Only FSUIPC can start them. I really don't understand how you have become so confused.

Of course you can keep your editor open whilst you test, but there is no editor which sends a keypress or button press to FSUIPC!!

Pete

Posted

Hello,

ah, now i understand how to restart the LUA Plugin...thanks and sorry for not understanding you.

But at the moment i have the File ready for me.

All works perfekt, and for understanding: I only need to set the PM SPD, HDG and ALT Values with the LUA PlugIn. Thats all i need.

For that the file shows like this:

function SetFsToPm(handle, str)
	ipc.log("SetFsToPm=" .. str)
	if string.match(str, "SPD") ~= nil then
		speed = tonumber(string.match(str, "SPD(%d%d%d)"))
		ipc.writeUD(0x5406, speed)
		--ipc.log("   --> SPD=" .. speed)
	end

	if string.match(str, "HDG") ~= nil then
		hdg = tonumber(string.match(str, "HDG(%d%d%d)"))
		ipc.writeUD(0x5408, hdg)
		--ipc.log("   --> HDG=" .. hdg)
	end

	if string.match(str, "ALT") ~= nil then
		alt = tonumber(string.match(str, "ALT(%d%d%d)"))
		ipc.writeUD(0x540A,alt)
		--ipc.log("   --> ALT=" .. alt)
	end
end

event.VRIread(dev, "SetFsToPm")

The Problem here is that :

1. i turn the SPD knob at the MCP. The Values at PM MCP are exact the same as in the MCP Display...OK, fine !!

2. i turn the HDG Knob in the MCP. The Values at the PM MCP are exactly the same as in the MCP DIsplay...fine !!!

But when i now again turn the SPD Knob at the MCP, the HDG Value at the PM MCP displays 000.

Why that?

Matthias

Posted

But at the moment i have the File ready for me.

All works perfekt, and for understanding: I only need to set the PM SPD, HDG and ALT Values with the LUA PlugIn. Thats all i need.

Okayyou don't need the VRi MCP to reflect the MCP values as well?

But when i now again turn the SPD Knob at the MCP, the HDG Value at the PM MCP displays 000.

Why that?

It sounds like you've got some VRi device command wrecking your code. The only way to find out what is going on is to use the logging. Unse the VRi logging additions ot the FSUIPC INI file (Debug=Please and LogExtras=x4) and see what exchanges are truly happening. My bet is you are getting a HDG string which has no number -- maybe a hdg command other than a value. Your lines:

hdg = tonumber(string.match(str, "HDG(%d%d%d)"))
 ipc.writeUD(0x5408, hdg)

have no check that there is indeed a result, so a zero is quite possible. If you check my example, for Speed, I included a check like

if speed ~= nil then ...

before writing an offset with the result.

Regards

Pete

Posted

Hello Pete and all other,

i have ready the Plugin:

--
if VRImodel == nil then
   -- Set known ports if testing with Lua not loaded automatically
   VRIdriver = "COM3"
   VRIdevice = "COM4"
end

speed = 115200 -- is this the same for all VRI devices?
handshake = 0  -- No handshake
minsize = 8
maxsize = 8    -- VRI seems to use fixed length blocks of 8 bytes

dev = com.open(VRIdevice, speed, handshake)

spd = 0
hdg = 0
alt = 0

function SetFsToPm(handle, str)

end

function displayVars()
	--ipc.display("SPD: " .. spd .. "\nHDG: " .. hdg .. "\nALT:" .. alt)

	ipc.writeUW(0x5406, spd)
	ipc.writeUW(0x5408, hdg)	
	ipc.writeUW(0x540A, alt)
end

function setSPD(off,val)	
	spd = val
	displayVars()
end

function setHDG(off,val)
	hdg = (val / 65536 * 360)
	hdg = math.floor(hdg + 0.5)
	displayVars()
end

function setALT(off,val)
	alt = val / 65536 * 3.28084
	alt = math.floor(alt + 0.5)
	alt = alt / 100

	if alt <= 0 then		
		alt = 1
	end

	displayVars()
end

setSPD(0x7e2, ipc.readUW(0x7e2))
setHDG(0x7cc, ipc.readUW(0x7cc))
setALT(0x7d4, ipc.readUD(0x7d4))


-- FSUIPC AP_SPD -- 07E2 2 Autopilot airspeed value, in knots
event.offset(0x7e2, "UW", "setSPD")

-- FSUIPC AP_HDG -- 07CC 2 Autopilot heading value, as degrees*65536/360
event.offset(0x7cc, "UW", "setHDG")

-- FSUIPC AP_ALT -- 07D4 4 Autopilot altitude value, as metres*65536
event.offset(0x7d4, "UD", "setALT")


--event.VRIread(dev, "SetFsToPm")

It holds the PM MCP always congruent to the MCP Displays :-)

Pete: One question:

I anywhere a listing from the "Control sent when Button pressed" actions?

I search for the Transponder ON/OFF action.

Matthias

Posted

I anywhere a listing from the "Control sent when Button pressed" actions?

You mean the "List of FSxxx controls" document, installed alongside all the other documents and Lua stuff when you installed FSUIPC? That lists all of the FS controls that exist. The additional ones added by FSUIPC are listed in the FSUIPC Advanced User's document.

I search for the Transponder ON/OFF action.

There isn't one. FS has never simulated any of the transponder selector switch settings. If you are using Squawkbox or FSInn the FSUIPC added transponder standby/on controls will work (you'll need to update the FS version to the most recent version -- see the Updates and other goodies announcement near the top of this forum).

Regards

Pete

  • 2 weeks later...
Posted
Hello Pete and all other,

i have ready the Plugin:

Matthias

I'm really interested in this topic. I would like to modify the plugin in order to write de AP Modes (VNAV, LNAV, LOC, ...) in the MCP Compo display. Any clue will be appreciated.

@Peter:

In your published "LUA Plugins for VRInsight devices" you wrote:

I am also attempting to put together a complete listing of SerialFP2 output commands for each device. That will follow in due course.

New docs to be readed?

Many thanks in advance and sorry for my poor english

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.