-
Couldn't load subscription status.
- Fork 10
Messages
You can send custom messages to your script using BasRemoteClient. It's very useful if you want to perform actions like:
- Retrieve results/logs.
- Set/get global variables.
- Show/hide browsers. and other different actions.
You can send a custom message using the send_async method. This method can be used with the await keyword. In this case, the response will be contained in the variable you specify. You can also send message synchronously using asyncio event loop. If want to do this, you can use the event_loop.run_until_complete() function. You can read more about asyncio here.
Take a look at examples:
# Set global variable with name 'TEST_VARIABLE' and value 'Hello'.
await client.send_async('set_global_variable', {
'value': json.dumps('Hello'),
'name': 'TEST_VARIABLE',
})
# Retrieve actual variable value.
actual = await client.send_async('get_global_variable', {
'name': 'TEST_VARIABLE'
})
# Print the value.
print(actual)Among other options, you can just send a custom message. For example, if you want to show the database manager window, you can run the following code:
await client.send('show_database_manager');After sending this message, you will see a manager window.
Main difference between send_async and send methods can be described by the following points:
- The
send_asyncmethod marks the outgoing message as asynchronous. - The
send_asyncmethod sends message and waits for response. - The
sendmethod does not wait for the result.
The use of this methods depends on which message you want to send. You can learn more about it on the BAS official web interface documentation page.