Results 1 to 9 of 9
  1. #1
    300+ Forum Addict jmig's Avatar
    Join Date
    Apr 2007
    Location
    Lafayette, LA USA
    Posts
    422
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    A General SIOC Question

    As someone who is almost a programming luddite I find myself to be a modifier of code rather than someone who understands code. I can see how an example works and often modify it to meet my needs. However, I don't really understand it and if something goes wrong, I am at a loss to explain why.

    This troubles me. I have always been good at soving problems by following the sequence of events until I find the broken part. I can't do this in programming. Thus my first question to help me better understand SIOC.

    Initialization? I know it is to set something or zero out a counter or offset. However, why must and when must it be done? Why can't you just set the offset to say 100, to pick a number out of the air?

    Can you reset the offset elsewhere during the code event sequence? How?

    Nico once used the term Semaphore during an initialization of code. I looked up the definition and was completely confused. I obviously lack a basic understanding of programming necessary to understand the definition.

    Is Semaphore different from Initialization?

    Ok enough. I hope my questions don't bore anyone.
    John

    System:
    ASUS P5Q SE/R
    Intel Q9550 O/C to 3.4 GHz
    4 GB 1066 DDR2 RAM
    300 GB WD 10,000 RPM Raptor SATA Drive
    GeForce 8800 GT 512 KB RAM
    Matrox TH2Go with three 19" Sumsung 940 BX
    IR Track 4

  2. #2
    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: A General SIOC Question

    Hi,

    Don't understand exactly what you would like to know, but here is some information about initialisation of SIOC variables:
    http://www.lekseecon.nl/howto.html#init Note that initialisation of SIOC varaibles is a different topic from giving (FSUIPC) offsets a value, you can do that from anywhere in your SIOC code.

    A semaphore in computer programming see http://en.wikipedia.org/wiki/Semaphore_(programming) is a means to prevent two or more processes from acting at the same time upon a (shared) resource. This is a different topic then initialisation.

    regards,
    Nico

  3. #3
    150+ Forum Groupie pdpo's Avatar
    Join Date
    Nov 2005
    Location
    belgium
    Posts
    260
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: A General SIOC Question

    Jimig,

    I think I already explaned some of the SIOC working in another thread, maybe another forum, dont remember exactly when but here it goes again.
    You can understand SIOC by looking at it the following way.
    SIOC is a program and the SIOC script is just telling the program which are the variables it want to work with and what to do when one of those variables changes value.
    Initialy the SIOC program sets all variables to a value of 'unknown'. Then it starts its function.
    It checks first variable 0 (VAR0000) and if you set this value to an initial vaue of 0 (or something else) the value of VAR0000 changes from unknown to 0 (or something else).
    Since VAR0000 changes value it will execute the body between the { } attached to this VAR0000. This body can of course set values to other variables which have until this moment the value of unknown. Thus generating a chain of events. Like this it will continue
    until all vars are initialised.
    When all these initialisation events are over, the SIOC program continues its course by examining all possible inputs it can have, like hardware inputs closing/opening, FSUIPC_IN changes, FSUIPC_INOUT changes, etc. (it will read these fsuipc offsets that you defined as IN or INOUT which a certain pace)
    When one of these values changes the body attached to the variable will be executed and this can each time generate a chain of variable changes and other bodies to be executed.
    Something special are the timers since these will be able to run in another thread and change a variable in a certain timely manner.
    This is a very general overview...hopefully it clears out after reading this.

    I give a small example :

    VAR 0000, name INIT, value 123
    {
    &var1 = 10
    &var2 = 20
    }
    VAR 0001, name var1
    VAR 0002, name var2
    {
    if &var1 = 10
    {
    &led1 = 1
    }
    }
    VAR 0003, name led1, type = IOCARD_OUT
    VAR 0004, name gear, type FSUIPC_IN, offset XXXX

    voila, initially the SIOC program will build a database registering 5 variables with value 'unknown' and it will register for each of these
    variables a body to execute, var 0001 and var0003 and var0004 will have an empty body
    now SIOC will threat first VAR0000 and set the value to 123 so its value changes and the body needs to be executed
    so now it will set VAR0001 to 10, so its changes value from unknown to 10 but there is no body to execute so SIOC goes to the
    next line where it will set var0002 to 20. So now var0002 changes from unknown to 20 and there is a body defined so it will execute that
    body. This var0002 body checks to see if var0001 is 10 and this is true so it sets Var0003 to 1. var0003 changes from unknown to 1 so it
    needs to do the body. But there is no body. However is of an output type so it will send this to the hardware where the output will become high voltage.
    Now SIOC finished threating var0000 so it goes to var0001, this one doesnt have an initialisation value so nothing needs to happens.
    Now SIOC goes to var0002, again no init value specified so nothing to do
    The same for Var0003
    Now SIOC ends up at VAR0004 which is an fsuipc input at offset XXXX, so it will now copy the value from offset XXXX to var0004
    If Var0004 would have a body it would execute this one too.

    Now the complete init is done and SIOC will read continuously FSUIPC offset XXXX since this is the only input defined.
    If it changes value it will copy it to var 0004

    Simple example but understandable I think

    Greetz Peter
    FS9+PM+AST+opencockpits

  4. #4
    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: A General SIOC Question

    Hi Peter,

    Good explanation. I'm thinking of copying your example in stead of mine about flow control at my howto page. Hope you do not mind (zal aan bronvermelding doen ) Flow of control at start-up

    Just one question:

    "hardware where the output will become high voltage."

    Don't think that is correct..., the output will become a logical 1, for the Master card outputs it means a high voltage, for the USB output cards outputs it means ground. Note that outputs at a Master Card share a common ground while outputs at a USB expansion card share a common high voltage. But from a programming point of view these differnces are not visible, I use both cards in my simulator and sending 1 to an output has the same effect on both type of card.

    If I'm not mistaken..

    Groeten,
    Nico
    P.S. it was nice talking to you at the FSWeekend!

  5. #5
    300+ Forum Addict jmig's Avatar
    Join Date
    Apr 2007
    Location
    Lafayette, LA USA
    Posts
    422
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: A General SIOC Question

    Thank you once again Peter and Nico for all of your help and explanations. I understand the flow...for the moment. I know I will never be a programmer. Part of my problem is I don't know enough to know what I don't know. I do know that if the sample I borrow from one of you guys doesn't work, I quickly get so befuddled at to become totally lost.

    Little by little I am getting it to work. I have been struggling (and losing ) with an attempt to get a encoder to set the AP altitude. I have looked at several MCP type routines and attempted to pull from them the necessary code. So far no luck. I don't need to light the 7 segment LED yet. I just want to turn the dial and set the altitude.

    I have resisted asking for help because I would like to learn to understand SIOC enough to do it myself. Little by little or, maybe I should say, bit by bit I am getting there.

    Hummmm what next?
    John

    System:
    ASUS P5Q SE/R
    Intel Q9550 O/C to 3.4 GHz
    4 GB 1066 DDR2 RAM
    300 GB WD 10,000 RPM Raptor SATA Drive
    GeForce 8800 GT 512 KB RAM
    Matrox TH2Go with three 19" Sumsung 940 BX
    IR Track 4

  6. #6
    150+ Forum Groupie pdpo's Avatar
    Join Date
    Nov 2005
    Location
    belgium
    Posts
    260
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: A General SIOC Question

    Nico,

    you are right about the output. I was only taking master card in mind.
    No problem you put the flow info on your site, just dont shoot me if
    it turns out SIOC doesnt really work like that. This was of looking at it
    however already opened the mind for others and then they understood it.

    Jmig,
    nothing wrong with looking at others scripts and try to understand them
    but ones you get to understand what are the possibilities of the scripting
    language its sometimes better to start with en empty page and build up each
    item you want by yourself. Sometimes its easier to write it completely on your
    own then to modify existing things to suit your purpose. Since one person might
    do it different then another.

    Anyway, dont be ashamed asking, Niko or I will always assist. Just take a look
    at the available info and Niko his site. Many answers are there too.
    Then you try out a small script and see wether it does what you expect. If it doesnt
    post it and ask ....

    greetz Peter
    FS9+PM+AST+opencockpits

  7. #7
    75+ Posting Member MortenHa's Avatar
    Join Date
    Apr 2007
    Location
    Norway, Vardø
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: A General SIOC Question

    Hi folks!
    Interesting discussion, but I'm a bit unclear on one point:

    now SIOC will threat first VAR0000 and set the value to 123 so its value changes and the body needs to be executed
    Are you saying that the Value attribute MUST be present for VAR0000 code to execute?

    Let me illustrate what I mean:

    VAR 0000, name INIT, value 123
    will execute the code within the brackets

    VAR 0000, name INIT
    will NOT execute the code within the brackets?

    Perhaps the question is stupid, why would you use the VAR 0000 without the value attribute, since it has only one use: Initialization

    jmig:

    Initialization? I know it is to set something or zero out a counter or offset. However, why must and when must it be done? Why can't you just set the offset to say 100, to pick a number out of the air?


    It is always good programming practice to initialize variables when you write code. In fact some programming languages demands it (Others will do it automatically when the programs loads, like Java). Variables resides in computer memory, and there's no telling what value resides at the memory adress where the variable is stored before you initialize it.

    There's nothing stopping you from initializing your variable with whatever value you like. As long as you know how it will affect your program execution. But it often makes sense to initialize your variables with value of zero. It is easy to remember. And it will, in most cases, make it easier to debug the code if you run into trouble.


    Regards
    Morten

  8. #8
    75+ Posting Member
    Join Date
    Apr 2009
    Location
    Toronto
    Posts
    125
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: A General SIOC Question

    Hello Morten.

    VAR0000 has the special property that its associated script will be executed when it is initialized. So, yes, if it is required to run some script at startup, supply an initial value for VAR0000. Except for that, VAR0000 is just like any other variable. It can be used for more than iniitialization.

    Jim

  9. #9
    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

    Hi guys,
    It simply goes like this
    Sioc initialises each var that has a value attribute, and it will do this from lowest number to highest number (not physical location in the source script)

    so var 0 will be treated first
    Quote Originally Posted by deering View Post
    Hello Morten.

    VAR0000 has the special property that its associated script will be executed when it is initialized. So, yes, if it is required to run some script at startup, supply an initial value for VAR0000. Except for that, VAR0000 is just like any other variable. It can be used for more than iniitialization.

    Jim


    Posted via Mobile Device

  10. Thanks deering thanked for this post

Similar Threads

  1. Sioc Question
    By Olympic260 in forum OpenCockpits General Discussion
    Replies: 6
    Last Post: 02-01-2010, 08:50 PM
  2. sioc question
    By djcevera20 in forum OpenCockpits General Discussion
    Replies: 1
    Last Post: 06-01-2009, 02:01 AM
  3. Question on SIOC
    By 4EVERCooL in forum OpenCockpits General Discussion
    Replies: 5
    Last Post: 10-14-2008, 12:07 AM
  4. SIOC question
    By barkay in forum OpenCockpits General Discussion
    Replies: 7
    Last Post: 10-08-2008, 03:29 PM
  5. A BIG thanks & another SIOC question
    By jmig in forum OpenCockpits General Discussion
    Replies: 1
    Last Post: 09-02-2008, 12:25 PM