[simpits-tech] CIM programming to FSUIPC Offsets?

Gene Buckle geneb at deltasoft.com
Tue Jul 22 15:02:30 PDT 2008


>> Do you mean code for the AC360 gauges?  Not yet - I had forgotten to order
>> interconnect hardware when I first got them and I place the part order
>> yesterday.
>
> I think Leo drives his gauges with a 0 to 5vdc signal, and his gauge
> converts that voltage to angular position.
>
> So I am using just the 0 to 5vdc analog out
>
Right, but you send it a value from 0 to 255 to specify the needle 
position because you're talking to an 8 bit DAC on the other end. (Leo, if 
you're monitoring - help me out if I'm wrong on the 0..255 value)

So your scale command would be some thing like this

NeedlePos = CIM:Scale(0,500,0,255,Airspeed)

0..500 is the range the ASI can show, 0..255 is the range you can feed the 
DAC.  The result should give you a pretty good needle position based on 
the airspeed value you fit into it.

>> It'll go something like this though:
>>
>> Airspeed = CIM:GetNumericValue("AIRSPEED")
>> NeedlePos = CIM:Scale(InMin, InMax, OutMin, OutMax, Airspeed)
>> CIM:SetGauge("AIRSPEED", NeedlePos)
>>
>> GetNumericValue() would look up the value that matches the name "AIRSPEED"
>> in whatever sim you're using and return it.
>
> How do you define the name "AIRSPEED" to FSUIPC offsets 02BC
>
> "02BC   4       IAS: Indicated Air Speed, as knots * 128 "
>

I'll give you an example from the configuration file.  (I can't run MSFS 
right now to show you an example via screenshot)

<Parameter Key="COM1_FRQ" Offset="846" Size="2" VarType="2" Direction="2" />

This is what the configuration file shows for the first entry in the MSFS 
section.
The Parameter Key field is the name you call it and what you'll use 
to reference that value when you want to read or write it.

Offset is the decimal representation of the offset you found in the
documentation.

Size is the size in bytes of the field you're reading from.

VarType is the variable type the simulator is sending you.  In this case, 
the 2 represents BCD format.  This means that the value coming out of the 
simulator for the COM1 frequency is a Hexadecimal BCD value.

Direction = 2 means that this variable can be both read from and written 
to.  Some are read only, and I don't think I've ever found a write only 
parameter in MSFS.

Here is one of the examples I'm going include.  The SetValue() calls send 
"debug" data to CIM so you can see what it did AFTER the script finishes. 
I'm looking adding a "remote" debugger that you can use to single step the 
code via a network connection while the script is running.

This particular example is a "run many" script.  This means that this 
script is executed at an interval you specify.  For my testing, I've been 
using 10ms.

g.



---------------------------------------------------------
-- Cockpit Interface Master - Copyright 2008, Gene Buckle
-- Controls COM1 frequency selection
---------------------------------------------------------

-- Get the currently selected frequency from the simulator.
Com1Freq = CIM:GetStringValue("COM1_FRQ")
if Com1Freq == "" then
    CIM:SetValue(0, "Com1Freq was blank for this cycle.")
    return
end
-- Choose the correct frequency "step" based upon what the current
-- simulator needs.
if SimType == "FlightGear" then
    kHz_offset = .0250
    Mhz_Offset = 1.0
elseif SimType == "MSFS" then
    kHz_offset = 2
    Mhz_Offset = 100
else
    CIM:SetValue(0, "Invalid SimType - >" .. SimType .. "<-")
    return
end

-- The next four if..then blocks control how the step up/step down
-- buttons work for gross (Mhz) and fine (kHz) tuning of the COM
-- radio.
-- The routines are written to eliminate "keybounce" by ensuring that
-- the user has released the button before the script terminates.

-- The "CIM:SetValue(0,...)" calls are an easy way to see how the code is 
operating
-- if there is a problem with the simulator.

if CIM:GetInput("KHZ_DOWN") == true then
    repeat
      -- do nothing
    until CIM:GetInput("KHZ_DOWN") == false
    Com1Freq = Com1Freq - kHz_offset
    CIM:SetStringValue("COM1_FRQ", Com1Freq)
    CIM:SetValue(0, "KHZ_DOWN ->" .. Com1Freq .. "<-")
    return
end

if CIM:GetInput("KHZ_UP") == true then
    repeat
      -- do nothing
    until CIM:GetInput("KHZ_UP") == false
    Com1Freq = Com1Freq + kHz_offset
    CIM:SetStringValue("COM1_FRQ", Com1Freq)
    CIM:SetValue(0, "KHZ_UP - " .. Com1Freq)

    return
end

if CIM:GetInput("MHZ_UP") == true then
    repeat
      -- do nothing
    until CIM:GetInput("MHZ_UP") == false
    Com1Freq = Com1Freq + Mhz_Offset
    CIM:SetStringValue("COM1_FRQ", Com1Freq)
    CIM:SetValue(0, "MHZ_UP - " .. Com1Freq)
    return
end

if CIM:GetInput("MHZ_DOWN") == true then
    repeat
      -- do nothing
    until CIM:GetInput("MHZ_DOWN") == false
    Com1Freq = Com1Freq - Mhz_Offset
    CIM:SetStringValue("COM1_FRQ", Com1Freq)
    CIM:SetValue(0, "MHZ_DOWN - " .. Com1Freq)
    return
end



-- Proud owner of F-15C 80-0007
http://www.f15sim.com - The only one of its kind.


More information about the Simpits-tech mailing list