-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial
Zentetsu edited this page Nov 7, 2024
·
8 revisions
Short example of Sender-Listener (Publisher-Subscriber) communication.
It's important to define the JSON as follow:
{
"name": "Module_1",
"sender": {
"shared_list": [0, 1, 2]
},
"listener": {}
}Structure:
-
name: Define the name of the module that will be loaded -
sender: Define theSharedMemorythat will be used by the module (updating data) -
listener: Define theSharedMemorythat will be observed
Optional:
-
remote: This option can be defined in a case of remote communication between module see here
WARNING: Be careful with the initial size of a shared data as it cannot be changed dynamically. It's possible to assign a specific size by using the option size. However, it can be only used with a JSON file.
from IRONBark import Module
# Initialize Module 1 and create the associated SharedMemory
m = Module(file="Module_1.json")
# Make the SharedMemory available
m.startModule()
# Get a copy of the stored data from the SharedMemory
shared_data = m.getValue("sender_1")
# Update the value inside the SharedMemory
m.setValue("sender_1", [0, 0, 0])
# Close the access and clear the Sharedmemory
m.stopModule()It's important to define the JSON as follow:
{
"name": "Module_2",
"sender": {},
"listener": {
"shared_list": []
}
}listener:
- Is a
dictthat will contain all the observed data - Each data are associated with a
listwhich can be define like here in the case of a remote communicaiton
from IRONBark import Module
# Initialize Module 1 to be ready to access to the SharedMemory
m = Module(file="Module_2.json")
# Attempt to link and access to the SharedMemory
m.startModule()
# Get a copy of the stored data from the SharedMemory only if the sahred space is already created
shared_data = m.getValue("sender_1")
# Close the access to the Sharedmemory
m.stopModule()It's only possible to update the data from the SharedMemory from the Listener side during a local communication
{
"name": "Module_1",
"remote": {
"ip": "127.0.0.1",
"port": "12345"
},
"sender": {
"shared_list": [0, 1, 2]
},
"listener": {}
}{
"name": "Module_2",
"sender": {},
"listener": {
"shared_list": ["127.0.0.1", "12345"]
}
}