Events are too quick

I am working on the RFXCOM plugin.

It can send commands to different devices. I use it for closing a Harrison curtain rail.

I have two curtains and therefore want to send two commands at sunset. This all works perfectly well, except that the two events get sent so quickly that the RFXCOM device cannot send both commands. The first curtain gets closed but the second stays open…

Therefore I need a way to slow down the implementation file. Does anyone have any ideas?
I think I need a pause of only 100 ms. When I pause longer commands get processed too slow…

How could I do this. Adding a pause to the Implementation file does not seem like a solution…
And is it possible to compare two time variables with a 100 millisecond precision?

Any help appreciated.

http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_sleep

socket.gettime() (see http://code.mios.com/trac/mios_sqblaster/browser/trunk/I_SQBlaster1.xml)

I have been thinking about this problem for the last few days. The problem is not about slowing things down… We want maximum speed after all!

What I need to do is to make sure that the connection to the RFXCOM device is serialized. Where one command after the other gets sent. And I need to make sure the commands do not get sent too quickly one after the other, there needs to be a short pause (50 - 100 ms).

In programming languages there are more than one way to do this. Some languages refer to singleton objects or methods. Others speak of using a semaphore/mutex object to gain access to a resource (being the rfxcom device) and when finished, release the mutex to allow other threads to access the resource.

This leads to new questions:
On a scene with multiple commands, how does the luup processor handle these? One after the other, or parallel through threads?

When I look at the log files, it looks like the commands are sent as events. But how are events processed?

Many questions then. Does any one have some answers?

Is it possible to have a semaphore/mutex or singleton in an implementation file?

Or are there alternatives to limiting access to devices or serial ports for that matter?

I believe that the events are fed from the scene to each device sequentially, but each device can then operate in parallel. When you run ps in a shell on Vera, you can see a bunch of LuaUPnP processes, likely one per device (or implementation, where devices are implemented by their parent device). I don’t know this for sure, but it’s how I’d do it and Vera seems consistent with my conjecture.

Is it possible to have a semaphore/mutex or singleton in an implementation file?

I think you can take advantage of the fact that for a given device’s Luup implementation, it runs sequentially in a single thread (source: http://wiki.micasaverde.com/index.php/Luup_Plugins_ByHand). So you need to arrange for all mutex-able devices to be run by the same implementation. Avoid “job” tasks, which can be asynchronous and stick with “run” tasks. If you need to queue up tasks, add them onto a queue and have your code remove a job from the queue when your code knows that it’s “between” jobs. I do something like this in the Caddx alarm panel code, which you’re welcome to mine for coding ideas.