Results 1 to 3 of 3
  1. #1
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    235
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    P3Dv4 FSUIPC5 LUA and Arduino

    It appears FSUIPC5 isn't processing the "event.com" function call like it did in FSUIPC4.
    My Radio LUA script will send data from the sim to the Arduino but doesn't process data from the Arduino to the Sim.
    Pete Dowson author of FSUIPC is out of communication until June 20th.
    I have seen some of his interactions with others folks on "bugs" in FSUIPC5.
    Going to search some more and maybe try a work around with a "while" loop to test.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  2. #2
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    235
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: P3Dv4 FSUIPC5 LUA and Arduino

    OK, the While loop method will work, but it is not elegant.
    If the script is in a while loop it cant do the other even functions.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  3. #3
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    235
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: P3Dv4 FSUIPC5 LUA and Arduino

    I have a work around using an event called event.timer.
    Code:
    event.timer(50, "check_knob")
    If you have an Arduino Radio setup to use Link2FS, this LUA script should work with it in P3Dv4 using FSUIPC5.
    I replaced the event.com with event.timer. I just remarked out event.com until it becomes workable again.

    Every 50ms the script will read the connection to see if anything was sent from the Arduino.
    RADIO_v4.lua
    Code:
    port_file = "RADIO_port.txt"
    feet_per_meter = 3.28083989501312
    speed = 115200
    handshake = 0
    serial_wait = 20
    ---------------------------------------
    file = io.open(port_file, "r")
    if file == nil then
        port_number = "10"
        file = io.open(port_file, "w")
        io.output(file)
        io.write(port_number)
        io.close(file)
        Arduino_Com_Port = com.open("COM"..port_number, speed, handshake)
    else
        port_number = file:read (2)
        --ipc.display(port_number)
        io.close(file)
        Arduino_Com_Port = com.open("COM"..port_number, speed, handshake)
    end 
    if Arduino_Com_Port ~= 0 then
        ipc.display("Arduino Com Port "..port_number.." Open",5)
        
    else
        ipc.display("Could not open ARDUINO Com Port")
        ipc.sleep(2000)
        port_number = ipc.ask('\n'..'\n'..'\n'..'\n'..'\n'..'\n'..'\n'..'\n'.." Enter the Arduino Com Port for Your RADIO")
        file = io.open(port_file, "w")
        io.output(file)
        io.write(port_number)
        io.close(file)
    
    
        Arduino_Com_Port = com.open("COM"..port_number, speed, handshake)
         
        if Arduino_Com_Port == 0 then
            ipc.display("Could not open ARDUINO Com Port",5)
            
            ipc.exit()
        else
            ipc.display("Arduino Com Port "..port_number.." Open",5)
            
        end
    end 
    -------------------------------------------------------------------
    -------------------------------------------------------------------
    
    
    --function Arduino_Data(Arduino_Com_Port, datastring, length)
    function check_knob(tyme)
        datastring = com.read(Arduino_Com_Port,50,1)
        --ipc.display("Function called",2)
        --ipc.display(datastring)
        
        --- L CRS -------------------------------------
        if (string.find(datastring, "A56")) then  --L CRS UP
            for i in string.gfind(datastring, "A56") do
                ipc.control(65663,0)
            end
            
        end
        if (string.find(datastring, "A55")) then  --L CRS DOWN
            for i in string.gfind(datastring, "A55") do
                ipc.control(65662,0)
            end
            
        end    
        ----------------------------------------------------------
        --- IAS/mach -------------------------------------
        if (string.find(datastring, "B15")) then  --IAS/mach UP
            ipc.control(65896,0)
            
        end
        if (string.find(datastring, "B16")) then  --IAS/mach DOWN
            ipc.control(65897,0)    
        end    
        ----------------------------------------------------------    
        --- HDG -------------------------------------
        if (string.find(datastring, "A57")) then  --HDG UP
            for i in string.gfind(datastring, "A57") do
                ipc.control(65879,0)
            end
            
        end
        if (string.find(datastring, "A58")) then  --HDG DOWN
            
            for i in string.gfind(datastring, "A58") do
                ipc.control(65880,0)
            end
            
        end    
        ----------------------------------------------------------
        --- ALTITUDE -------------------------------------
        if (string.find(datastring, "B11")) then  --ALT UP
            ipc.control(65892,0) 
        end
        if (string.find(datastring, "B12")) then  --ALT DOWN
            ipc.control(65893,0) 
        end
        ----------------------------------------------------------
        --- VERTICLE SPEED -------------------------------------
        if (string.find(datastring, "B13")) then  --V/SPEED UP
            ipc.control(65894,0) 
        end
        if (string.find(datastring, "B14")) then  --V/SPEED DOWN
            ipc.control(65895,0) 
        end
        ---- Transponder -------------------------------------
        if (string.find(datastring, "A34")) then  
            ipc.control(65651,0) 
        end
        if (string.find(datastring, "A35")) then  
            ipc.control(65652,0) 
        end
        if (string.find(datastring, "A36")) then  
            ipc.control(65653,0) 
        end
        if (string.find(datastring, "A37")) then  
            ipc.control(65654,0) 
        end
        if (string.find(datastring, "A38")) then  
            ipc.control(66455,0) 
        end
        if (string.find(datastring, "A39")) then  
            ipc.control(66456,0) 
        end
        if (string.find(datastring, "A40")) then  
            ipc.control(66457,0) 
        end
        if (string.find(datastring, "A41")) then  
            ipc.control(66458,0) 
        end
        ---- COM1 -------------------------------------
        if (string.find(datastring, "A02")) then  
            ipc.control(65637,0) 
        end
        if (string.find(datastring, "A01")) then  
            ipc.control(65636,0) 
        end
        if (string.find(datastring, "A04")) then  
            ipc.control(65639,0) 
        end
        if (string.find(datastring, "A03")) then  
            ipc.control(65638,0) 
        end
        ---- NAV1 -------------------------------------
        if (string.find(datastring, "A14")) then  
            ipc.control(65641,0) 
        end
        if (string.find(datastring, "A13")) then  
            ipc.control(65640,0) 
        end
        if (string.find(datastring, "A16")) then  
            ipc.control(65643,0) 
        end
        if (string.find(datastring, "A15")) then  
            ipc.control(65642,0) 
        end
        ---- COM2 -------------------------------------
        if (string.find(datastring, "A08")) then  
            ipc.control(66437,0) 
        end
        if (string.find(datastring, "A07")) then  
            ipc.control(66436,0) 
        end
        if (string.find(datastring, "A10")) then  
            ipc.control(66440,0) 
        end
        if (string.find(datastring, "A09")) then  
            ipc.control(66438,0) 
        end
        ---- NAV2 -------------------------------------
        if (string.find(datastring, "A20")) then  
            ipc.control(65645,0) 
        end
        if (string.find(datastring, "A19")) then  
            ipc.control(65644,0) 
        end
        if (string.find(datastring, "A22")) then  
            ipc.control(65647,0) 
        end
        if (string.find(datastring, "A21")) then  
            ipc.control(65646,0) 
        end
        ---- ADF 1 -------------------------------------
        if (string.find(datastring, "A25")) then  
            ipc.control(65648,0) 
        end
        if (string.find(datastring, "A29")) then  
            ipc.control(65666,0) 
        end
        if (string.find(datastring, "A26")) then  
            ipc.control(65649,0) 
        end
        if (string.find(datastring, "A30")) then  
            ipc.control(65667,0) 
        end
        if (string.find(datastring, "A27")) then  
            ipc.control(65650,0) 
        end
        if (string.find(datastring, "A31")) then  
            ipc.control(65668,0) 
        end
        if (string.find(datastring, "A28")) then  
            ipc.control(66454,0) 
        end
        if (string.find(datastring, "A32")) then  
            ipc.control(66453,0) 
        end
        ---- Freq Swap -------------------------------------
        if (string.find(datastring, "A06")) then  --com1
            ipc.control(66372,0) 
        end
        if (string.find(datastring, "A12")) then  --com2
            ipc.control(66444,0) 
        end
        if (string.find(datastring, "A18")) then  --nav1
            ipc.control(66448,0) 
        end
        if (string.find(datastring, "A24")) then  --nav2
            ipc.control(66452,0) 
        end
        --ipc.sleep(serial_wait)
    end  -- function end
    
    
    --------------------------------------------------------
    --- Displays -------------------------------------------
    --------------------------------------------------------
    function call_crs_l (offset, value)
        if (string.len(value) == 2) then
            value = "0"..value
        end
        if (string.len(value) == 1) then
            value = "00"..value
        end
        com.write (Arduino_Com_Port, "=e"..value)
    end 
    -------------------------
    function call_crs_r (offset, value)
        
        if (string.len(value) == 2) then
            value = "0"..value
        end
        if (string.len(value) == 1) then
            value = "00"..value
        end
        com.write (Arduino_Com_Port, "=e"..value)
    end 
    -------------------------
    function call_iasmach (offset, value)
        --ipc.display(value)
        
        if (string.len(value) == 2) then
            value = "0"..value
        end
        if (string.len(value) == 1) then
            value = "00"..value
        end
        com.write (Arduino_Com_Port, "=f"..value)
    end 
    -------------------------
    function call_heading (offset, value)
        value = (value/65536)*360
        value = tonumber(string.format("%.0f", value))
        --ipc.display(value)
        --hdg = value
        if (string.len(value) == 2) then
            value = "0"..value
        end
        if (string.len(value) == 1) then
            value = "00"..value
        end
        com.write (Arduino_Com_Port, "=d"..value)
    end 
    -------------------------
    function call_altitude (offset, value)
        value = (value/65536)*feet_per_meter
        --ipc.display(value)
        value = tonumber(string.format("%.0f", value))
        --ipc.display(value)
        if (string.len(value) == 4) then
            value = "0"..value
        end
        if (string.len(value) == 3) then
            value = "00"..value
        end
        com.write (Arduino_Com_Port, "=b"..value)
    end 
    -------------------------
    function call_vertical (offset, value)
        if (value > 9900) then
            value = 65536 - value
            if (string.len(value) == 3 ) then
                value = "-0"..value
            elseif (string.len(value) == 4 ) then
                value = "-"..value
            end
        else
            if (string.len(value) == 3 and value > 0) then
                value = "+0"..value
            elseif (string.len(value) == 4 and value > 0) then
                value = "+"..value
            end
        end
        if (value == 0) then
            value = "+0000"
        end
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=c"..value)
    end 
    -----------------------------------------------
    function call_com1_main (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=A"..value)
    end
    function call_com1_stdby (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display("Com1 Stdby called",2)
        com.write (Arduino_Com_Port, "=B"..value)
    end
    function call_nav1_main (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=E"..value)
    end
    function call_nav1_stdby (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=F"..value)
    end
    function call_com2_main (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=C"..value)
    end
    function call_com2_stdby (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=D"..value)
    end
    function call_nav2_main (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=G"..value)
    end
    function call_nav2_stdby (offset, value)
        value = string.format("%04x", value)
        value = "1"..value:sub(1,2).."."..value:sub(3,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=H"..value)
    end
    function call_xpndr (offset, value)
        value = string.format("%04x", value)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=J"..value)
    end
    function call_dme1 (offset, value)
        value = string.format("%04d", value)
        value = value:sub(1,3).."."..value:sub(4,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=K"..value)
    end
    function call_dme2 (offset, value)
        value = string.format("%04d", value)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=L"..value)
    end
    function call_adf1 (offset, value)
        value = string.format("%04x", value)
        value_ext = ipc.readUW(0x0356)
        value_ext = string.format("%04x", value_ext)
        value = value_ext:sub(2,2)..value:sub(2,4).."."..value_ext:sub(4,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=I"..value)
    end
    function call_adf1_ext (offset, value_ext)
        value = ipc.readUW(0x034C)
        value = string.format("%04x", value)
        value_ext = string.format("%04x", value_ext)
        value = value_ext:sub(2,2)..value:sub(2,4).."."..value_ext:sub(4,4)
        --ipc.display(value)
        com.write (Arduino_Com_Port, "=I"..value)
    end
    -----------------------------------------------------
    --- EVENTS ------------------------------------------
    -----------------------------------------------------
    event.timer(50, "check_knob")
    --event.com(Arduino_Com_Port, 50,1, "Arduino_Data")
    event.offset (0x0c5e, "UW", "call_crs_l") -- autopilot crs left side
    event.offset (0x0C4E, "UW", "call_crs_r") -- autopilot crs right side
    event.offset (0x07E2, "UW", "call_iasmach") -- autopilot IAS/mach
    event.offset (0x07CC, "UW", "call_heading") -- autopilot heading
    event.offset (0x07D4, "UD", "call_altitude") -- autopilot altitude
    event.offset (0x07F2, "UW", "call_vertical") -- autopilot vertical speed
    ---------
    event.offset (0x034e, "UW", "call_com1_main") -- com one main
    event.offset (0x311a, "UW", "call_com1_stdby") -- com one standby
    event.offset (0x0350, "UW", "call_nav1_main") -- nav one main
    event.offset (0x311e, "UW", "call_nav1_stdby") -- nav 1 standby
    
    
    event.offset (0x3118, "UW", "call_com2_main") -- com two
    event.offset (0x311c, "UW", "call_com2_stdby") -- com two standby
    event.offset (0x0352, "UW", "call_nav2_main") -- nav two main
    event.offset (0x3120, "UW", "call_nav2_stdby") -- nav two standby
    
    
    event.offset (0x0354, "UW", "call_xpndr") -- transponder
    event.offset (0x0300, "UW", "call_dme1") -- VOR1 DME distance
    event.offset (0x0306, "UW", "call_dme2") -- VOR2 DME distance
    event.offset (0x034c, "UW", "call_adf1") -- ADF one frequency main
    event.offset (0x0356, "UW", "call_adf1_ext") -- ADF one frequency main
    
    
    
    
    --event.offset (0x02D4, "UW", "call_radio") -- ADF two main
    --event.offset (0x0304, "UW", "call_radio_DME") -- VOR1 DME time
    --event.offset (0x030a, "UW", "call_radio_DME") -- VOR2 DME time
    
    
    ---------
    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com