Flight simulator, EZCA and FreeTrack – restart script v 2.0b

Update 5.2.2015

Hello, maybe you have noticed, maybe not, but the development of EZCA has been resumed. As for the date of this update, there is version 1.18.5 BETA of EZCA available here: EZCA 1.18.5 Beta Available for Download. This new version works with TrackIR interface differently and it seems it eliminates the bug this whole post is about = it now works with FreeTrack without crashing (making my solution redundant). Ok, at least it works for me. It is BETA though, it might bring another issues for you. (I use mainly virtual cockpit views and access them via shortcuts and have no problem with this). So if anyone interested, check out the link above, read through it and decide if you want to try it.

1) Intro:

At first, I did not want to invest any more time into that EZCA issue, as it would be definitely cheaper to buy TrackIR and have no issues rather than trying to solve all the problems arising from concurrent FreeTrack and EZCA usage. But I discovered the “power” that we have thanks to Lua – thanks to its integration within FSUIPC. Thank you Peter Dowson!!! And so the curiosity and my passion to learn new things won again.

I thought: Hey, I can run the script inside FSX and not bother with scheduled tasks at all. Actually, the need to schedule the script is not painful enough to spend another couple of hours rewriting the script written in PowerShell to Lua to get the same functionality (and then writing this post). And I did not even mention that I had to write a small library in C++ to bring some functions required by the script to Lua. But I learned a small of what I can do with FSX and Lua, and C++ so I don’t regret. Besides, the script now can do more, like sending a keystroke to reset view to default one before it kills EZCA, so your camera is not “frozen” to where you were looking during EZCA restart.

I think you will agree that it is irritating when the script restarts EZCA 10 seconds prior landing and you were just looking at instrument and could not move camera because EZCA is off. (You still could have used default shortcuts, but…)

So that was a short long introduction for EZCA restart script version 2.0b, which you can download somewhere down below.

2) I see, but actually I don’t follow…

Ok, words in previous paragraphs was written with one or two expectations: That you already know about my EZCA restart script (Version 1.0 here, 1.1 here) and the problems that exists when using the combination of: FSX, FreeTrack and EZCA.

If you don’t know any of above, I’ll try to say it simple. If you want to use FSX with Freetrack, but also with EZCA, you will experience problems. EZCA and FreeTrack does not like to be run both at the same time. After some time, EZCA will crash (because of memory leak that’s being developing when EZCA receives head movement data from FreeTrack via TrackIR interface). What you have to do than, is close EZCA and FreeTrack and open them again. The EZCA restart script I wrote does this automatically – it closes EZCA before it crashes and opens it again. The first version was written in PowerShell and was executed as scheduled task.

This second version is written in Lua, using my own MouseviatorHelper.dll support library written in C++ and is being executed by FSUIPC – so only when simulator is running. It was primarily written for Flight Simulator X, but I tested it also with Prepar3D (version 2.0 to 2.2). It should work with Prepar3D v1.4, but I did NOT test it.

3) Download

The script uses MouseviatorHelper.dll, which I wrote using Visual Studio 2013. Therefore, you need to have required C++ libraries:

NOTE: For 32 bit Windows, download and install 32 bit version. For 64 bit Windows, download and install both versions.

The script requires FSUIPC. I recommend at least version 4.8, but the more recent you have the better. You should find the most recent version at Pete Dowson’s page:


or here:


And finally, download the script below:

Normal note: The script and MuseviatorHelper.dll are released under LGPL v3 license.

The green note: The package includes source code of MouseviatorHelper.dll library. You can check the source code to make sure it does not hide anything “bad”, at least not programmed on purpose. Also, you can take a look on how to write library that can be used within flight simulator via FSUIPC lua scripting capabilities. It took me some time to make it work from “fragmented” examples I found, so I thought someone might find this “complete example” useful.

