Setting Up and Using the RPC Server with BuildIT Projector
- Last updated
- Save as PDF
Overview
The RPC (Remote Procedure Call) server allows executing BuildIT commands remotely. Activating this functionality enables using the BuildIT remote control, a browser-based application that offers an interface for conducting inspection and projection workflows.
The functionality can also be leveraged when external systems such as PLCs (Programmable Logic Controllers) or other control systems require driving BuildIT and coordinate the execution of automated processes and measurements commands.
Enabling the RPC server
By default, the RPC server functionality is deactivated. It needs to be activated manually once, and will remain activated whenever launching BuildIT afterwards. To activate the RPC server:
- Open “File: Setting”
- Go to the “Interface” category
- In the “HTTP Server” section, tick the “Enabled” option
- Click “OK”
- Set the appropriate permissions for the network on which you will communicate with the RPC server.
Using the BuildIT Remote Control
The BuildIT Remote Control is a web-based application that offers a convenient interface for conducting inspection and projection workflows. The remote control interfaces with BuildIT using the RPC server and provides a good overview of the capabilities of the framework. To access the remote control application see: Download and Installation Instructions for BuildIT Remote Control
Communicating with External Systems via the RPC Server
The RPC server can be accessed by clients other than the remote control. It can be leveraged for performing communication with PLCs and other control systems.
- If the control system can communicate over WebSocket, it can communicate directly with the RPC server.
- If the control system cannot communicate over WebSocket, we suggest setting up a “broker” or “proxy” application that would translate the inputs from the control system into WebSocket calls, and send back the responses from the RPC server to the control system.
Accessing the RPC Server Documentation
The available commands and expected syntax are available through a web page:
- In a web browser, go to http://localhost:34203/html/rpc_test.html (if needed, replace the digits with the port number defined in the settings).
- Prior to 2020.7, the address is: http://localhost:34203/html/apidoc.html.
- Hit the “Connect” button to connect to the WebSocket server.
- All commands are available from this page and can be tested through this interface.
- The full list of commands can be printed using the “rpc.dir()” command.
Expected Syntax
The RPC server expects a json string over WebSocket. This string should be comprised of the following properties:
- method: Name of the method to run - this name can be obtained via the documentation
- params: Arguments passed to the method
- The definition of arguments can be obtained via the documentation
- Methods that do not expect an argument should be passed the “null” parameter
- id: the id sent along with the request will be sent back with the response
Typical usage
In general, the RPC server’s available functions and mechanisms encourage designs where the external system controls BuildIT, and BuildIT performs the requested actions and commands, and provides handshakes and feedback.
Example: Robot Path Validation with the Laser Tracker
In this application, the external controller (robot controller) and BuildIT need to coordinate and go through a robot path validation workflow. The robot starts at an arbitrary position, and BuildIT acquires data during the robot movement, before performing an analysis. The two systems need to exchange some information before and after the robot movement, and coordinate when to start and stop the acquisition.
During the execution of the process, the controller would coordinate the necessary steps with BuildIT through calls to the RPC server.
In this example, the robot controller performs essentially 5 calls to the RPC server:
- Set global BuildIT variables to be retrieved and used by the process
- Available in BuildIT 2021 - In older versions, the exchange needs to be done via other means
- Launch the process corresponding to the job to be performed
- Launch the measurement when both the robot and BuildIT are ready
- Stop and accept the measurement when the robot has completed its path
- Retrieve the global BuildIT variables set by the process
- Available in BuildIT 2021 - In older versions, the exchange needs to be done via other means
For ensuring that BuildIT is ready to be issued those 5 calls (i.e. validating there is no process already running, knowing when the measurement command is ready, or confirm it has started, validating the process has finished, etc.) the robot controller can by poll the BuildIT RPC server for getting the relevant measurement and process status.
Example: Projection Workflow
In this application, the external controller activates the projection layers pre-defined in the projection plan. Before starting the projection, the controller and BuildIT need to coordinate on a few preliminary steps.
The whole workflow consists of essentially 4 separate calls to the RPC server:
- Opening the model.
- This model contains the layers to be projected.
- Connecting to the projectors in plan.
- Aligning the projectors to retro-targets.
- Those retro-targets are listed in the projection plan and their nominal positions are defined in the BuildIT model.
- Activating the projection layers. This step would generally consist of a loop on the controller’s side. The BuildIT application does not require running any automated process for receiving those calls.
In cases where the projector or the part would be moving using an actuator, performing a dynamic relocation would require calling an automated BuildIT process for moving the projectors to the desired position in the BuildIT model. This step could be called via the RPC server at any point, just like the other steps in the workflow.
Example Client (Python)
import json
import asyncio
import websockets
uri = "ws://localhost:34203/ws/buildit"
commands = [
{
'method' : 'buildit.getProfileName',
'params' : None,
'id' : 1
},
{
'method' : 'buildit.messageBarOutput',
'params' : ['Sending a message via RPC server', 'normal'],
'id' : 2
},
{
'method' : 'buildit.getProcessInfo',
'params' : None,
'id' : 3
}
]
async def send_messages():
try:
async with websockets.connect(uri) as websocket:
for command in commands:
message = json.dumps(command)
await websocket.send(message)
print(f"> {message}")
response = await websocket.recv()
print(f"< {response}")
except OSError:
print(f'Make sure BuildIT is connected and RPC server is running and listening at address {uri}')
asyncio.get_event_loop().run_until_complete(send_messages())
"""
Output:
> {"method": "buildit.getProfileName", "params": null, "id": 1}
< {"id":1,"result":"Metrology"}
> {"method": "buildit.messageBarOutput", "params": ["Sending a message via RPC server", "normal"], "id": 2}
< {"id":2,"result":null}
> {"method": "buildit.getProcessInfo", "params": null, "id": 3}
< {"id":3,"result":{"name":"","path":"","status":"STOP"}}
"""