Jump to content
The simFlight Network Forums

VRInsight MCP Combo and FSUIPC Lua scripting


prokopiu

Recommended Posts

Hi all,

having a week off after Easter gave me some time to start a little project of documenting all the findings and results of me using FSUIPC and Lua scripting to connect all kinds of aircraft with my VRInsight MCP Combo. I found a way to do this without virtual serial ports or SerialFP and learnt an awfull lot on the way there. Time to document this in a growing topic. First installment is the setup of FSUIPC and VRInsight hardware to talk directly to each other.

The attached PDF documents this approach and the text file is a sample for that kind of lua script I am talking about.

In the coming days and weeks I will add more to this thread, also going into more details about individual planes from PMDG to Level-D and so forth for which I have collected quite some details about how to connect something like the MCP Combo to them. The knowledge here can also be applied to the Go-Flight MCP - you probably have to change some aspects of the scripts though as one connects differently to the Go-Glight stuff.

Kosta

VRInsight_MCP_and_FSUIPC_V10.pdf

Other_VRIH.lua.txt

Link to comment
Share on other sites

The next step with having the Lua script work with my MCP Combo is to be able to automatically start the appropriate Lua script for each individual airplane. There seem to be some ways to do this, the most flexible I found was to use Lua scripting again and facilitate the Lua macros (pretty much like you would when selecting something in the drop-downs for key or button assignments).

In Lua there is the ipc.macro("name of macro") with which one can start, re-start or kill a running Lua script. Perfect for me.

For example, having the Other_VRIH.lua file from my previous post I could start it by using the line:

ipc.macro("Lua Other_VRIH")

If I want to stop it because I would like to call another one (for another aircraft) I can use:

ipc.macro("LuaKill Other_VRIH")

In combination with the name of the currently loaded aircraft coming from the FSUIPC offset 0x3D00 I can start and switch VRInsight Handler Luas whenever I switch airplanes in FSX.

Since the names of several variations (textures) of FSX planes usually start with the same text you can start the same lua script by providing the common part of the name (e.g. "Level D Simulations B767" covering all available types).

I have my current version of the dispatcher Lua attached here.

Make sure it gets started when FSX starts. It will take care of the rest then.

Kosta

LuaDispatcher.lua.txt

Link to comment
Share on other sites

Next part is displaying A/P values and handling radios:

The VRInsight MCP Combo has 2 displays, one in the middle with the Autopilot values (SPD, HDG, ALT) and on the right side the multi-purpose display for the radios. The content of the displays cannot be read by the Lua script - only changed by sending commands via the serial port to the MCP Combo. In order to keep MCP display and real values aligned you need to install an event handler for each value that triggers when the FSX value changes. The corresponding display is then updated by sending a command.

The middle display:

SPD*.... HDG* ALT*

999 .... 999 99999

You can change the following parts:

Value          Command
=========================================
SPD value      SPD999 (speed in kts)
Top .... area  DSP XXXX (XXXX being a 4 character text)
Bottom ....    DSP_XXXX
HDG value      HDG999 (heading 3 digit degree)
ALT value      ALT999 (altitude in thousands of feet)

For many planes the standard FSX offsets work as a source for the values in Lua scripting:

function setAPSPD(offset, value)
  buffer = ipc.readUW(0x07e2)
  com.write(dev, string.format("SPD%03d", buffer),8 )
end

function setAPHDG(offset, value)
  buffer = ipc.readUW(0x07CC)/65536*360
  com.write(dev, string.format("HDG%03d", buffer),8 )
end

function setAPALT(offset, value)
  buffer = ipc.readUD(0x07D4)/65536*3.28/100
  com.write(dev, string.format("ALT%03d", math.ceil(buffer)),8 )
end

The Radio Panel display has two lines for displaying radio values and six mode buttons:

[LINE 1                   ]
[LINE 2                   ]

 [ ]  [ ]  [ ]  [ ]  [ ] 
 COM  NAV  ADF  DME  TRN

