Results 1 to 7 of 7
  1. #1
    500+ This must be a daytime job



    Join Date
    Jan 2007
    Location
    NEW ZEALAND
    Posts
    899
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Sioc Code Frustration

    Hi All,
    Im battling again, it seems to be a never ending battle for me. Read all docs, been to Nico
    site but my code dont do what i want. The simple stuff is ok but when i have to do
    anything slightly diff all goes wrong. It seems to me this sioc is not what it appears.
    Heres my problem.
    Im driving an Analogue meter from the Servo card via a PWM to Dc converter. AS the
    first 25% of the scale is non linear i have to add an offset for this first 25%.
    Here is my Code:

    Var 1002,name Fuel Link FSUIPC_IN,Offset $0b7c,Length 4
    {
    L0 = v1002 / 8388608
    L2 = L0 * 100
    IF L2 < 25

    {
    CALL V100
    }
    ELSE
    V1000 = L0 * 1023
    }

    VAR 100,Link SUBRUTINE
    {
    L1 = L0 * 1023
    V1000 = L1 + 70
    }
    Var 1000,Link USB_SERVOS,Output 2,Posl 0,Posc 512,Posr 1023,Type 2

    If i select 20% fuel in FSX then it just carries out the statement after ELSE.
    I thought that after an IF statement(L2 < 25) the Code following in the Curly Brackets
    would be executed. In my case its not, ive tried everything but no success.
    Apparently this if statement is not what it appears.
    Can someone please help.
    Thanks
    Les

  2. #2
    500+ This must be a daytime job



    Join Date
    Jul 2013
    Posts
    917
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Sioc Code Frustration

    Les

    Are you sure that section of conditional code is not being run. The reason I ask is that you appear to be using L0 in two variable sections of code. You cannot carry across a local variable value from one section to another - that is why they are local. This will give you strange results Perhaps you could call the subroutine passing the L0 (not sure?). Simplest answer is to have a new variable defined to replace the instances where you have used L0

    As always I stand to be corrected

    Regards

    David

  3. #3
    500+ This must be a daytime job kiek's Avatar
    Join Date
    Jan 2007
    Location
    Netherlands
    Posts
    698
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Sioc Code Frustration

    Hi Les,
    David is right.
    This statement:
    Code:
    L1 = L0 * 1023
    gives undefined results, while L0 has no defined value...

    Nico
    BTW: wrap CODE tags around your code, will make your posts a lot more readable (see the numbersign icon above in this editor)

  4. #4
    150+ Forum Groupie


    Perik's Avatar
    Join Date
    Aug 2007
    Location
    NORWAY
    Posts
    193
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Sioc Code Frustration

    Hello iwik

    A small change and the code should logically work though not as you may expect.
    Unsure what you try to achieve because it seems that the "servo" value will
    have an overlapping region.

    I would have split the gauge/meter in two sections - each with its own scaling factor
    or maybe just lower the multiplier in the line:

    L1 = L0 * 1023

    Code:
    Var 1002,name Fuel Link FSUIPC_IN,Offset $0b7c,Length 4
    {
    	L0 = v1002 / 8388608
    	L2 = L0 * 100
    	IF L2 < 25
    	{ 
    		L1 = L0 * 1023
    		V1000 = L1 + 70
    	}
    	ELSE
    	{
    		V1000 = L0 * 1023
    	}
    }
    
    Var 1000,Link USB_SERVOS,Output 2,Posl 0,Posc 512,Posr 1023,Type 2
    Happy coding
    Regards,
    Per-Erik
    www.hoddo.net

  5. #5
    500+ This must be a daytime job



    Join Date
    Jan 2007
    Location
    NEW ZEALAND
    Posts
    899
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Sioc Code Frustration

    Hi and Thanks all.
    David- Learnt something new, meaning of Local variables.

    Kiek- Will do code with tags in future, always wondered how others were getting that format.

    Per-Eirk- i think i lost my way big time. Your comments helped a lot, put me back on track and made my code simpler. Works well now.

    Les

  6. #6
    500+ This must be a daytime job kiek's Avatar
    Join Date
    Jan 2007
    Location
    Netherlands
    Posts
    698
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Sioc Code Frustration

    Hi,
    Here some information about Local or Internal Variables in SIOC.
    regards,
    NMico

  7. #7
    500+ This must be a daytime job



    Join Date
    Jan 2007
    Location
    NEW ZEALAND
    Posts
    899
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Sioc Code Frustration

    Thanks Nico,
    I was aware of those varaibles but unsure of when and how they can be used. I find i have to trip myself up before it sinks in. I quite often visit your page
    for clarification.
    Regards
    Les