Appearance
Using Logic Analysers
A Rockface logic analyser allows a set of digital signals to be sampled at a configurable sample rate.
In the rockface
python library, logic analyser tools are represented using the rockface.tools.logic_analyser.LogicAnalyser
type:
py
from rockface import Rig
from rockface.tools.logic_analyser import LogicAnalyser
rig = Rig.find_by_name("my-rig")
analyser = rig.tools["logic"]
assert isinstance(analyser, LogicAnalyser)
Examples continue from the above
For brevity, the rest of the examples on this page will continue on from the above example, with the analyser
variable set to a LogicAnalyser
instance.
Listing Signals
A logic analyser has a set of signals that it can sample. Each of these signals has a name. The list of the signals can be accessed through the signals
property:
py
for name in analyser.signals:
print(f"Signal '{name}'")
Starting a Recording
To make the logic analyser start recording a set of signals, call its start_recording
method. It takes a list of the signal names to record, the sample rate to use (in Hertz), as well as the number of samples to capture:
py
analyser.start_recording(["scl", "sck"],
sample_rate_hz=1_000_000,
samples=500_000)
Recording Status
The is_recording
property indicates whether the analyser is currently recording. When the recording finishes, this property will be False
:
py
import time
while analyser.is_recording:
time.sleep(0.1)
print("Recording has finished!")
Retrieving a Recording
When a recording has completed, it can be accessed through the data
property of the analyser. This property provides a Recording
instance, which contains a polars DataFrame of the sampled data, as well as the sample rate the recording was performed with:
py
rec = analyser.data
print("Sampled signal names:", *rec.data.columns)
print("Sample rate:", rec.sample_rate_hz)
# Print out only the first 10 samples
for scl, sck in rec.data[:10][["scl", "sck"]].iter_rows():
print(f"scl={scl}, sck={sck}")
Sample data types and indexing
The data
field in a Recording
is a polars DataFrame. Each column in the table contains the samples for one signal, with each sample representing the state of the signal as a bool
.
The data
field can be indexed with a signal name, or a sample number. The polars DataFrame type provides a large number of other ways of manipulating the data, and allows easy conversion into pandas DataFrames as well as numpy types.