# Save protocol and integration :id=top

------

> _Doc Ver:_ 1.0  
_App Ver:_ 2.6.6.53  
_Date:_ 09/14/2026

------

> For integrators and field staff: SA1 **live interfaces stay original**. On-disk save can stay original or switch to **SA2 v1.7** with Data save **1.11** (`DS_SAVE_PROTO`).  
> Do not mix wavelength offsets. Detect the dialect from byte 4 of each frame. CSV columns match original SA1 export.  
> SA1 and SA2 are **mutually exclusive** (UDP **8190**). Do not `killall -9`. After a config change, Save then `:SYS:RELOAD`.

Byte tables: [wavelength 0x00](data-wl.md) · [wavelength 0x10](data-wl-v1.7.md) · [physical 0x04/0x05](data-pv.md) · [physical 0x15](data-pv-v1.7.md) · [data save](data_save.md) · [get data](get_data.md)

On the device: Help → Save protocol. Online: http://192.168.3.9/sa1/help/reader.html#/data-save-proto (internet host `sc.casstk.com`). The settings-page Help button still opens [data save](data_save.md).

------

## 1. What changes, what does not :id=scope

| Path | `DS_SAVE_PROTO=0` (default) | `=1` (optional) |
|------|------------------------------|------------------|
| On-disk `persist/data/wl` | `0x00`, float = absolute pm − 1 500 000 | `0x10`, float = **absolute pm** |
| On-disk `persist/data/pv` | `0x04` / `0x05`, wavelength minus 1 500 000 | `0x15`, wavelength **absolute pm**, extra rate-alarm byte |
| Live UDP **8190** | original | **still original** |
| `:DATA:RAW?` / `:DATA:PV?` | original | **still original** |
| Modbus TCP **1502** | original dense float | **unchanged** |
| Browser `/ws`, spectrum 7094 | original | **unchanged** |
| Register frames `0x20` / `0x21` | SA1 | **still SA1** (not 3.x registers) |
| Mode **2** full-speed sa-ds | original | **still original** |
| On-box CSV (`sa-file`) | original SA1 columns | **same columns** (see §5) |
| Playback `:PLAY:*` | `0x00` | `0x10` converted to `0x00` first; `0x15` **skipped** (no `err++`) |

Only the on-disk dialect changes. Integrators that already consume UDP 8190 / SCPI / Modbus do **not** need live-path code changes. Offline readers of `persist/data/wl` and `pv` must branch on byte 4 (§3).

------

## 2. How to switch in the Web UI :id=web

1. Sign in as admin → Setting → System → **Data save** (or Data → Realtime save → Setting). Same file as `conf/data_save.json`.
2. Check **1.1 Enable**, **1.8 Save wavelength**, and **1.9 Save physical value** if you need PV files. No files usually means 1.1 is off.
3. Set **1.11 Save protocol** to `0` or `1`. Factory is **0**.
4. Click **Save**. AfterCfg sends `:SYS:RELOAD` and should return `0`. Do not `killall -9 sa-di`.
5. Only newly opened volumes use the new dialect. An already open `{stem}.dat.temp` keeps the protocol it started with.
6. Check: Monitor → Data, or SSH:

```bash
/var/sa/bin/sa-file info /var/sa/data/wl/*.dat
/var/sa/bin/sa-file csv -s FILE -o /tmp/csv --kind auto
```

`info` `versions`: `0` = `0x00`, `4`/`5` = `0x04`/`0x05`, `16` = `0x10`, `21` = `0x15`.

------

## 3. Auto-detect (byte 4) :id=detect

Each frame starts with `b[0:4] = 0xFFFFFFFF`. **`b[4]`** is the version. `sa-file` detects per frame, so one file may mix original and v1.7. Names `-wl-` / `-pv-` are only a default kind; `session.dat` / `other.dat` also use `b[4]`.

| `b[4]` | Kind | How wavelength is stored | Length notes |
|:------:|------|--------------------------|--------------|
| `0x00` | wavelength | stored + 1 500 000 = absolute pm | header 67; counts at **35**; floats from 67; end `0xFEFEFEFE` |
| `0x10` | wavelength | **already** absolute pm | `0xFEFEFEFE` at **34**; 32 counts at **38**; `0xFDFDFDFD` at 70; floats from **74**; end `0xFCFCFCFC`; length `78+4N` |
| `0x04` / `0x05` | physical | same as `0x00` | wavelength half-frame, then ID/PV/err/threshold; `0x05` adds virtual |
| `0x15` | physical | **already** absolute pm | uint16 count at **38**; 15-byte records from 44; end `0xFCFCFCFC`; length `48+15N` |
| `0x20` / `0x21` | register | config, not samples | SA1 layout; independent of save protocol |

Do not add 1 500 000 to `0x10`/`0x15` floats. Do not treat `0x00` floats as absolute pm. Do not parse SA1 `0x20` as a 3.x register.

------

## 4. Layout summary :id=layout

### 4.1 Wavelength `0x10`

