Jump to content
The simFlight Network Forums

ipc.set / get questions


Recommended Posts

I'm doing some work with FSUIPC and Tripod's SuperScripts for the VRS SuperBug.  I want to drive LEDs on a generic HID device in response to Offset changes.  I've prototyped a system and it's working pretty well, but I've had to work around some funnies with the ipc.set and get calls.  So I have some questions about how the ipc.set and get calls work.

 

I wanted to store some tables via these calls.  The documentation appears to state that they will work for 'any type' however my experience is that when trying to retrieve a table, I get back nil.  If I change the variable to a string for example then it works.  Can anyone explain how or why this might be?

 

Possibly related - I wanted to open the HID device in one script and use it elsewhere.  The com.openhid call works fine and I can write my Output Report to the device, LEDs light up etc.  But if I try to store the device handle using ipc.set and later retrieve it for writing via ipc.get then the write call fails.  It seems related to the above issue, any ideas would be appreciated.

 

To deal with this last issue I am opening and closing the HID device handle every time I need to update the LEDs.  However I have a small but noticeable latency between the virtual cockpit annunciators and the LEDs, I suspect the file open / close for every write is hurting me here. 

 

I'm pretty new to Lua, as I learn it further maybe a solution well become apparent.  But if anyone can suggest a means to avoid these repeated openhid calls then that would be most helpful, thanks! 

Link to comment
Share on other sites

So I have some questions about how the ipc.set and get calls work.

 

They use a separate Lua thread which is always running to store and retrieve the variables. That thread contains only its stack, for such data. No code as such.

 

I wanted to store some tables via these calls.  The documentation appears to state that they will work for 'any type' however my experience is that when trying to retrieve a table, I get back nil.  If I change the variable to a string for example then it works.  Can anyone explain how or why this might be?

 

Ah ... just checking the code, by "any type" it looks like I meant "any type of normal scalar" -- it only does numbers and strings. In fact it doesn't even do Booleans! Ouch! Sorry for misleading you.

 

Checking the possibitlies for pushing variables onto stacks in C, I only see those for numbers, strings, booleans, and one called "values". Maybe that last is of more general use and will cover tables etc. I could try -- but only in FSUIPC4 and WideClient. I'm not doing any more development for FS9. Would you like to test such a change?

 

Possibly related - I wanted to open the HID device in one script and use it elsewhere.  The com.openhid call works fine and I can write my Output Report to the device, LEDs light up etc.  But if I try to store the device handle using ipc.set and later retrieve it for writing via ipc.get then the write call fails.  It seems related to the above issue, any ideas would be appreciated.

 

 

No, it is not related. Using devices involves the maintenance of lots of data structures which are thread specific. You cannot handle a device in one thread which was opened in another.

 

To deal with this last issue I am opening and closing the HID device handle every time I need to update the LEDs.

 

Why not simply have a global value which tells you whether it is open or not? In fact the handle itself. If the global hasn't been set, open the device and set it.

 

More usually you would open the device at the start of your Lua program, during initialisation, in the part of the code never re-executed. Globals are only really used for communicating between threads.

 

However I have a small but noticeable latency between the virtual cockpit annunciators and the LEDs, I suspect the file open / close for every write is hurting me here. 

 

There's a lot of memory and data management going on to create the file facilities and tidy up when you close.

 

Regards

Pete

Link to comment
Share on other sites

Checking the possibitlies for pushing variables onto stacks in C, I only see those for numbers, strings, booleans, and one called "values". Maybe that last is of more general use and will cover tables etc. I could try -- but only in FSUIPC4 and WideClient. I'm not doing any more development for FS9. Would you like to test such a change?

 

No. I tried the "value" method, and that only pushes the NAME of the variable. As far as I can see it would be complex to move the entire table from C. It would need iterating through its contents testing each type and constructing a new table in the other thread's stack. I'm not doing that.

 

Regards

Pete

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.