Your first capture
Connect, open a demo device, capture, count the edges, close. No hardware
needed: the program runs against se254, a demo device every server offers.
Make sure a server is running first: either the ScanaStudio application, or the
scanastudio-server binary it installs, run on its own. Both are covered under
Installation.
- Python
- NodeJS
- Rust
- C
from ikalogic_scanastudio import ScanaStudio, Trigger
with ScanaStudio.connect() as server:
print(server.info)
for device in server.devices():
print(" ", device.key, device.name)
workspace = server.create("se254")
print(f"\nopened {workspace.device_name} "
f"with {len(workspace.channels)} channels")
last = workspace.capture.run(
samples=1_000_000,
sample_rate=25_000_000,
trigger=Trigger.immediate(),
)
seconds = workspace.capture.seconds(last)
print(f"captured {last} samples ({seconds:.3f} s) "
f"at {workspace.capture.sample_rate} S/s")
edges = sum(1 for _ in workspace.data.transitions(channel=0))
print(f"channel 0 holds {edges} transitions")
workspace.close()
Run it:
python first_capture.py
import { ScanaStudio, Trigger } from '@ikalogic/scanastudio';
const server = await ScanaStudio.connect();
try {
console.log(server.info);
for (const device of await server.devices()) {
console.log(' ', device.key, device.name);
}
const workspace = await server.create('se254');
console.log(`opened ${workspace.device_name} `
+ `with ${workspace.channels.length} channels`);
const last = await workspace.capture.run({
samples: 1_000_000,
sample_rate: 25_000_000,
trigger: Trigger.immediate(),
});
console.log(`captured ${last} samples `
+ `(${workspace.capture.seconds(last).toFixed(3)} s) `
+ `at ${workspace.capture.sample_rate} S/s`);
let edges = 0;
for await (const _ of workspace.data.transitions(0)) edges += 1;
console.log(`channel 0 holds ${edges} transitions`);
workspace.close();
} finally {
server.close();
}
Run it:
node first-capture.mjs
use std::time::Duration;
use scanastudio_client::{CaptureRequest, ScanaStudio, DEFAULT_URL, Result};
#[tokio::main]
async fn main() -> Result<()> {
let server = ScanaStudio::connect(DEFAULT_URL).await?;
println!("{:?}", server.info());
for device in server.devices().await? {
println!(" {} {}", device.key, device.name);
}
let workspace = server.create("se254").await?;
println!("opened {} with {} channels",
workspace.device_name(), workspace.channels().len());
let last = workspace.capture()
.run(&CaptureRequest::new(1_000_000, 25_000_000), Duration::from_secs(300))
.await?;
println!("captured {last} samples ({:.3} s) at {} S/s",
workspace.capture().seconds(last), workspace.capture().sample_rate());
let edges = workspace.data().transitions(0, 0, None).await?;
println!("channel 0 holds {} transitions", edges.len());
workspace.close()?;
Ok(())
}
Run it:
cargo run
#include <stdio.h>
#include <stdlib.h>
#include "scanastudio.h"
static void fail(const char *what) {
const char *reason = ss_last_error();
fprintf(stderr, "%s: %s\n", what, reason ? reason : "no reason given");
exit(1);
}
int main(void) {
ss_server *server = ss_server_connect(NULL);
if (!server) fail("connect");
char *info = ss_server_info(server);
if (info) { printf("%s\n", info); ss_string_free(info); }
char *devices = ss_server_devices(server);
if (devices) { printf("%s\n", devices); ss_string_free(devices); }
ss_workspace *workspace = ss_server_create(server, "se254");
if (!workspace) fail("open");
const char *request = "{\"samples\": 1000000, \"sample_rate\": 25000000}";
if (ss_capture_run(workspace, request, 300.0) < 0) fail("capture");
printf("captured %lld samples at %llu S/s\n",
(long long)ss_capture_last_sample(workspace),
(unsigned long long)ss_capture_sample_rate(workspace));
enum { ROOM = 4096 };
ss_edge *edges = malloc(sizeof(ss_edge) * ROOM);
if (!edges) return 1;
ptrdiff_t written = ss_data_transitions(workspace, 0, 0, -1, edges, ROOM);
if (written < 0) fail("transitions");
printf("channel 0 holds %ld transitions (up to %d)\n", (long)written, ROOM);
free(edges);
ss_workspace_close(workspace);
ss_workspace_free(workspace);
ss_server_disconnect(server);
return 0;
}
Build and run:
cc -I/path/to/scanastudio-c/include first_capture.c \
-L/path/to/scanastudio-c/linux-x86_64 -lscanastudio -o first_capture
LD_LIBRARY_PATH=/path/to/scanastudio-c/linux-x86_64 ./first_capture
Replace /path/to/scanastudio-c with the folder you unpacked the archive into,
and linux-x86_64 with macos-universal on macOS. The Windows command line is
under Installation.
What it printsā
On the se254 demo device:
ScanaStudio 6.0.23 (cd798ee), protocol 8
se254 SE254 (demo)
sq25 SQ25 (demo)
sq50 SQ50 (demo)
sq100 SQ100 (demo)
sq200 SQ200 (demo)
sp209 SP209 (demo)
sp209i SP209I (demo)
sp259 SP259 (demo)
sp259i SP259I (demo)
sp1018 SP1018 (demo)
sp1036 SP1036 (demo)
sp1054 SP1054 (demo)
opened SE254 (demo) with 4 channels
captured 1000000 samples (0.040 s) at 25000000 S/s
channel 0 holds 216 transitions
The transition count changes on every run, since a demo device generates a new pseudo-random signal each time. The version line shows the server you run, and any hardware connected to it is listed before the demo devices.
What just happenedā
connect()connected to the server atws://127.0.0.1:4911and checked that both sides speak the same protocol version.devices()listed what the server can open: your hardware, plus the demo devices.create("se254")created a workspace: a session that owns the device, the capture, and everything attached to it.capture.run()armed the acquisition and waited for it. It returns the index of the last sample captured.transitions(0)read the edges on channel 0. Bulk data is only transferred when you read it.close()ended the workspace on the server.
se254 produces pseudo-random signals, not protocol traffic. It exercises the
whole path (capture, decode, measure, export), which makes it useful for writing
and testing a script, but it will not show you a real I²C address.
workspace.close() ends the session on the server. Disconnecting does not: the
capture keeps running and you can attach to it later. See
Headless datalogger.
Nextā
- Core concepts: the ideas behind what you just ran.
- Decode a bus and export it: the same program, with a protocol decoder and a CSV at the end.
- API reference: every call, in four languages.