Your first program
Quick start tutorial on how to get your first project up and running. This tutorial assumes that you have already created an account, environment and project.
Connecting a device
To connect your first device click "Add" in the Device tree-view facet and name your device.
There are two options
Physical device supports hard or soft real-time. Useful when you want to control real inputs and outputs especially with hard realtime timing constraints.
Virtual machine supports soft real-time only. Create a cloud based instance. Useful for workloads where you need more power but don’t need hard realtime. Also, very useful for simulation when you don’t have a physical device handy.
TIP
Hard real-time means that the programs launched by the agent will have strict timing controls. This makes it suitable for things like machine control, robotics and process control where determinism is a key requirement.
If you have selected a physical device, copy the connection command to the terminal of your device and run it as root user.
Further information on the agent such as compatibility, installation and upgrading can be found here Agents
INFO
The installation is fully automated and typically takes 5-10 minutes. However, it can vary depending on the performance of the hardware.
Once the agent is fully installed it will indicate that in both the terminal of the device and in the "Device" treeview facet with a "Connected" flag.
Code
Once your device is fully connected a default sample python program will already be created.
Physical devices > [Device name] > MyProgram > Files > python.py
The default code snippet is below. This very simple program will print "Hello world" out to the terminal.
class PythonProgram:
def on_initialize(self):
# This method is invoked once, the first time the program runs.
pass
def on_cycle(self):
# This method is invoked every cycle. Put your per-cycle logic here.
print(f"Hello world!")
WARNING
The entire program must be contained within the PythonProgram class. This is due to the architecture of the agent. It will not compile if it does not conform to this structure.
def on_initialize(self):
Code that should only run once on program initialisation should be inserted into the on_initialize(self) definition.
def on_initialize(self):
# This method is invoked once, the first time the program runs.
pass
def on_cycle(self):
Code that should only run every cycle continuously should be inserted into the on_cycle(self) definition. The mutexer platform is centred around programs that continuously execute in a loop as that is the typical mode that industrial automation programs run in. Usually the loop will run as fast as possible but no slower than the maximum watchdog time.
def on_cycle(self):
# This method is invoked every cycle. Put your per-cycle logic here.
print(f"Hello world!")
TIP
The on_cycle(self) section execution at runtime is timed and monitored by the agent. If the time it takes to execute this section of code when set to hard real-time mode exceeds the watchdog timer the program will halt with and error.
Start-up file
The entry point file for the entire program is set in the program settings.
Physical devices > [Device name] > MyProgram > Settings
WARNING
That means all file if they are to run must be called directly by the start-up file or by a file that can trace its call origin to the start-up file.
Build
Now that your have created your first program it's time to built it.
To build your program click the "Build only" button at the top toolbar in the text editor or right-click on your program in the "Device" treeview.
The progress and output of the build process can be viewed in the "Deployments" facet.
INFO
The build can be cancelled anytime by click the corresponding "Cancel" button in the "Deployments" facet.
If the build did not succeed further information about the error will be output to the "Build Output" section.
Deployment
Another option to build your program is the "Build and Deploy" button in the top toolbar in the text editor or in the dropdown when right-clicking on the program itself.
DANGER
However, in this instance after the build process is finished the program will immediately begin to be deployed to the device. As soon as the deployment process is complete the program will start running.
Therefore, please take care when deploying programs to ensure that it is safe to do so.
Programs can be started and stopped through the device agent facet.
Physical devices > [Device name] > Configuration > Agent
Congratulations, you have now successfully deployed your first program from the cloud to your device.