Commands to be used:

Command                Display
============================================
COMSEL1                COM1 frequencies
COMSEL2                COM2 frequencies
NAVSEL1                NAV1 frequencies
NAVSEL2                NAV2 frequencies
ADFSEL1                ADF1 frequency
ADFSEL2                ADF2 frequency
DMESEL1                Display DME1 dist/speed
DMESEL2                Display DME2 dist/speed
TRNSEL                 Transponder display

COMs9999               Set COM1 standby freq 199.99
COMx9999               Set COM1 active frequeny 199.99
COMS9999               Set COM2 standby freq 199.99
COMX9999               Set COM2 active frequeny 199.99
NAVs9999               Set NAV1 standby freq 199.99
NAVx9999               Set NAV1 active frequeny 199.99
NAVS9999               Set NAV2 standby freq 199.99
NAVX9999               Set NAV2 active frequeny 199.99
ADF99999               Set selected ADF frequency to 9999.9
TRN9999                Set transponder display to 9999
DMiAAAA                Set DME1 VOR name to AAAA
DMEd9999               Set DME1 distance to 999.9 NM
DMEs999                Set DME1 speed to 999 KT
DMIAAAA                Set DME2 VOR name to AAAA
DMED9999               Set DME2 distance to 999.9 NM
DMES999                Set DME2 speed to 999 KT  

In Lua scripting one needs to get these values from their respective FSUIPC offsets. Most planes use the FSX standard offsets so the code lines here work almost all the time:

function setCOM1Radio(offset, value)
    buffer = ipc.readUW(0x034E)
    com.write(dev, string.format("COMx%04x", buffer),8 )
    ipc.sleep(500)
    buffer = ipc.readUW(0x311A)
    com.write(dev, string.format("COMs%04x", buffer),8 )
end

function setCOM2Radio(offset, value)
    buffer = ipc.readUW(0x3118)
    com.write(dev, string.format("COMX%04x", buffer),8 )
    ipc.sleep(500)
    buffer = ipc.readUW(0x311C)
    com.write(dev, string.format("COMS%04x", buffer),8 )
end

function setNAV1Radio(offset, value)
    buffer = ipc.readUW(0x0350)
    com.write(dev, string.format("NAVx%04x", buffer),8 )
    ipc.sleep(500)
    buffer = ipc.readUW(0x311E)
    com.write(dev, string.format("NAVs%04x", buffer),8 )
end

function setNAV2Radio(offset, value)
    buffer = ipc.readUW(0x0352)
    com.write(dev, string.format("NAVX%04x", buffer),8 )
    ipc.sleep(500)
    buffer = ipc.readUW(0x3120)
    com.write(dev, string.format("NAVS%04x", buffer),8 )
end

function setADF1Radio(offset, value)
    buffer = ipc.readUW(0x034C)
    buffer2 = ipc.readUW(0x0356)
    com.write(dev, string.format("adf%01x%03x%01x", buffer2/256, buffer, buffer2 % 0x0100),8 )
end

function setADF2Radio(offset, value)
    buffer = ipc.readUW(0x02D4)
    buffer2 = ipc.readUW(0x02D6)
    com.write(dev, string.format("ADF%01x%03x%01x", buffer2/256, buffer, buffer2 % 0x0100),8 )
end

function setTransponder(offset, value)
    buffer = ipc.readUW(0x0354)
    com.write(dev, string.format("TRN%04x", buffer),8 )
end

In order to keep the displays updated and in synch, event listeners are added at the end of the lua script to be triggered whenever one of the offsets change. So when you or the FMC changes the NAV1 frequency, the event is recognized and the setNAV1Radio function is called.

The events are declared like that:

-- listen to changes of the Radions
event.offset(0x034E, "UW", "setCOM1Radio")
event.offset(0x311A, "UW", "setCOM1Radio")
event.offset(0x3118, "UW", "setCOM2Radio")
event.offset(0x311C, "UW", "setCOM2Radio")
event.offset(0x0350, "UW", "setNAV1Radio")
event.offset(0x311E, "UW", "setNAV1Radio")
event.offset(0x0352, "UW", "setNAV2Radio")
event.offset(0x3120, "UW", "setNAV2Radio")
event.offset(0x034C, "UW", "setADF1Radio")
event.offset(0x0356, "UW", "setADF1Radio")
event.offset(0x02D4, "UW", "setADF2Radio")
event.offset(0x02D6, "UW", "setADF2Radio")
event.offset(0x0354, "UW", "setTransponder")

To detect changes to the frequency entered in the MCP you need to detect the VRI event (the action code sent by the MCP) and react accordingly. Sample for COM1 and ADF2:

  
  -- detect the change of standby freq
	if string.match(str, "COMs(%d%d%d%d)") then
	  comfreq = tonumber(string.match(str, "COMs(%d%d%d%d)"),16)
      ipc.writeUD(0x311a, comfreq)
	end

  -- detect the transfer of standby to active frequency
	if string.match(str, "COMx(%d%d%d%d)") then
	  ipc.control(66372)
	end

  -- detect what ADF has been selected
 	if str == "ADFSEL1" then
	  ipc.set("adfsel",1)
	end

  -- detect what ADF has been selected
	if str == "ADFSEL2" then
	  ipc.set("adfsel",2)
	end

  -- set ADF frequency based on two offsets
	if string.match(str, "ADF(%d%d%d%d%d)") then
	  comfreq = tonumber("0x0" .. string.sub(str, 5,7), 16)
	  adffreq = tonumber("0x0" .. string.sub(str, 4,4) .. "0" .. string.sub(str,8,8 ),16)
	  if (ipc.get("adfsel") == 1) then
	    ipc.writeUD(0x034C, comfreq)
	    ipc.writeUD(0x0356, adffreq)
	  else
	    ipc.writeUD(0x02D4, comfreq)
	    ipc.writeUD(0x02D6, adffreq)
	  end
	end

Kosta

Link to comment
Share on other sites

  • 2 months later...

Hi,

a couple of months later and I have actually moved to the next level thanks to a simmer/programmer called Artem Crum. He developed LINDA which is a great way of assigning those Lua scripts one has found with a Joystick or the MCP Combo. I helped testing it and also created a profile for one of the planes /more are actually in the queue but I had not yet time enough to test them).

Some of what I explained here applies in LINDA as well and if you cannot find your addon in the ever growing list of supported planes then you can use that great editor in LINDA and creat your own scripts.

See http://fs-linda.com/ for more.

Kosta

Link to comment
Share on other sites

  • 8 months later...

Im not a programmer or computer expert and sorry if this question was asked before, but as fsuipc, LINDA is one of the best tools ever being created for us the simmers (thanks to Pete and Artem). I am a mcp combo (vrinsight) user and will be nice to have the possibility to use this wonderfull tool for a more stable platform as FS2004. As fsuipc; why is not possible to have it?

Thank you

Link to comment
Share on other sites

Not that its really relevant for the topic at hand but to answer your question its simply because Artem does not use or have any interest in FS2004 anymore. Artem made LINDA mainly for his own personal use and then expanded on its features at a later date when he was convinced by others to release it to the public, he has basically finished the project now and has moved on to other things.

Link to comment
Share on other sites

  • 10 years later...
On 3/25/2012 at 12:39 PM, Andydigital said:

Not that its really relevant for the topic at hand but to answer your question its simply because Artem does not use or have any interest in FS2004 anymore. Artem made LINDA mainly for his own personal use and then expanded on its features at a later date when he was convinced by others to release it to the public, he has basically finished the project now and has moved on to other things.

Does this work with msfs, and the fbw a320?

Link to comment
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
×
×
  • 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.