Cockpitbuilders.com

LUA Projects => General Discussions => Topic started by: RayS on February 17, 2021, 09:24:15 PM

Title: Need some LUA help.....
Post by: RayS on February 17, 2021, 09:24:15 PM
I'm trying to to get X-Plane FlyWithLUA to connect to an Arduino Mega256.

I have 1 line of code: (After stripping away everything else that isn't failing)

dev = com.open("COM4", 9600, 0)

This code fails with:

lua:1: attempt to index global 'com' (a nil value)

What the heck am I missing?

The error appears to point to a missing DLL or something... I've spent the past couple evenings trying to figure this out and all I've done is bump Heineken Beer stock up a few points.


Title: Re: Need some LUA help.....
Post by: ame on February 17, 2021, 11:52:02 PM
You've probably seen this, but shouldn't that be io.open() ?

https://stackoverflow.com/questions/54603854/read-and-write-to-serial-port-with-lua-on-windows

I hate Lua.
Title: Re: Need some LUA help.....
Post by: navymustang on February 18, 2021, 10:16:15 AM
Have you verified that "COM4" is the exact spelling of the com port the Arduino is connected to. The error is actually telling you that "COM4" is pointing to a nil value.

http://thegeekforge.com/2017/11/10/arduino-lua-fsuipc-tutorial-001_a/

OK - this is for FSX or P3D, but I imagine the same code structure works for both.
Title: Re: Need some LUA help.....
Post by: RayS on February 18, 2021, 09:50:56 PM
I had to post on X-Plane.org for this.

com.open() should work but "com" isn't recognized, nor is "ipc"

I swear I'm missing something stupid-simple...

Title: Re: Need some LUA help.....
Post by: navymustang on February 19, 2021, 04:47:07 AM
The only thing I can think of is that you are missing the COM library with your Lua installation.
Title: Re: Need some LUA help.....
Post by: Fess_ter_Geek on February 19, 2021, 08:14:36 AM
That Geekforge lua code will not work with X-Plane it is for FSUIPC only. Pete included a COM library in FSUIPC with it.

When I first tried to get my radio working with X-Plane, I could not figure out how to get the lua com library installed and or working.

I bailed on FlywithLua, dabbled with C#, and settled with the Python Plugin.
I got the radio working nearly as good as with P3D but acceleration on HDG bug and CRS knob varies from plane to plane. Some airplane devs use their own datarefs which can nul some functionality...until you code it in. Just like in P3D, with devs using custom Lvars, one size does not fit all...without a table, anyway.

The nice thing about the Python plug in is that you can have multiple py scripts running just like LUA in FSUIPC.

If you go with Python Plugin, ye best be knowin how to indent propper like, lest ye be stuck in the damnation of the error log.

~Fess
Title: Re: Need some LUA help.....
Post by: RayS on February 19, 2021, 10:13:21 AM
Thanks, Fess_Ter_Geek!

I was slowly coming to that realization last night that maybe this just won't work in X-Pain.

I'll try the Python plugin. Interestingly, I am learning Python since I need that skill in a new role at work.

Thanks again for the info. Now I can stop bashing my head against the wall.
Title: Re: Need some LUA help.....
Post by: ame on February 19, 2021, 11:44:11 AM
I love Python.
Title: Re: Need some LUA help.....
Post by: Trevor Hale on February 19, 2021, 01:57:51 PM
I HATE SNAKES..........   J/K
Title: Re: Need some LUA help.....
Post by: ame on February 19, 2021, 03:51:24 PM
Quote from: Trevor Hale on February 19, 2021, 01:57:51 PMI HATE SNAKES..........   J/K
My on-again/off-again Python X-Plane library is called SOAP (Snakes on a Plane). It is humourous on so many levels (not least that it isn't finished).