Jump to content
The simFlight Network Forums

LUA Com Library Help


 Share

Recommended Posts

I just started fooling with Lua and had a few successes. I thought it would be cool to try to write something out a com port such as when a button is pressed. So I wrote this:

dev = com.open(com1, 19200, 0)

if dev == 0 then

ipc.log("Could not open port")

ipc.exit()

end

val = 5.0978056

str = string.format("NUM%04d", val)

com.write(dev, str)

As soon as I press the "button", FS immediately crashes.

However, the com port (a real com port which is tested good) never opens and the log file says that the com port says "LUA. 0: Could not open port" The "val" means nothing, just a number to spit out the com port when I push a button. I am sure I'm missing something simple. I checked the com ports looping two together with Hyperterm and they are working.

I looked at the documentation but I am obviously missing something...any help would be appreciated.

Gil

Link to comment
Share on other sites

dev = com.open(com1, 19200, 0)

...

However, the com port (a real com port which is tested good) never opens and the log file says that the com port says "LUA. 0: Could not open port"

Of course, because the variable you named com1 is never assigned a value. It is, in Lua terms, 'nil' -- non-existent.

I looked at the documentation but I am obviously missing something

Names of ports are strings, as in "com1". Evidently in looking at the documentation you did not actually refer to the com.open function itself, where the presence of the "" is clearly shown -- twice!

The reason you get the error message is because you programmed it so, here:

if dev == 0 then

ipc.log("Could not open port")

ipc.exit()

end

and the only possible reason I can see for FS crashing is that you are using an old and unsupported version of FSUIPC which had a bug in the ipc.exit function! That was fixed a few months ago!

Please, before coming here for support, always check to see you are using the current version -- 3.999w and 4.853 are the main releases at present, with an update 4.856 also available. And please always state the actual version number in use. (See Download Links subforum for updates).

Regards

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.