The red note: I tested the script on my configuration and did not experience any issues. There is however thousands of another configurations out there. I cannot guarantee that the script will work without issues for you to. This why it is version 2.0b, where the b stands for – BETA. Also, there is the MouseviatorHelper.dll that I wrote in C++. I have to admit however that my C++ proficiency is kind of outdated.  So in the included source code of the library you can confirm there is nothing “bad” hidden, at least not done on purpose. If you find any stupid mistake I might have done, I will be happy to correct it if you let me know. As always, use this software at your own RISK, I take NO RESPONSIBILITY for anything.

4) Installation

  1. Download the script archive from the links above.
  2. Download Visual C++ 2013 Redistributable Packages (If you have 32 bit Windows, download 32 bit version, if you have 64 bit Windows, download both 32 bit and 64 bit package).
  3. Install downloaded Visual C++ Redistributable Packages.
  4. Continue reading below…

The archive contains two folders – „for simulator“ and „MouseviatorHelper source“.

In the „MouseviatorHelper source“ folder there is source code of MousevaitorHelper.dll library (A solution for Visual Studio 2013). You can look at it, fix issues, edit it… You will need to set references for Lua libraries, but it will be no problem for programmer as you. The library was compiled with Lua version 5.1.4.

The “for simulator“ folder contains the EZCA Restart Script with all dependencies. Copy the content of this folder into Modules folder (this is where FSUIPC.dll is also) inside your simulator folder (FSX or Prepar3D).  The full path may look like this: C:\FSX\Modules (as in my case :)). So now, among another files, there will be also:

  • ezca_restart.lua – the EZCA Restart Script.
  • ezca_restart-License.txt – a license for EZCA restart script. Just a copy of LGPL v3 license. Just for your information.
  • ezca_restart-Readme.txt – short information about EZCA restart script.
  • lua\MouseviatorHelper.dll – a lua folder with MouseviatorHelper.dll – the helper library I wrote in C++ for EZCA restart script.
  • lua\MouseviatorHelper_ReferenceManual.pdf – a reference manual listing all functions currently provided by MouseviatorHelper.dll.
  • lua\MouseviatorHelper-License.txt – a license for MouseviatorHelper.dll. Just a copy of LGPL v3 license. Just for your information.
  • dll\Lua5.1.dll – a Lua library used by MouseviatorHelper.dll.

in your Modules folder.

Than you need to somehow execute the script. I recommend that you set it to run automatically with flight simulator. Here comes the two possible solutions on how to do that.

4.1) Add or edit [Auto] section to your FSUIPC4.ini

Open your FSUIPC4.ini with text editor (can be simple notepad) and find section named [Auto]. In this section, add line:

If you already have this section and some script in there, then change the number “1” to the number following right after the last number in this section. For example, if your [Auto] section looks like this:

than change it like that:
If you don’t have [Auto] section in the file, just add this to the end of the FSUIPC.ini file:
Hope it makes sense. It is not so complicated.

4.2) Create or edit ipcReady.lua in your Modules folder.

If you do not have a file called ipcReady.lua in your Modules folder, create one with notepad. The .lua file is simple text file, it just have .lua extension. So create an empty text file and save it as ipcReady.lua (you must select “Save as type: All files” when saving, otherwise it will end up in: ipcReady.lua.txt).

Add this line of code to the ipcReady.lua:

I can’t say which approach is better, it’s up to you.

5) Script description

This will probably sound complicated, but I’ve got a good message for you. You don’t need to understand what is written below, but doing so will allow you to make customizations and set-up the script for your needs. The script should work “as is” with most configurations.

5.1) What it does?

Ok, if you setup the script as written above, in default configuration, it does the following:

  • Check if FreeTrack is running. If it is not, the script terminates.
  • Schedule restart/check function to be executed every couple of seconds.

The restart/check function does the following:

  • Check if FreeTrack and EZCA are running.
  • Check of EZCA memory usage.
  • Sending a keystroke to simulator.
  • Termination of EZCA process.
  • Start of EZCA process.
  • Setting of EZCA process priority.
  • Setting of EZCA process affinity.
  • Keeping simulator window foreground.
  • Maximization, restoration or switching to full-screen or exclusive full-screen of flight simulator main window.

NOTE: Switch to exclusive full-screen means the script will execute press of predefined key combination to toggle between full-screen mode and windowed mode (Alt+Enter by default).

The restart/check function, and the script as whole is heavily driven by script options. Not all actions mentioned above has to be executed. What will be done depends on script settings.

5.2) Modifying behavior

As already told, the script behavior is driven by script settings/options, which are described here. There is a hash of values defining the script options:

I hope the comments are explanatory enough. But those were just the options, we need to turn them into script settings. This is done via the following variable and its value (ie. the options that are currently in use):

The options are combined together by logic OR operation. Enabling or disabling option is as simple as enabling or disabling specific command that sets the specific option as you can see above. The lines starting with double dash — are comments, ie. the command will not execute and the option will not be set. Another way to disable option is to delete the whole line that sets it. But than if you change your mind you will have to write the deleted line again. As you may guess, enabling option is as simple as un-commenting specific line of code or writing it if not present.

Except those setting and options, you might also be interested in following variables:

The most important for you will be EZCA_EXECUTABLE. Make sure it matches the path where you have EZCA installed.

The EZCA_PRIVATE_BYTES_LIMIT is threshold value for EZCA memory consumption. This value is used when EZCA_RESTART_BY_MEM_LIMIT option is enabled. It tells the script what memory consumption is still Ok. If the memory used by EZCA is lower than this value, EZCA will not be restarted. Otherwise,EZCA will be restarted. The value can be different on you system.

SIMULATOR_WINDOW_TEXT is used by script to find main window of simulator. The script needs this to maximize simulator window or switch it to full screen mode (it is required by SIM_MAXIMIZE, SIM_MAKE_FULLSCREEN and SIM_MAKE_EXCLUSIVE_FULLSCREEN options). If you did not set anything that could change the simulator window title, the default value should work with Flight Simulator X. For Prepar3D you need to change this to “Prepar3D“. Or, the value can be completely different text. If for example you monitor simulator VAS usage by FSUIPC and have the value displayed in main simulator window title, you would set this to “Monitor IPC” or something similar. Only partial match is required.

The KEYPRESS defines the key that is sent to simulator before EZCA is killed. This is meant for the purpose of reseting view before it freezes due to EZCA being killed. In the default configuration this is set 49 – this key: 1. I have this set as hot key for “Pilot eyes” view in most EZCA profiles. After this key press is send, script waits AFTER_KEYPRESS_WAIT_TIME milliseconds so that EZCA has time to change view. You will find the possible key code values in the FSUIPC for Advanced users manual.

I think this is all you need to know to just use the script. Of course don’t be afraid to study the script, improve it and let me know about the changes 🙂

6) Trubleshooting

I was in doubt whether to write something like this or not, because based on my own experience, in these type of troubleshooting help text you will not solution for your problem or it will not work… So for the lucky ones:

Problem: There is some error in the FSUIPC.log (or another log file) saying it cannot find or load MouseviatorHelper.dll.
Solution: Every two times I faced this it was because I forgot to install Visual C++ libraries. Download them from above.

Problem: EZCA is not being restarted.
Solution: Make sure you EZCA_EXECUTABLE points to the right executable file. See here. Make sure there exists conditions for EZCA being restarted. Are settings correct? By default, FreeTrack and EZCA must both be running.

Problem: EZCA still crashes before it is restarted.
Solution: If you use option to check EZCA memory consumption, lower the value of EZCA_PRIVATE_BYTES_LIMIT. See here. If you don’t use this option, EZCA should be restarted every time the restart/check function is executed. Than, RESTART_CHECK_PERIOD may be too high or script settings are wrong. (This may require to check the log).