N is usually 32. Thirty-two count bytes start at offset 38 (empty channels are 0). Floats are in channel order. After [precise wavelength](precise_wl.md) they are calibrated absolute pm. Full table: [wavelength (SA2 v1.7 save)](data-wl-v1.7.md).

### 4.2 Physical `0x15`

Each record is 15 bytes: ID(2) channel(2) error(1) wavelength(4) physical(4) threshold alarm(1) rate alarm(1). Virtual sensors use channel 0 and wavelength 0. SA1 writes **sorted by ID** with **rate alarm = 0** (original `0x04` has one alarm byte → threshold; CSV rate column is 0). Native SA2 may use config order and a non-zero rate byte. CSV still uses the same Chinese header. Full table: [physical (SA2 v1.7 save)](data-pv-v1.7.md).

------

## 5. CSV (same as original SA1) :id=csv

On-box `/var/sa/bin/sa-file`. The Data page runs the same command. Not the old English long table (`time_sec,…,wavelength_pm`) and not desktop saData.

**Wavelength (no header), one row per frame, non-zero peaks only:**

```
{YYYY-MM-DD HH:MM:SS}.{usec6},{unix}.{usec6},{counter},{ch},{wl},…
```

The same peaks and timestamp must export **identical** rows from `0x00` and `0x10`. Example (counter 42, channel 1, three peaks):

```
2023-11-15 06:13:20.123456,1700000000.123456,42,1,1499900.000000,1,1499910.000000,1,1499920.000000
```

**Physical (header once):**

```
ISO时间,Unix时间,计数器,ID,通道,错误码,波长,物理值,阈值报警,变化率报警
```

`0x04` and `0x15` (rate = 0) must export identical rows. Wavelength column is absolute pm.

```bash
sa-file info FILE
sa-file csv -s FILE -o DIR --kind wl|pv|raw|auto
```

`auto` uses the file name, then `b[4]`.

------

## 6. Playback, mode 2, raw :id=play

- Playback is closed uncompressed `wl/` (plus inbox / legacy `rt/`) `.dat` only. `pv` / `raw` do not play.
- `0x10` is converted to `0x00` (offset applied) before the demod path. `0x15` is skipped.
- Mode **2** full-speed sa-ds **ignores** 1.11 and still writes original. Use mode `0` or `1` for v1.7 files.
- **1.10 Raw** stays `SA_DATA_FILE` and is independent of save protocol. See [raw file](data-rawfile.md).

------

## 7. Troubleshooting :id=trouble

| Symptom | Cause | What to do |
|---------|--------|------------|
| Offline wavelength ≈ 1 500 000 too high | Added the offset on `0x10` | Read `b[4]`; do not add on `0x10`/`0x15` |
| CSV ≠ live | Live stays original; disk may be `0x10` | Use UDP/SCPI for live; sa-file for CSV |
| `info` → `frames=0` | Empty PV from Mode 1 before 2.6.6.14, or register-only | Save again after upgrade; `versions` should include 4/5 or 21 |
| `versions` still `[0]` | 1.11 still 0, or mode 2, or no `:SYS:RELOAD` | Check 1.11, mode, Save button |
| No wl/pv files | **1.1 Enable** is off | Check 1.1 and 1.8/1.9 |
| Page has no data | Two `sa-di`, or SA2 still on 8190 | `pgrep -a sa-di`; stop `sa_daq` / `sa_web` / `sa_run` |
| `*VER?` is a stale integer | sa-di did not reload version.json | `sudo systemctl restart sa-di` |

Do not `rsync conf/` onto persist (that resets sensors). Pages only: `bash scripts/sync-runtime.sh --web`.

------

## 8. Acceptance :id=accept

- [ ] Default `DS_SAVE_PROTO=0`: new wl `versions` include `0`; pv includes `4` or `5`
- [ ] After `1` and `:SYS:RELOAD`, new wl includes `16`; pv includes `21`
- [ ] Same peaks: wavelength CSV identical for `0x00` vs `0x10`; physical CSV identical for `0x04` vs `0x15` (rate 0)
- [ ] UDP 8190 / `:DATA:RAW?` version byte is still `0x00` (not `0x10`)
- [ ] Modbus 1502, spectrum page, `/ws` unchanged
- [ ] `sa-file info session.dat` (`0x10` body) → `kind=wl`; `other.dat` with `0x15` → `kind=pv`
- [ ] Exactly one `sa-di`, no SA2 processes

------

## 9. Online help :id=online

| Entry | Where |
|------|--------|
| Device | Help → Save protocol; Handbook tip `SAH2026091401` |
| LAN portal | http://192.168.3.9/sa1/help/ (search「保存协议」「0x10」) |
| Internet portal | http://sc.casstk.com/sa1/help/ (pages only, **no** dist tars) |
| Q&A | http://112.74.47.129:9999 (say SA1 2.x) |
| FAQ | `save-proto` / `save-proto-csv` / `save-proto-offset` |

------

## Change log :id=changelog

|Version|Date|Description|
|:--:|----|----------|
|1.0|09/14/2026|1. Integrator cookbook: live vs disk, auto-detect, CSV identity, playback, mode 2, troubleshooting, portal entries.|

------

[Top](#top)
