Jump to content
The simFlight Network Forums

event.com causes lua error and termination when Comport failed to open


Recommended Posts

Hi John,

I have a dormant lua script which communicates with 3 arduinos over 3 comports.
It listens to incoming data from these Comports via an event.com.

Lately sometimes one of these comports do not open, probably a problem with the arduino.
Whats iritating is the fact that the event.com for the not opened Comport generates an error and causes the lua to terminate.
I can test if the Comport is open before sending data but cannot conditionally load the event.com, so if that Comport is not opened, lua exits 
and i would like to just keep running as its perfectly usable with those 2 comports that still work, in fact the failing Comport is hardly used.

I realise that my main problem is the faulty arduino, but it would be nice if i had a possibility to only load the event.com if the port opens correct.
I tried the if statement to only load the event.com if the com.open returned a value >  0 but that doesn´t seem to work.
It happens very intermittantly and i see the problem only after loading the flight.

Is there a way to conditionally load the event.com which i don´t know of, or do you have other suggestions
I attached a logfile in which i repeatedly loaded the lua file again just to see it exit on this error.

Thank you.


Link to comment
Share on other sites

Hi John,

In the attached lua file you can see that i open MainComport at line 184 and it indeed logs an error when the return is 0 (line 186).
on line 4245 to 4247 are event.com events that listen to incoming data from the comports.
If opening MainComPort returns 0, the event.com generates an error and lua terminates.
Yesterday i tried to conditional load the event with: if MainComPort ~= 0 then  event.com(MainComPort, 25, -1, 10, "GetMainData") end 
but that didn't change anything, if MainComPort isn't opened the event.com is still loaded and generates an error.
I was wondering if there is a method to conditionally load that event only if the returned handle is valid.

Don't look at all the commented code because i am building a Helicopter-cyclic based on a arduino but that isn't ready yet so i commented that code out for now.
the lua script performs fine as long as it can open all the Comports.

thanks for taking the time and making such a fine product, as i enjoyed it for years now.
Any sugestions to cope with this intermittend error would be highly appreciated.



Link to comment
Share on other sites

Hi John,

Don't bother for this problem, it is solved.
Just saw that it isn't the Comport that failed to open for which the event.com generates an error and cause lua to terminate but one of the other Comports.
In debugging this i found that i made a THINKING error: if the open of the first Comport fails i also don't open the others, so the conditional load of the event.com did probably work but the others were also not opened and generated the error. 

I moved the event-handlingprocedures in front of the opening of the comports and then load the event only on succesfull opening of the comport.
Now the only error that is logged is the fact that the Comport didn't open but the lua script keeps running albeit with one comport less.
So this indicates that the conditional load of the event.com is possible.

Sorry to bother you with this, which is in fact a programming error.

Have a nice evening.


Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.