NOTE: Run As Admin!!! If you are running FreeTrack “As Admin” (under Administrator account), make you also run your simulator and EZCA “As Admin”, otherwise script may not have privileges to terminate EZCA.

The log can be very helpful when things doesn’t work. Read next chapter.

7) Knowing what it does

You can “read” what the script does in the FSUIPC.log file (or ezca_restart.log if you enabled to log scripts separately, depends on your FSUIPC logging settings). I think the log messages generated by the script can be located within the log file pretty easily, even if you don’t know what to look for. See:

********* FSUIPC4, Version 4.931 by Pete Dowson *********
Reading options from "C:\Prepar3D v2\Modules\FSUIPC4.ini"
Running inside Prepar3D v2 on Windows 8
Module base=63890000
FSUIPC4 Key is provided
WIDEFS7 not user registered, or expired
 16 System time = 20/04/2014 15:40:24
 16 FLT path = "C:\Users\Murdock\Documents\Prepar3D v2 Files\"
 16 Trying C:\Prepar3D v2\Modules\SimConnectP3D2.dll
 16 Found it: trying to connect
 31 FS path = "C:\Prepar3D v2\"
 328 Run: "C:\Program Files (x86)\FSPS\Sim Physics X\Sim Physics P3D.exe"
 2937 Run: "C:\Prepar3D v2\Modules\linda.exe"
 2953 LogOptions=00000000 00000001
 2953 SIM1 Frictions access gained
 2953 Wind smoothing fix is fully installed
 2953 SimConnect_Open succeeded: waiting to check version okay
 2953 Trying to use SimConnect Prepar3D
 7406 Running in "Lockheed Martin® Prepar3D® v2", Version: 2.2.10438.0 (SimConnect:
 7406 Initialising SimConnect data requests now
 7406 FSUIPC Menu entry added
 7406 C:\Users\Murdock\Documents\Prepar3D v2 Files\My default.FXML
 7406 C:\Prepar3D v2\SimObjects\Airplanes\IRIS Raptor Driver\Raptor.AIR
 25750 C:\Prepar3D v2\SimObjects\Airplanes\Carenado BONANZA A36\A36.AIR
 82219 System time = 20/04/2014 15:41:47, Simulator time = 13:27:34 (20:27Z)
 82219 Aircraft="BONANZA A36 60th ANNIVERSARY"
 83156 Starting everything now ...
 83156 LUA.0: beginning "C:\Prepar3D v2\Modules\ipcReady.lua"
 83156 LUA.0: ended "C:\Prepar3D v2\Modules\ipcReady.lua"
 83172 LUA.2: EZCA Restart Script started...
 83172 Run: "C:\Program Files (x86)\SPAD\SPAD.exe"
 83172 LUA.2: MouseviatorHelper.dll , version: 1.0b , author: Radek Henys, compile date: Mar 28 2014 17:06:56
 83172 LUA.2: freetrack is running and its handle is: 47590300
 83172 LUA.2: Setting EZCA restart function to be called every: 180 seconds
 83172 LUA.2: EZCA Restart Script end...
 83187 LUA.1:
 83187 LUA.1: [INIT]LINDA:: Loading...
 83391 LUA.1: LINDA:: Aircraft: BONANZA A36 60th ANNIVERSARY
 83391 LUA.1: LINDA:: Aircraft module detected: Carenado Bonanza A36
 83422 LUA.0: LINDA:: AivlaSoft library loaded...
 83422 LUA.0: LINDA:: FSX standard library loaded...
 83437 LUA.0: LINDA:: IVAO library loaded...
 83453 LUA.0: LINDA:: RealityXP library loaded...
 83469 LUA.0: LINDA:: Weather library loaded...
 83469 LUA.0: LINDA:: A2A MAP library loaded...
 83578 LUA.0: LINDA:: Loading a fallback joysticks config...
 83594 LUA.0: LINDA:: Loading Carenado Bonanza A36 joysticks config...
 83594 LUA.0: LINDA:: Module: Carenado Bonanza A36 Started...
 83609 LUA.0: LINDA:: Ready to go, Captain!
 83609 LUA.0: LINDA:: 
 83719 LUA.0: LINDA:: [S] LVars watching list cleared...
 83844 LUA.0: LINDA:: [S] Offsets watching list cleared!
 84344 Advanced Weather Interface Enabled
 85125 Ready for ASN WX radar
 91578 Weather Mode now = Theme
 113984 Sim stopped: average frame rate for last 32 secs = 26.9 fps
 263187 LUA.2: freetrack is running and its handle is: 2124186660
 263187 LUA.2: EZCA is running and its handle is: 2124187988
 263203 LUA.2: EZCA private bytes would be around: 107148 by next time the script runs. That is less than safety value of: 153000 . Will wait for next execution. Bye
 443187 LUA.2: freetrack is running and its handle is: 2124189060
 443187 LUA.2: EZCA is running and its handle is: 2124190644
 443187 LUA.2: EZCA private bytes would be around: 114016 by next time the script runs. That is less than safety value of: 153000 . Will wait for next execution. Bye
 623187 LUA.2: freetrack is running and its handle is: 2124191716
 623203 LUA.2: EZCA is running and its handle is: 2124192020
 623203 LUA.2: EZCA private bytes would be around: 133940 by next time the script runs. That is less than safety value of: 153000 . Will wait for next execution. Bye
 803187 LUA.2: freetrack is running and its handle is: 2124192324
 803203 LUA.2: EZCA is running and its handle is: 2124192628
 803203 LUA.2: EZCA private bytes would be around: 155244 by next time the script runs. That is more than safety value of: 153000 .Continuing to restart EZCA...
 803203 LUA.2: Sending key press: 49
 804375 LUA.2: Killing EZCA (handle: 2124192628)
 804891 LUA.2: Trying to run EZCA...
 804953 LUA.2: EZCA started again. Handle is: 2124192932
 804953 LUA.2: Starting EZCA wait loop...
 804953 LUA.2: Trying to return focus to FS...
 805531 LUA.2: Trying to return focus to FS...
 806109 LUA.2: Trying to return focus to FS...
 806625 LUA.2: Trying to return focus to FS...
 807250 LUA.2: Trying to return focus to FS...
 807797 LUA.2: Trying to return focus to FS...
 808344 LUA.2: Trying to return focus to FS...
 808891 LUA.2: Trying to return focus to FS...
 809422 LUA.2: Trying to return focus to FS...
 810016 LUA.2: EZCA wait loop finished!
 810312 LUA.2: Trying to maximize simulator window (Handle: 264502)...
 983203 LUA.2: freetrack is running and its handle is: 2124403076
 983219 LUA.2: EZCA is running and its handle is: 2124403380
 983219 LUA.2: EZCA private bytes would be around: 105846 by next time the script runs. That is less than safety value of: 153000 . Will wait for next execution. Bye
 1163219 LUA.2: freetrack is running and its handle is: 2124403684
 1163219 LUA.2: EZCA is running and its handle is: 2124403988
 1163219 LUA.2: EZCA private bytes would be around: 113028 by next time the script runs. That is less than safety value of: 153000 . Will wait for next execution. Bye
 1235672 Sim stopped: average frame rate for last 1120 secs = 28.4 fps
 1252031 System time = 20/04/2014 16:01:16, Simulator time = 13:46:33 (20:46Z)
 1252031 *** FSUIPC log file being closed
Average frame rate for running time of 1152 secs = 28.4 fps
Memory managed: 562 Allocs, 561 Freed
********* FSUIPC Log file closed ***********

8) Conclusion

Finally, there is the end of this post. Sorry, I also don’t like long reading like this one, I just kind of felt that all those informations are important. Hope some of you sim-aviators will find this work of mine useful.