P-38L Posted October 7 Report Posted October 7 Hello I am programming the reading and assignment of variables, so far everything has been fine. I am using the following line of code and it works perfectly since I can assign the value of variable A to variable L. ipc.execCalcCode("(A:CIRCUIT ON:89, Bool) (>L:WING_DEICE)") ipc.writeUB(0x66C8, ipc.readLvar("L:WING_DEICE")) I am doing this so that I can get the values of the KingAir Analogic in MFS2020 indicator lights. My question is this: the LED turns on when the switch is activated or when the light test button is pressed using the mouse only. But in the latter case, the LED does not turn on, it only turns on when I use the switch. What I am looking for is for it to turn on when the switch is used or when the light test button is pressed. Something like the following, but that doesn't work for me. Only the LED lights up when I use the Light Test, but not when I use the switch. ipc.execCalcCode("(A:CIRCUIT ON:89, Bool) or (L:var_GlareshieldAnnunciatorTest, Number) (>L:WING_DEICE)") ipc.writeUB(0x66C8, ipc.readLvar("L:WING_DEICE")) I've tried OR and AND but I can't get it to work. Any help would be greatly appreciated.
John Dowson Posted October 7 Report Posted October 7 8 hours ago, P-38L said: I can assign the value of variable A to variable L. ipc.execCalcCode("(A:CIRCUIT ON:89, Bool) (>L:WING_DEICE)") ipc.writeUB(0x66C8, ipc.readLvar("L:WING_DEICE")) I am surprised that works... The problem is that the ipc.execCalcCode call will return almost immediately, but it will take a while for the updated lvar value to be received back by FSUIPC, so when you read the lvar value you will be reading its old value. You should add a delay before reading the lvar value (i.e. ipc.sleep(30)). But it would be better to just either: 1. Add the A:CIRCUIT ON:89 simvar directly to an FSUIPC offset using the myOffsets.txt file (see Advanced User guide), or 2. Add the lvar L:WING_DEICE to an FSUIPC offset using the [LvarOffsets] ini file section. The offset would then be automatically updated when a new/updated value was received. 8 hours ago, P-38L said: Something like the following, but that doesn't work for me. Only the LED lights up when I use the Light Test, but not when I use the switch. ipc.execCalcCode("(A:CIRCUIT ON:89, Bool) or (L:var_GlareshieldAnnunciatorTest, Number) (>L:WING_DEICE)") ipc.writeUB(0x66C8, ipc.readLvar("L:WING_DEICE")) I've tried OR and AND but I can't get it to work. Any help would be greatly appreciated. Calculator code is in RPN format (see https://docs.flightsimulator.com/flighting/html/Additional_Information/Reverse_Polish_Notation.htm), so try: ipc.execCalcCode("(A:CIRCUIT ON:89, Bool) (L:var_GlareshieldAnnunciatorTest, Bool) or (>L:WING_DEICE)") You could also maybe treat them as numbers and add them: ipc.execCalcCode("(A:CIRCUIT ON:89, Number) (L:var_GlareshieldAnnunciatorTest, Number) + (>L:WING_DEICE)")
P-38L Posted October 7 Author Report Posted October 7 Excellent explanation. I finally got it done thanks to your kind help. I will have to use some variables with the method I showed you and I am already using others with myOffsets. Example: ipc.execCalcCode("(A:PROP RPM:1, rpm) 1370 < (>L:L_PROP_PITCH)") ipc.writeUB(0x66C0, ipc.readLvar("L:L_PROP_PITCH")) In this case, I need the value to be given only when the number in variable A is less than 1370, otherwise it will always be a zero. I don't know if this can be done in the myOffsets.txt file as well. In the following example the variable depends on two variables A and L to deliver the value. In all these cases it is working fine. Also, I don't know if this method can be implemented in the myOffsets.txt file. ipc.execCalcCode("20 13 (>A:BUS LOOKUP INDEX,number) (A:CIRCUIT CONNECTION ON:20, number) ! (>L:CBL_BAT_RELAY)") ipc.writeUB(0x66C2, ipc.readLvar("L:CBL_BAT_RELAY"))
John Dowson Posted October 8 Report Posted October 8 14 hours ago, P-38L said: In this case, I need the value to be given only when the number in variable A is less than 1370, otherwise it will always be a zero. I don't know if this can be done in the myOffsets.txt file as well. No it can't - but you don't need to. You can just correct for this in the offset event handling function, and set the lvar to a value of 1 when the value if the simvar is > 1370, otherwise set it to 0 (as the calc,. code does). 14 hours ago, P-38L said: In the following example the variable depends on two variables A and L to deliver the value. In all these cases it is working fine. Also, I don't know if this method can be implemented in the myOffsets.txt file. You do not implement any logic in the myOffsets.txt file. This only allows you to add simvars to FSUIPC offsets so they you can read/write/update them. The logic in how you use the values is encapsulated in the lua script that uses the offsets. So instead of this: ipc.execCalcCode("20 13 (>A:BUS LOOKUP INDEX,number) (A:CIRCUIT CONNECTION ON:20, number) ! (>L:CBL_BAT_RELAY)") in your offset event handling function for the simvar A:CIRCUIT CONNECTION ON:20, you would use: ipc.execCalcCode("20 13 (>A:BUS LOOKUP INDEX,number) " .. value .. " ! (>L:CBL_BAT_RELAY)") where value will be the value if the A:CIRCUIT CONNECTION ON:20 sinvar that is passed into the handling function. John
P-38L Posted October 8 Author Report Posted October 8 Hello Mr. Dowson. With your wonderful explanation, I was able to improve my programming code. I have made great progress, and so far I have managed to control a large percentage of the cockpit elements. Thank you very much for your valuable help. Alejandro
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now