read_message()

Reads and returns messages that have been sent from the main application.

This function is used by the host program to communicate with the script by sending a message name and an associated value.

There can be multiple messages waiting. This function transfers all pending messages into the provided dictionary and returns the number of messages read.

Syntax

planetcnc.read_message(dict)

Parameters

Parameter Type Description
dict dict A Python dictionary (passed by reference) into which the pending messages will be inserted. The function expects this parameter to be a valid dictionary object.

Return Value

Examples

#! /usr/bin/env python 
 
import planetcnc
 
# Create an empty dictionary to receive messages.
messages = {}
# Read messages from the module.
num_messages = planetcnc.read_message(messages)
if num_messages > 0:
    print("Received messages:")
    for key, value in messages.items():
        print(f"  {key}: {value}")
else:
    print("No messages received.")

See also

py_msg()

ready
terminate
send_message
read_message