This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

localbus library documentation
#1
Hello everyone,

really sorry if this have already been asked, but I could not find an answer.
I found many script examples using the localbus library, and I understood how to define a callback function to be called when a groupread or groupwrite telegram is received, but I would like to understand a bit more the details about the localbus library. For example: step and loop methods are the same ? Can I write a callback when an object tag is updated or added ? And so on ...
Can you please direct me to the library documentation ?
Thanks in advance 

Antonio
Reply
#2
localbus is not documented because most users don't need to use it directly.

step waits and processes a single bus message. loop processes all messages received in the give time.

You can listen to reload events which are sent when any object properties are changed (name, tags, datatype, units etc):
Code:
local function reloadhandler(which)
  if which == 'objects' or which == 'all' then
    -- reload object list
  end
end

lb:sethandler('reload', reloadhandler)
Reply
#3
Thank you @admin for your answer.

If I understand correctly, using localbus in a resident script:

(1) If I use, for example, step(10), the resident script waits for a message and,
- if the message arrives before 10 seconds, it calls whatever callbackfunction is defined, and, after that, exit the step(), continues with other instructions and, when it reaches the end of the resident script. it starts the script again
- if the message does not arrive before 10 seconds, after 10 seconds it exit the step(), continues with other instructions and, when it reaches the end of the resident script. it starts the script again
(2) If I use, for example, loop(10), the resident script:
- waits for messages for 10 seconds, and, for each message it receives, it calls whatever callbackfunction is defined
- after 10 seconds it exit the loop(), continues with other instructions and, when it reaches the end of the resident script. it starts the script again

Is this correct ?

The script for the reaload event on the bus is perfect for my need, thank you.

Just one more question: which is the meaning of the timeout I can define when creating the local bus connection ? Has it any relations with the time-out in step() and loop() ?

Thanks again
Reply
#4
Per-message timeout is specified when creating localbus instance via new(timeout). Default timeout is 1 second.

step does not accept any arguments. It uses the per-message timeout.

When using loop the per-message timeout should be low enough otherwise the total function call time might be longer. For example if per-message and loop timeouts are set to 1 then loop can take from 1 to 2 seconds to complete.

You can also use copas library or socket.selectfds:
https://kb.logicmachine.net/scripting/sh...g-dimming/
https://kb.logicmachine.net/scripting/si...ble-press/
Reply
#5
Great, thank you, now it's clear !
Reply


Forum Jump: