0.60

ReferenceClient librariesExamples

Examples

Runnable Python and TypeScript scripts that write, read, and stream data, run control sequences, and set up hardware tasks.

Each example is a script in the Synnax repository that you can run against your own Core.

Run an example

Enterprise

Most Python examples connect with the login that sy login saves. Log in once, see Log in once with sy login, then run a script:

python basic_read_write.py

The Arduino examples set their connection values in the script.

The control examples and the simulators import other example files. Run them as modules from the client/py folder, with a simulator in a second terminal:

python -m examples.simulators.press
python -m examples.control.press.control_sequence

The README in each folder gives the steps.

Examples by topic

Enterprise

Write, read, and work with data. See Write data and Read data.

Example Shows how to
basic_read_write.py Create channels, write samples, read them back, and plot them.
read_latest.py Read the latest samples of a channel.
series_and_frames.py Work with series and frames.
export_to_csv.py Export samples to a CSV file.
plot.py Plot samples with Matplotlib.

Stream data. See Stream data. The scripts that read live samples need stream_write.py to run in a second terminal.

Example Shows how to
stream_write.py Write live samples with a writer.
stream_read.py Stream live samples.
stream_read_async.py Stream live samples with asyncio.
simulation.py Write many channels and answer commands to many valves.

Channels and ranges. See Channels and Ranges.

Example Shows how to
create_channels.py Create many channels at once.
create_range.py Create a range and read its data.
calculated_channels.py Calculate values from live channels and write them to new channels.
multi-rate-calculated/ Calculate values from channels that have different sample rates.

Control sequences. See Control.

Example Shows how to
control/press/ Pressurize a system in steps with a valve.
control/tpc/ Run a tank pressure control sequence, in Python and in Arc.
control/abort/ Watch for overpressure, take control, and vent the system.
control/virtual.py Send values between scripts through a virtual channel.
simulators/ Simulate hardware, so you can test sequences with no devices.

Hardware tasks. See Hardware. These examples need the Driver and the device. The Modbus, OPC UA, and HTTP folders include a simulated device.

Example Shows how to
ni/ Create National Instruments read, write, and counter tasks.
labjack/ Connect a LabJack and create read and write tasks.
modbus/ Connect a Modbus TCP server and create read and write tasks.
opcua/ Connect an OPC UA server and create read and write tasks.
http_sim/ Connect an HTTP server and create read and write tasks.
arduino/ Write your own driver for an Arduino.
hardware/task_management.py Find, configure, start, and stop tasks.
pagerduty/alert_task.py Open a PagerDuty incident when a status changes.