slogic32u3-python-libsigrok-stream.py
Python example using libsigrok-python to open the device, configure sampling, and retrieve data packets.
This code requires libsigrok and its Python bindings installed. It illustrates opening the USB connection, configuring the sampling rate (here 800 MS/s for 8 channels), and the data reception loop. Processing raw packets requires specific handling of the binary format.
slogic32u3-python-libsigrok-stream.py
import libsigrok
import numpy as np
import time
def capture_logic():
# Initialiser le contexte libsigrok
ctx = libsigrok.Context()
# Obtenir la liste des pilotes et des appareils
drivers = ctx.driver_list()
# Recherche du pilote SLogic (nom à vérifier selon la version du pilote)
driver = next((d for d in drivers if 'slogic' in d.name.lower()), None)
if not driver:
raise Exception("Pilote SLogic non trouvé")
# Obtenir la liste des appareils pour ce pilote
devices = driver.scan()
if not devices:
raise Exception("Aucun appareil SLogic détecté")
dev = devices[0]
dev.open()
# Configurer les canaux (ex: activer les 8 premiers canaux)
# Note : L'API libsigrok-python peut varier, ceci est une structure type
dev.config_set(libsigrok.CONF_SAMPLE_RATE, 800000000) # 800 MS/s pour 8 canaux
dev.config_set(libsigrok.CONF_NUM_LOGICAL_CHANNELS, 8)
# Démarrer l'acquisition
dev.start()
print("Acquisition en cours...")
data_buffer = []
start_time = time.time()
try:
while time.time() - start_time < 1.0: # 1 seconde
packet = dev.receive()
if packet:
data_buffer.append(packet)
finally:
dev.stop()
dev.close()
# Traitement basique (exemple : compter les transitions sur le canal 0)
# Attention : Le format des données dépend de la configuration (bits/packed)
print(f"Packets reçus : {len(data_buffer)}")
if __name__ == "__main__":
capture_logic()