ckovoor Posted August 3, 2014 Report Posted August 3, 2014 Hi, I know Pete is away, but for those who are interested in this issue, I now have a working solution to update all NAV and COM frequencies at network clients running FSX. It implements Pete's suggestion that I could write "the frequency to a file in the Client Lua and have an FSUIPC-based Lua plug-in read that file": (1) recordnavcom.lua in the Server Modules folder automatically updates 4 local text files with current nav/com frequencies. (2) an Autohotkey routine at each of the Clients copies the text files from the Server to the Client's Modules folder, and also runs receivenavcom.lua at the Client FSX which writes the contained updated frequencies to the various FSUIPC offsets. (3) Note A: to automate step (1) recordnavcom.lua is added to the [Auto] section of the Server FSUIPC, B: step (2) is triggered at all Clients by an Input Director macro at the Server. Thus only 1 action is necessary to transfer the frequencies to the 8 clients in my system, namely, pressing a hotkey at the Server. C: The Server Modules folder will initially need to contain (initially empty) text files named com1freq.txt, com2freq.txt, nav1freq.txt and nav2freq.txt, as lua cannot create these files. Here are the plugins: ............................ recordnavcom.lua -- lua plugin to write updated COM and NAV frequencies to local text files at SERVER -- this plugin to be located in the SERVER FSX\Modules folder along with the 4 empty text files -- these 4 files are to be named com1freq.txt, com2freq.txt, nav1freq.txt, nav2freq.txt -- add this lua to the [Auto] section of the SERVER FSUIPC function recordCOM1(offset, value) file = io.open("com1freq.txt","w") file:write(value) file:close() end function recordCOM2(offset, value) file = io.open("com2freq.txt","w") file:write(value) file:close() end function recordNAV1(offset, value) file = io.open("nav1freq.txt","w") file:write(value) file:close() end function recordNAV2(offset, value) file = io.open("nav2freq.txt","w") file:write(value) file:close() end event.offset(0x034E, "UW", "recordCOM1") event.offset(0x3118, "UW", "recordCOM2") event.offset(0x0350, "UW", "recordNAV1") event.offset(0x0352, "UW", "recordNAV2") ............................ receivenavcom.lua -- lua plugin to update NAV/COM offsets with updated frequencies contained in copied .txt files -- the 4 .txt files would have been copied into the local Modules folder by the .ahk routine -- this plugin to be located in the CLIENT FSX\Modules folder -- 4 text files will have been named com1freq.txt, com2freq.txt, nav1freq.txt, nav2freq.txt -- this lua can be assigned to key 'f' in the CLIENT FSUIPC file = io.open("com1freq.txt","r") value = file:read() file:close() ipc.writeUW(0x034E, value) file = io.open("com2freq.txt","r") value = file:read() file:close() ipc.writeUW(0x3118, value) file = io.open("nav1freq.txt","r") value = file:read() file:close() ipc.writeUW(0x0350, value) file = io.open("nav2freq.txt","r") value = file:read() file:close() ipc.writeUW(0x0352, value) ............................ .ahk script at the CLIENT(s) which copies .txt files from SERVER to CLIENT Modules folder, and then runs receivenavcom.lua at the Client FSX. #/:: ;receive NAV and COM frequencies and copy to offset FileCopy, \\SERVER\Microsoft Flight Simulator X\Modules\com1freq.txt, C:\FS Files\Microsoft Flight Simulator X\Modules\com1freq.txt, 1 FileCopy, \\SERVER\Microsoft Flight Simulator X\Modules\com2freq.txt, C:\FS Files\Microsoft Flight Simulator X\Modules\com2freq.txt, 1 FileCopy, \\SERVER\Microsoft Flight Simulator X\Modules\nav1freq.txt, C:\FS Files\Microsoft Flight Simulator X\Modules\nav1freq.txt, 1 FileCopy, \\SERVER\Microsoft Flight Simulator X\Modules\nav1freq.txt, C:\FS Files\Microsoft Flight Simulator X\Modules\nav1freq.txt, 1 IfWinExist Microsoft Flight Simulator X { WinMaximize, Microsoft Flight Simulator X WinActivate, Microsoft Flight Simulator X WinWaitActive, Microsoft Flight Simulator X Send {f} Reload } return ............................ I have tested this on my network and it works. The offsets are duly updated at the clients. I did not use WideFS or lua to transfer the .txt files across the network. So, if you do not use Autohotkey and Input Director then you will need to find other ways of sending the files to the Clients, running the Client lua's, and mapping these actions to a hotkey. I am sure there are more efficient ways of doing this, and I welcome your comments. Regards, Chakko.
Paul Henty Posted August 3, 2014 Report Posted August 3, 2014 Hi Chakko, I have two things you can try that could improve this a bit... 1. If the local data files do not exist then the lua library should create them for you when you write them the first time. You shouldn't need to create them manually. 2. You should be able to eliminate the whole copying process by directly accessing the server files from the client LUA. \ is a special character and needs to be doubled to mean one \. so something like this could work: file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\com1freq.txt","r") Paul
ckovoor Posted August 3, 2014 Author Report Posted August 3, 2014 Hello Paul, Thank you for taking a look at this. I have implemented both your suggestions. It is indeed unnecessary to manually create the .txt files on the Server. And your snippet of code does indeed facilitate direct access of the Server files from the Client LUA, which makes the use of Autohotkey unnecessary. So here are the revised plugins: recordnavcom.lua -- lua plugin to write updated COM and NAV frequencies to local text files at SERVER -- this plugin to be located in the SERVER FSX\Modules folder -- add this lua to the [Auto] section of the SERVER FSUIPC function recordCOM1(offset, value) file = io.open("com1freq.txt","w") file:write(value) file:close() end function recordCOM2(offset, value) file = io.open("com2freq.txt","w") file:write(value) file:close() end function recordNAV1(offset, value) file = io.open("nav1freq.txt","w") file:write(value) file:close() end function recordNAV2(offset, value) file = io.open("nav2freq.txt","w") file:write(value) file:close() end event.offset(0x034E, "UW", "recordCOM1") event.offset(0x3118, "UW", "recordCOM2") event.offset(0x0350, "UW", "recordNAV1") event.offset(0x0352, "UW", "recordNAV2") and receivenavcom.lua -- lua plugin to copy updated NAV/COM frequencies from .txt files in Server FSX\Modules to local FSUIPC offsets -- this plugin to be located in the CLIENT FSX\Modules folder, and can be run by assigning a key in the CLIENT FSUIPC (I chose key "f") file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\com1freq.txt","r") value = file:read() file:close() ipc.writeUW(0x034E, value) file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\com2freq.txt","r") value = file:read() file:close() ipc.writeUW(0x3118, value) file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\nav1freq.txt","r") value = file:read() file:close() ipc.writeUW(0x0350, value) file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\nav2freq.txt","r") value = file:read() file:close() ipc.writeUW(0x0352, value) The only other thing needed is an Input Director macro (with hotkey) to send a key ("f" in my case) across the network to the Clients, and an assignation of that key at each Client FSUIPC to the Client Lua. Very neat and economical. I tested everything and it all works fine! Thank you once again! Warm Regards, Chakko.
ckovoor Posted August 17, 2014 Author Report Posted August 17, 2014 Hi Pete, I have further simplified matters by writing the offsets into a single file as a string, so for those who are interested, these are the revised lua's: recorddata.lua -- lua plugin to write updated COM/NAV frequencies and other data to local data.txt file at SERVER -- this plugin to be located in the SERVER FSX\Modules folder -- add this lua to the [Auto] section of the SERVER FSUIPC function processdata(offset, value) COM1freq = ipc.readUW(0x034E) COM2freq = ipc.readUW(0x3118) NAV1freq = ipc.readUW(0x0350) NAV2freq = ipc.readUW(0x0352) parkbrake = ipc.readUW(0x0BC8) battery = ipc.readUD(0x281C) -- code string, just numbers in order with non-number separators local value = string.format("COMone=" .. COM1freq .. ",COMtwo=" .. COM2freq .. ",NAVone=" .. NAV1freq .. ",NAVtwo=" .. NAV2freq .. ",parkbrake=" .. parkbrake .. ",battery=" .. battery) file = io.open("data.txt","w") file:write(value) file:close() end event.offset(0x034E, "UW", "processdata") event.offset(0x3118, "UW", "processdata") event.offset(0x0350, "UW", "processdata") event.offset(0x0352, "UW", "processdata") event.offset(0x0BC8, "UW", "processdata") event.offset(0x281C, "UD", "processdata") and receivedata.lua -- lua plugin to copy NAV/COM frequencies and other data from data.txt file in Server FSX\Modules to local FSUIPC offsets -- this plugin to be located in the CLIENT FSX\Modules folder, and can be run by assigning a key in the CLIENT FSUIPC (I chose key "f") file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\data.txt","r") value = file:read() file:close() -- decode string, just numbers in order with non-number separators w = string.gmatch(value, "[+-]?[0-9%.?]+") COM1freq = w() COM2freq = w() NAV1freq = w() NAV2freq = w() parkbrake = w() battery = w() ipc.writeUW(0x034E, COM1freq) ipc.writeUW(0x3118, COM2freq) ipc.writeUW(0x0350, NAV1freq) ipc.writeUW(0x0352, NAV2freq) ipc.writeUW(0x0BC8, parkbrake) ipc.writeUD(0x281C, battery) Rather than run the Client lua's at regular intervals using event.timer, I have decided instead to program a hotkey at the Server to initiate an Input Director macro which sends a keypress to the Clients FSUIPC. I have tested the lua's and they are working fine. Thank you and Paul for the help and patience. Warm Regards, Chakko.
ckovoor Posted August 18, 2014 Author Report Posted August 18, 2014 Hi Pete, Thank you for separating this part of the thread from its parent at http://forum.simflight.com/topic/77415-tuning-radios-on-a-networked-client-running-fsx/ For those of us WidevieW users who do not use Input Director or Key2Lan or any equivalent network tool, or for those who would in any case prefer to use event.timer at the Client lua to automate the transfer of the data across the network, would running the lua there, say on a 500 msec interval, result in any significant addition to the processing load at the Clients? Thank you for your patience and encouragement. Regards, Chakko. For those who are interested, this is the alternative Client plugin: receivedata.lua (alternative) -- lua plugin to copy NAV/COM frequencies and other data from data.txt file in Server FSX\Modules to local FSUIPC offsets -- this plugin to be located in the CLIENT FSX\Modules folder, and is run automatically on a 500 mSec interval (can be changed) -- add this lua to the [Auto] section of the CLIENT FSUIPC function processdata(time) file = io.open("\\\\SERVER\\Microsoft Flight Simulator X\\Modules\\data.txt","r") value = file:read() file:close() -- decode string, just numbers in order with non-number separators w = string.gmatch(value, "[+-]?[0-9%.?]+") COM1freq = w() COM2freq = w() NAV1freq = w() NAV2freq = w() parkbrake = w() battery = w() ipc.writeUW(0x034E, COM1freq) ipc.writeUW(0x3118, COM2freq) ipc.writeUW(0x0350, NAV1freq) ipc.writeUW(0x0352, NAV2freq) ipc.writeUW(0x0BC8, parkbrake) ipc.writeUD(0x281C, battery) end event.timer(500, "processdata")
Pete Dowson Posted August 18, 2014 Report Posted August 18, 2014 For those of us WidevieW users who do not use Input Director or Key2Lan or any equivalent network tool, or for those who would in any case prefer to use event.timer at the Client lua to automate the transfer of the data across the network, would running the lua there, say on a 500 msec interval, result in any significant addition to the processing load at the Clients? No, nothing noticeable at all. Pete
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