Skip to content

Instantly share code, notes, and snippets.

@bergkvist
Last active September 21, 2023 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bergkvist/13f8623812256313374c3d5bff0b9f5a to your computer and use it in GitHub Desktop.
Save bergkvist/13f8623812256313374c3d5bff0b9f5a to your computer and use it in GitHub Desktop.
Saleae Logic 2 Automation in Python - working with UART.
# pip install pyserial==3.5 logic2-automation==1.0.6
from saleae import automation
import serial
import time
# Make sure that this is accessible to your Linux user. It probably isn't.
# Run `sudo chmod a+rw /dev/ttyUSB1` to allow everyone on the machine access.
tty = serial.Serial('/dev/ttyUSB1') # UART over USB
# Remember to enable "Automation" in Logic 2 software.
# Preferences > Enable Automation Server ([Ctrl+,] opens preferences)
# 10430 is the default port Logic 2 listens on when this is activated
manager = automation.Manager.connect(port=10430)
# device_id can be left out, or be set to the serial number of your logic analyzer.
# manager.start_capture(...) is non-blocking, and starts the capture in the background.
capture = manager.start_capture(
device_id='0000000000000000',
device_configuration=automation.LogicDeviceConfiguration(
enabled_digital_channels=[0,1,2,3],
enabled_analog_channels=[0,1,2,3],
digital_sample_rate=500_000_000,
analog_sample_rate=12_500_000,
digital_threshold_volts=3.3,
),
capture_configuration=automation.CaptureConfiguration(
capture_mode=automation.TimedCaptureMode(duration_seconds=1.0)
)
)
# You can now do whatever you want for the duration of the capture
# and run any kind of tests your desire
time.sleep(0.5)
tty.write(b'Hello world')
# Analyzers can be added after capture/tests have finished, as you don't want
# adding them to affect the timing of your tests.
# This will helpfully show our decoded UART-data as labels over the waveform
capture.add_analyzer(label='UART RX',
name='Async Serial',
settings={'Input Channel': 2,
'Bit Rate (Bits/s)': 9600,
'Bits per Frame': 8,
'Stop Bits': 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment