pilotgil Posted September 18, 2012 Report Posted September 18, 2012 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
Pete Dowson Posted September 18, 2012 Report Posted September 18, 2012 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
pilotgil Posted September 18, 2012 Author Report Posted September 18, 2012 I guess that is what happens after a 15 hour day of work and then you try to code :( you miss the " "...even twice...works now :) I'll download the latest FSUIPC to make sure I have the fix for the ipc.exit bug.
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