The simFlight Network Forums

# Lua scripts and FSUIPC Offsets

## Recommended Posts

I am trying to learn a little about Lua scripts and FSUIPC4 offsets, but clearly I do not understand some basic concepts.

The FSUIPC Offset table says the standby frequency for radio Com_1 is stored as 4 BCD characters in the 2 bytes starting at 0x311A. Therefore I expected the Lua script statements

ipc.writeUB(0x311A,  37);

ipc.writeUB(0x311B,  35);

to change the standby frequency for Com_1 to 123.25 since 37 decimal is the 8 bit value 0010 0101 which if interpreted as 2 BCD char is 25,  and decimal 35 is the 8 bit value 0010 0011 which if interpreted as 2 BCD characters is 23.  The leading frequency digit is always 1 and need not be written.

Since the above instructions had no effect on the displayed Com_1 standby frequency ( nothing I seem to do does ),  I am way off base somewhere.  I assumed once new values were written to the appropriate offset, the new frequency would immediately be displayed on the radio panel.  Would appreciate any guidance.

Thx,

Al

##### Share on other sites

The FSUIPC Offset table says the standby frequency for radio Com_1 is stored as 4 BCD characters in the 2 bytes starting at 0x311A. Therefore I expected the Lua script statements

ipc.writeUB(0x311A,  37);

ipc.writeUB(0x311B,  35);

to change the standby frequency for Com_1 to 123.25 since 37 decimal is the 8 bit value 0010 0101 which if interpreted as 2 BCD char is 25,  and decimal 35 is the 8 bit value 0010 0011 which if interpreted as 2 BCD characters is 23.  The leading frequency digit is always 1 and need not be written.

The action of setting the frequency is triggered by writing to 0x311A, so the second line has no effect. Why are you bothering to convert Hexadecimal into Decimal in order to write in any case when the hex representation is obviously clearer in this case?

You would be best simply witing the offset as one value. Writing one byte then the other, in either order, may not work properly because the offset reflects what the COM1 standby radio is currently set to. Since it is only changed by writing to 311A, by the time you try to write to 311B it is too late, the value there reflects the radio setting.

The proper way is

ipc.writeUW(0x311A, 0x2325)

Note that no ";" characters are needed in Lua, though I don't think they do any harm.

See that it makes sense using the correct ipc.write instruction for the size of the value you are writing? If you do not know the correspondence between bits, bytes and things like Words, Dwords, etc, please review the FAQ thread about bits, bytes ad numbers.

Regards

Pete

##### Share on other sites

My problem was I didn't understand the only  "trigger" for updating the radio standby freq display was just the 0x311A address.

Thanks for the feedback.

Al

##### Share on other sites

My problem was I didn't understand the only  "trigger" for updating the radio standby freq display was just the 0x311A address.

Thanks for the feedback.

All offsets operate using the offset value given. That is all 100% of those you can write to. Offsets aren't simple memory locations, they are instructions to FSUIPC to read or write things. The days when they were truly memory related (FS98) are long gone.

Pete

##### Share on other sites

You are correct in that I was treating the offsets as true memory locations!   I guess writing to an offset is more like passing parameters to a function call.

It looks like FSUIPC does some checking to make sure values, like a Com radio frequency, is valid when you attempt to write to the offset. Are invalid values just ignored?

What is the minimum delay ( using ipc.sleep, I assume) must there be between successive writes, or a read and a write, when updating a radio's displayed frequency ( e.g., at offset 0x311A for Com_1)? Is there a typical delay value to use for repeated access to most offsets?

Where can I find out which offsets require a delay after accessing them?

What is the size of the variable ipcPARAM, 32 bits?

On a control like the standby frequency swap for Com2, ipc.control(66444,1), where can I find out what the 1 does?

ADF frequencies involve 2 offsets. Can these be updated independently (i'm trying to update the displayed ADF freq digit by digit as each new digit is entered on the numpad). It seems sometimes writing to the 2nd (higher) offset, which should only effect the first and last ADF digits, also causes a change in the middle digits assocaited with the lower offset.

Finally, where could I have looked up the answers to these questions for myself?

I am new to FDUIPC and Lua scripts. I apoligize for these basic questions and appreciate your help and patience.

Al

##### Share on other sites

It looks like FSUIPC does some checking to make sure values, like a Com radio frequency, is valid when you attempt to write to the offset. Are invalid values just ignored?

No, FSUIPC does no such checking. It is FS which ignores invalid requests.

What is the minimum delay ( using ipc.sleep, I assume) must there be between successive writes, or a read and a write, when updating a radio's displayed frequency ( e.g., at offset 0x311A for Com_1)? Is there a typical delay value to use for repeated access to most offsets?

You mean "process" calls, not reads or writes, which are accumulated into a block for sending to FSUIPC when you execute the Process call.

I don't know of any restriction on reads or writes to set anything. But you should do the process calls at intervals which aren't going to slow FS down too much -- 20-30 times per second is normally good enough on most systems, even for lots of data. And it is best to have the whole thing event driven rather than loops with "sleeps" if possible. Just more efficient.

Where can I find out which offsets require a delay after accessing them?

Why do you think there are offsets needing a delay after accessing them? Have you any examples?

What is the size of the variable ipcPARAM, 32 bits?

Yes. It is the same as a Parameter supplied to an assigned FSUIPC or FS control, which are always 32-bit integers.

On a control like the standby frequency swap for Com2, ipc.control(66444,1), where can I find out what the 1 does?

What makes you think it does anything?  In general only "_SET" or "AXIS_" controls use parameters. If the function is merely a button which toggles something, or is specifically an ON or an OFF control it probably doesn't use the parameter. But, interestingly, some do and what the parameter does, if anything, has to be determined by experiment because none of this was ever documented by Microsoft.

ADF frequencies involve 2 offsets. Can these be updated independently (i'm trying to update the displayed ADF freq digit by digit as each new digit is entered on the numpad). It seems sometimes writing to the 2nd (higher) offset, which should only effect the first and last ADF digits, also causes a change in the middle digits assocaited with the lower offset.

The offsets can be updated separately, but not the individual digits. You'd have to read the value, change just the quartet (4-bits) you need to change, then write it back.

Finally, where could I have looked up the answers to these questions for myself?

Most of your questions appear to be either based on a misunderstanding (like just because there's a parameter, why isn't it used?), or related to Microsoft operation, for which Microsoft should ideally answer, except of course they don't develop or really support FS any more. When folks are developing stuff they find their way. FSUIPC is only an interface into FS, not the implementation of the things you are manipulating.

Regards

Pete

##### Share on other sites

The offsets can be updated separately, but not the individual digits. You'd have to read the value, change just the quartet (4-bits) you need to change, then write it back.

In case it is useful to anyone, what I found regarding the ADF frequency offsets is that just writing to the higher offset, that contains the MS and LS frequency digits, also changes the values of the middle frequency digits at least in terms of what is displayed on the radio panel. So, for example,  to change just the MS digit I had to write to both offsets to keep the displayed middle digits unchanged. Interestingly, the converse is not true. You can write to the lower offset to change one of the middle frequency digits without effecting the MS or LS digits. Has to do with how FSX updates the displayed ADF frequency I assume.

Al

## Create an account

Register a new account