Jump to content

Help needed to connect DCS with a VB program (for input only)


sapounas

Recommended Posts

So my project is:

 

Built a throttle for UH-1.

 

Things that i have:

One USB board with 8 GPIO/4 A-D

 

Situation:

I can write code to capture input from the board with VB .net

 

Problem:

What steps must i follow to send input data from VB program to DCS

(i would like the steps to be like first you write "this" to dcs\io\*.lua . after you do this, then this and if someone could explain theprotocol of the connection)

 

I tried to communicate the lua listener.lua with vb using socket (encoding ASCII) with no result..

 

Sorry if i am so noob, but you know.. it's confusing googling all week...

  • Like 1
Link to comment
Share on other sites

Here's how I do it (using a C# application for IO):

 

1. In my application I created a TCP listener, which runs on port 10309. This will be used for handling the requests you send from your export.lua.

 

2. In your export.lua, start by opening the connection to your application in function LuaExportStart(), like so:

 

function LuaExportStart()
   package.path = package.path .. ";.\\LuaSocket\\?.lua"
   package.cpath = package.cpath .. ";.\\LuaSocket\\?.dll"

   socket = require("socket")
   host = "localhost"
   port = 10309
   connection = socket.try(socket.connect(host, port))
   connection:setoption("tcp-nodelay", true)
   socket.try(connection:send("start"))
end

 

Then you can use this socket to send/receive data.

I use the LuaExportBeforeNextFrame and LuaExportAfterNextFrame to respectively read switch states and set LED states.

 

For example, in my LuaExportBeforeNextFrame, I do this:

 

function LuaExportBeforeNextFrame()
   if connection then
       connection:send("switches\n")
line, status, partial = connection:receive("*l")

       local GearSwitch = string.sub(line, 4, 4)

if GearSwitch == "1" then
	LoSetCommand(430)	-- Gear Up
else
	LoSetCommand(431)	-- Gear Down
end
   end
end

 

To set the MasterWarning LED, you can do the following:

 

function LuaExportAfterNextFrame()
   local Failures = LoGetMCPState()
if Falures then
	local MasterWarning = Failures.MasterWarning and 1 or 0
	local returnString = string.format("leds %d%d%d%d%d%d%d%d\n", MasterWarning, StallSignal, CanopyOpen, 1, 0, 1, 0, 1)

	if connection then
		socket.try(connection:send(returnString))
	end
end
end

 

The communication exists of simple strings going back and forth.

For the switches, the lua script sends "switches" to the socket, and then receives "11001" back (I have 5 switches).

For the LEDs, the lua script sends a string containing 8 digits, e.g. "00101000", where 1 = LED on, and 0 = LED off.

The script currently expects no answer from the application.

 

The lua functions I call (LoSetCommand, LoGetMCPState) are for Flaming Cliffs, you'd have to do some research yourself to find the functions you need for the Huey (Can't help you there, since I don't have that module)

 

Finally, we close the connection when the mission is over:

 

function LuaExportStop()
   if connection then
socket.try(connection:send("--\n"))
connection:close()
   end
end

 

The application closes the connection when it receives "--".


Edited by Joe Kurr
  • Like 2
Dutch Flanker Display Team | LLTM 2010 Tiger Spirit Award
Link to comment
Share on other sites

Indeed thanks for sharing that info I am about to embark on making a collective thank you to both of you the OP for asking and Joe for the code.

Eagles may soar high but weasel's don't get sucked into jet engines.

 

 

System Spec.

Monitors: Samsung 570DX & Rift CV1

Mobo: MSI Godlike gaming X-99A

CPU: Intel i7 5930K @ 3.50Ghz

RAM: 32gb

GPU: EVGA Nvidia GTX 980Ti VR Ready

Cooling: Predator 360

Power Supply: OCZ ZX Series 80 Plus Gold

Drives: Samsung SSD's 1tb, 500g plus others with OS Win10 64 bit

 

Link to comment
Share on other sites

In case someone needs data from FC3 containing gear, flap and airbrake status, here's how to do it:

 

if LoGetMechInfo() then
local RawGearStatus = LoGetMechInfo().gear.value
local RawFlapStatus = LoGetMechInfo().flaps.value
local RawBrakeStatus = LoGetMechInfo().speedbrakes.value
--[[
	Raw[Gear|Flap|Brake]Status == 1 --> Gear / Flaps / Airbrake Extended
	Raw[Gear|Flap|Brake]Status == 0 --> Gear / Flaps / Airbrake Retracted
	Raw[Gear|Flap|Brake]Status > 0 < 1 --> Gear / Flaps / Airbrake Retracting / Extending
--]]
local GearWarning = (RawGearStatus > 0 and RawGearStatus < 1) and 1 or 0
local GearStatus = (RawGearStatus > 0.5 and GearWarning == 0) and 1 or 0
local FlapStatus = (RawFlapStatus > 0.5) and 1 or 0
local BrakeStatus = (RawBrakeStatus > 0.5) and 1 or 0
local FodStatus = ((LoGetMechInfo().gear.main.left.rod + LoGetMechInfo().gear.main.right.rod) / 2 > 0) and 1 or 0
local MasterWarning = LoGetMCPState().MasterWarning and 1 or 0
	
local returnString = string.format("leds %d%d%d%d%d%d%d%d\n", 0, 0, MasterWarning, GearWarning, BrakeStatus, FodStatus, FlapStatus, GearStatus)

if connection then
	socket.try(connection:send(returnString))
end
end

 

FodStatus is used here to indicate the position of the FOD screens inside the intakes, but since 1.2.4 this isn't indicated in the cockpit anymore.

The indicators which were used for this are now used for the leading edge flaps instead.

Dutch Flanker Display Team | LLTM 2010 Tiger Spirit Award
Link to comment
Share on other sites

If i can ask, to find the commands for A-10C/UH-1/Ka-50 what kind of research is required? Like searching all the *.lua files in world? Or someone knows already please post here...

 

I have to learn lua now,,,:cry:

 

Many thanks Joe, without your help i would remain in darkness..

I will give it a shot, and post the results here.... thanks again

Link to comment
Share on other sites

If i can ask, to find the commands for A-10C/UH-1/Ka-50 what kind of research is required? Like searching all the *.lua files in world? Or someone knows already please post here...

 

I have to learn lua now,,,:cry:

 

Many thanks Joe, without your help i would remain in darkness..

I will give it a shot, and post the results here.... thanks again

 

If you look through my wiki for hogkeys there is a step by step instruction to find the data for the a10. Link is in my sig.

Link to comment
Share on other sites

  • 1 month later...
In case someone needs data from FC3 containing gear, flap and airbrake status, here's how to do it:

 

I am trying to get my old Touchbuddy FC2 profile to work with FC3. But it seems things have changed as to how you setup FC/DCS World to allow export. Is there an explanation somewhere that you could point me to??

 

There is no config/export/export.lua file anymore... I cannot find a the config.lua for the EnableExportScript=true variable. And I am not sure that the DCS LUA instructions are correct anymore..?

 

Any help on how to setup DCS World export for FC3 is greatly appriciated.

 

Thanks,

Snacko

Intel I9-10850K (OC @ 5.0ghz) │ Asus Maximus XII Hero │ G.Skill Ripjaws 64GB (4x16GB) DDR4 3200 │ Thermaltake Water 360mm
Gigabyte RTX 4090 Gaming OC 24gb │ 2TB M.2 EVO Pro; 1T M.2 EVO; Sandisk SSD Drives │ 49" Samsung Curved Widescreen │ 28" Touchscreen

- ҉ - Blackshark Cockpit Trainer - ҉ -    Thread   | Download

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...