PDA

View Full Version : Sioc Code Frustration



iwik
06-27-2011, 03:00 PM
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

fordgt40
06-27-2011, 04:13 PM
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

kiek
06-27-2011, 05:46 PM
Hi Les,
David is right.
This statement:


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)

Perik
06-27-2011, 08:18 PM
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


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 ;-)

iwik
06-28-2011, 02:39 PM
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

kiek
06-28-2011, 03:03 PM
Hi,
Here (http://www.lekseecon.nl/howto.html#internalVars) some information about Local or Internal Variables in SIOC.
regards,
NMico

iwik
06-29-2011, 02:42 PM
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