shorthauler Posted February 9 Report Posted February 9 I have a home cokcpit where I can set the standby frequencies using Event IDs. The C-47 by Manfred Jahn and others does not have standby frequencies. You are tuning the active radio (Coms and Navs). I a seeing it correctly that there is no Event ID for the active frequencies only for the standbys, so I will have to program a lua script? Best, shorthauler
John Dowson Posted February 10 Report Posted February 10 11 hours ago, shorthauler said: I a seeing it correctly that there is no Event ID for the active frequencies only for the standbys, so I will have to program a lua script? Of course there are events for active frequencies, e.g. 65707 COM_RADIO_SET 65708 NAV1_RADIO_SET 65636 COM_RADIO_WHOLE_DEC 65637 COM_RADIO_WHOLE_INC 65638 COM_RADIO_FRACT_DEC 65639 COM_RADIO_FRACT_INC 65640 NAV1_RADIO_WHOLE_DEC 65641 NAV1_RADIO_WHOLE_INC 65642 NAV1_RADIO_FRACT_DEC 65643 NAV1_RADIO_FRACT_INC 66434 COM_RADIO_FRACT_DEC_CARRY 66435 COM_RADIO_FRACT_INC_CARRY 66445 NAV1_RADIO_FRACT_DEC_CARRY 66446 NAV1_RADIO_FRACT_INC_CARRY 67361 COM1_RADIO_HZ_SET 68064 COM1_8333HZ_MODE_TOGGLE 68065 COM1_8333HZ_MODE_SET etc Basically you have all the same events on active frequencies as with standby.
shorthauler Posted February 10 Author Report Posted February 10 Hm, these are the onese that I am using: 65640 NAV1_RADIO_WHOLE_DEC 65641 NAV1_RADIO_WHOLE_INC 65642 NAV1_RADIO_FRACT_DEC 65643 NAV1_RADIO_FRACT_INC But they only change the standby frequency in the background (invisible, because just one Nav radio in the DC 3, no standby display). How do I know this? I have a frequency ("frequency 1") in the active (only) frequency display, I toggle via FSUIPC, I then have another frequency ("frequency 2") in the display. I dial my rotary encoders, "frequency 2" remains unchanged. I toggle again and "frequency 1" is back in the display, but this time modified according to how I have turned the dials.
John Dowson Posted February 10 Report Posted February 10 I guess it makes sense that the WHOLE / FRACT events control the standby, as there are no stnby equivalents...sorry about that. To set the active frequency directly, you would need to use the NAV1_RADIO_SET control, or write the new frequency (in BCD format) to offset 0x0350.
shorthauler Posted February 11 Author Report Posted February 11 Thank you for your reply. Do I understand correctly that using the NAV1_RADIO_SET control, one would send a frequency (for example one that has been generated in a Lua script) directly to the radio, without "turning the dials"?
John Dowson Posted February 11 Report Posted February 11 2 hours ago, shorthauler said: Do I understand correctly that using the NAV1_RADIO_SET control, one would send a frequency (for example one that has been generated in a Lua script) directly to the radio, without "turning the dials"? Well, the NAV1_RADIO_SET control will send the new frequency to the FS, but you need to trigger this and that would normally be done on a rotary button, i.e. when turning the dial. You could have a lua script that knows the current NAV1 frequency (i.e. via an event callback on offset 0x0350), and the lua script would also wait to be triggered using event.param. The rotary buttons can then be assigned to LuaValue to trigger the lua event.param callback function (with the parameter indicating an increment or decrement, or maybe both fast/slow inc/decs if you have fast/slow buttons), and in the event.param handling function/callback, you would take the current NAV1 frequency and then increment/decrement this value before sending to the FS. Note that NAV1_RADIO_SET takes BCD16 format, whereas NAV1_RADIO_SET_HZ takes a Hz value. Probably better to convert the current BCD NAV1 frequency (from offset 0x0350) to HZ before changing and send on using NAV1_RADIO_SET_HZ.
shorthauler Posted February 15 Author Report Posted February 15 Thank you very much, I tried this, but no luck: oldNav1 = ipc.readUW(0350) newNav1 = oldNav1 +100 function Nav1plus(param) ipc.writeLvar("L:NAV1_RADIO_SET", newNav1) end event.param ("Nav1plus") This is what I get in the log: ********* LUA: "C-47 Radios" Log [from FSUIPC version 4.977] ********* 7576015 System time = 15/02/2025 20:28:31, Simulator time = 13:45:33 (19:45Z) 7576015 LUA: beginning "E:\FSX\Flight Simulator X\Modules\C-47 Radios.lua" 7576031 >>> Thread forced exit (ipc.exit or os.exit) <<< 7576031 System time = 15/02/2025 20:28:31, Simulator time = 13:45:33 (19:45Z) ********* LUA execution terminated: Log Closed ********* Any idea what I could try that might work?
John Dowson Posted February 16 Report Posted February 16 12 hours ago, shorthauler said: This is what I get in the log: ********* LUA: "C-47 Radios" Log [from FSUIPC version 4.977] ********* 7576015 System time = 15/02/2025 20:28:31, Simulator time = 13:45:33 (19:45Z) 7576015 LUA: beginning "E:\FSX\Flight Simulator X\Modules\C-47 Radios.lua" 7576031 >>> Thread forced exit (ipc.exit or os.exit) <<< 7576031 System time = 15/02/2025 20:28:31, Simulator time = 13:45:33 (19:45Z) ********* LUA execution terminated: Log Closed ********* Any idea what I could try that might work? That log shows the lua exited16ms after it was started. How are you starting/stopping this lua? The lua didn't actually run and was killed during start-up... Also, the lua scrip is incorrect. As I said, 0ffset 0x0350 is in BCD format. Do, as an example, if the NAV1 frequency is 123.45, then that offset holds 0x2345, so when you read that as a decimal you will get 9029. Add 100, you get 9129, which is 0x23A9, i.e. a frequency of 123.A9, which is incorrect. There are also other issues. For speed you should have this lua auto-started and wait for the parameter event to be triggered, but you need to get the current value and increment it within the callback/handling function. You are not doing this and are just sending the same value in each parameter event... If you want further help, please attach the lua script, and your FSUIPC4.log and FSUIPC4.ini files. Please turn off log lua separately, and turn on logging for lua plugins and Buttons & Switches before generating the log file. John
shorthauler Posted Sunday at 07:34 PM Author Report Posted Sunday at 07:34 PM Hi John, These are the files, please let me know if something is missing. The script is triggered by a joystick button (for testing purposes) and should only increase the frequency by 1 MHz. Decreasing and kHz should follow once this works. Best, shorthauler This should be my script: oldNav1 = ipc.readUW(0350) => reading the offset newNav1_string = string.format(oldNav1, 0xaf) => converting the HEX value to a string newNav1_string_shortened = string.sub(newNav1_string, 3) => starting from the 3rd digit of the string, thereby cutting the first two digits from the string newNav1 = tonumber (newNav1_string_shortened) => converting the string to a (decimal) integer newNav1_Hz = newNav1*10000 => multiplying with 10^4 to obtain herz, newNav1_value = newNav1_Hz+1000000 => adding 1^6 Hz = 1 MHz ipc.writeLvar("L:NAV1_RADIO_SET_HZ", newNav1_value) => sending the result to FSX Files C-47 Radios.zip
John Dowson Posted Monday at 08:58 AM Report Posted Monday at 08:58 AM You could always try debugging this yourself....if you look in the log, you will see: Quote 161906 *** LUA Error: E:\FSX\Flight Simulator X\Modules\C-47 Radios.lua:10: attempt to perform arithmetic on global 'newNav1' (a nil value) This is also incorrect: Quote oldNav1 = ipc.readUW(0350) and should be either: oldNav1 = ipc.readUW(0x0350) or oldNav1 = ipc.readUW("0350") And this is wrong: Quote ipc.writeLvar("L:NAV1_RADIO_SET_HZ", newNav1_value) => sending the result to FSX I am pretty confident that there is no such lvar as NAV1_RADIO_SET_HZ. You should either write the new frequency to offset 0x0350 (so that is correct when in BCD) or use the (key) control NAV1_RADIO_SET_HZ (67251) via ipc.control. Your string.format is also incorrect.... Try something like: currentNav1 = ipc.readUW(0x0350) -- read the current NAV1 frequency currentNav1Nav1_string = "1" .. string.format("%04X", currentNav1Nav1) -- get frequenct as a string newNav1 = currentNav1Nav1_string + 100 -- lua has lazy types and will convert the string to a decimal and we increment by 1MHz newNav1Hz = newNav1*10000 -- convert to HZ ipc.control(67251, newNav1Hz) -- send to frequency to sim John
shorthauler Posted Wednesday at 04:43 PM Author Report Posted Wednesday at 04:43 PM Thank you very much. Does NAV1_RADIO_SET_HZ (67251) work for FSX? I am under the impression that it is only available for MSFS. For FSX, I have found NAV1 RADIO SET 65708, but I was not able to find an explication what it actually does. The script works as it sends the parameters to the values as I take from the FSUIPC log file: 8469032 [Buttons] 4=P2,4,CL18:R,0 8469110 FS Control Sent: Ctrl=67251, Param=118200000 8469313 Button changed: bRef=0, Joy=2, Btn=4, Released But there is no change in FSX. Same for 65708. Best, shorthauler Files C-47 Radios.zip
John Dowson Posted Wednesday at 06:02 PM Report Posted Wednesday at 06:02 PM 1 hour ago, shorthauler said: Thank you very much. Does NAV1_RADIO_SET_HZ (67251) work for FSX? I am under the impression that it is only available for MSFS. Sorry, didn't realise (or forgot) that you were using FSX/FSUIPC4, No, it is not available - you should use NAV1_RADIO_SET (65708) instead. That takes the frequency in BCD format. 1 hour ago, shorthauler said: For FSX, I have found NAV1 RADIO SET 65708, but I was not able to find an explication what it actually does. Sets the chosen NAV frequency (BCD16 encoded Hz). 1 hour ago, shorthauler said: Same for 65708. But you cannot just change 67251 to 65708 and expect the script to work. You need to change the parameter to BCD format, or to an integer than when converted to hex shows the frequency in BCD format (with leading 1 dropped). Try and do that yourself - use logging to check that you are sending the correct parameter. If you have difficulties I can look at it for you, but you should at least try. I do not have much free time for these type of things at the moment.... John
John Dowson Posted Wednesday at 06:14 PM Report Posted Wednesday at 06:14 PM This may help - a lua function to convert a decimal frequency, in MHz not Hz) to BCD16: -- Convert frequency to BCD (e.g., "113.45" → 0x1345) function convertToBCD(freq) local cleanFreq = freq:gsub("%.", "") -- Remove decimal (e.g., "109.2" → "0920") local decimalNumber = tonumber(cleanFreq) -- Convert to number if not decimalNumber then return 0 end -- Return 0 if conversion fails local bcd = 0 local shift = 0 -- Convert each decimal digit to BCD format while decimalNumber > 0 do local digit = decimalNumber % 10 bcd = bcd + (digit * (16 ^ shift)) -- Use base 16 shift instead of bitwise left shift decimalNumber = math.floor(decimalNumber / 10) shift = shift + 1 end return bcd end John
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