template for generic drivers - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: template for generic drivers (/showthread.php?tid=842) |
template for generic drivers - rocfusion - 16.06.2017 Hi, Maybe this helps someone. Here is basic bi-directional example for connecting the LM to some device that is controlled over TCP. Thanks, Roger Place a resident script with a sleep interval of 0 Code: if not ready then Create event based script for Code: if event.type=='groupwrite' then RE: template for generic drivers - rocfusion - 01.07.2017 Hi, Maybe someone has an idea, based on the above template. I have this TCP device which the LM is controlling. In this case you set a color light value. The light changes to the requested value by cycling through values and returning back a status for each light change. Now there is one caveat, I can bring this light on from the off state to a particular color with the exception of white. When I turn on white it will cycle through to the last light color that was previously on and then the what value has to be resent to get it to change. The time taken to change between any color is variable, changing from one color to another is not always the same. The number of times I receive a the status that the light is changing color is inconsistent. For example, I wish to turn the light to white and the last color the light was on with was green. SEND GOTO WHITE 1 sec later, received LIGHT IS GREEN 1.1 sec later, received LIGHT IS GREEN 0.5 sec later, received LIGHT IS GREEN 2 sec later, received LIGHT IS GREEN 1 sec later, received LIGHT IS GREEN 1.5 sec later, received LIGHT IS GREEN NOW I SEND GOTO WHITE Now for some light colors I may have to wait for 42 responses before I can change to white. My idea is to create some kind of timer every time a status is received. This gets cancelled on receiving a new status. When the timer is reached then send the request to change to white. Now my question is how can I realize this when working with my template. Using Sleep is not really an option because whilst the status of the light is coming back there can be other status values coming back. Is there a way to delay a non blocking function call with the option to cancel it in LUA? Thanks, Roger RE: template for generic drivers - rocfusion - 03.07.2017 Nobody has an idea? RE: template for generic drivers - admin - 04.07.2017 Have a look at this script, it has timers together with receiving data from a socket: https://forum.logicmachine.net/showthread.php?tid=539&pid=2945#pid2945 RE: template for generic drivers - rocfusion - 04.07.2017 Hi, That script I understand, in my script above I am working with Copas, its like nothing is being executed unless there is a send or receive to\from the socket. Thanks, Roger RE: template for generic drivers - admin - 04.07.2017 You have to use copas.step instead of copas.loop RE: template for generic drivers - rocfusion - 04.07.2017 Ok when I use step that code would only execute every time the socket is sending or receiving something. RE: template for generic drivers - rocfusion - 04.07.2017 Hi Admin, I figured it out. I can use copas to add a new thread, then put it to sleep until its needed. Code: co = copas.addthread(function() then when I need to activate it I use Code: copas.wakeup(co) Thanks, Roger |