Signals
Signals are mainly used for communication between processes or with external systems.
The system has 256 built-in signals, indexed from 0 to 255. Each signal can store a 32-bit integer value, ranging from -2147483648 to 2147483647.
After the system restarts, all signals are reset to 0.
Set Signal
- Function name: Method
set_signalunder [Robot] - Parameters:
- index: [int] Signal index
- value: [int] Signal value to set
- Return: None
Example Program
lebai:set_signal(0, 1)
lebai.set_signal(0, 1)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "set_signal", "params": [{"key": 0, "value": 0}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }
Set Multiple Signals
Batch set signals starting from the specified index.
- Function name: Method
set_signalsunder [Robot] - Parameters:
- index: [int] Signal starting index
- values: [list[int]] Signal values to set
- Return: None
Example Program
lebai:set_signals(1, {1,2,3})
lebai.set_signals(1, [1, 2, 3])
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "set_signals", "params": [{"key": 0, "values": [1, 2, 3]}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }
Get Signal
- Function name: Method
get_signalunder [Robot] - Parameters:
- index: [int] Signal index
- Return: [int] Value of the corresponding signal
Example Program
value = lebai:get_signal(0)
print(value)
value = lebai.get_signal(0)
print(value)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "get_signal", "params": [{"key": 0}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {"value": 0}, "id": 1 }
Get Multiple Signals
Get multiple continuous signals starting from the specified index.
- Function name: Method
get_signalsunder [Robot] - Parameters:
- index: [int] Signal starting index
- len: [int] Number of signals to get
- Return: [list[int]] Values of the continuous multiple signals
Example Program
values = lebai:get_signals(0, 3)
print(values)
values = lebai.get_signals(0, 3)
print(values)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "get_signals", "params": [{"key": 0, "len": 3}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {"values": [1, 2, 3]}, "id": 1 }
Wait for Signal Condition
Block wait for the specified signal to meet the condition, returning immediately after satisfaction.
Function name: Method
wait_signalunder [Robot]Parameters:
- index: [int] Signal index
- value: [int] Value to compare
- relation: [Relation] Comparison operator, optional, default
EQequal
Return: None
relationvalues:EQEqualNEQNot equalLTLess thanLTELess than or equalGTGreater thanGTEGreater than or equal
Example Program
lebai:wait_signal(0, 1, "EQ")
lebai.wait_signal(0, 1, "EQ")
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "wait_signal", "params": [{"key": 0, "value": 1, "relation": "EQ"}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }
Increment Signal Value
Increment the signal value at the specified index. Be careful of the value range, as overflow may occur.
- Function name: Method
add_signalunder [Robot] - Parameters:
- index: [int] Signal index
- value: [int] Value to increment, can be negative
- Return: None
Example Program
value = lebai:get_signal(0)
lebai:add_signal(0, 10)
value = lebai:get_signal(0)
value = lebai.get_signal(0)
lebai.add_signal(0, 10)
value = lebai.get_signal(0)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "add_signal", "params": [{"key": 0, "value": 0}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }
