half-sample 0.1.19__tar.gz → 0.1.20__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: half_sample
3
- Version: 0.1.19
3
+ Version: 0.1.20
4
4
  Summary: sample data and analysis
5
5
  Home-page: https://github.com/KD-Group/Half.Sample
6
6
  Author: kunde
@@ -24,36 +24,68 @@ cpp_build\daq_capability_test_legacy.exe --help
24
24
  cpp_build\daq_capability_test_xnavi.exe --help
25
25
  ```
26
26
 
27
- ## sample.exe自动选择Instant AI
27
+ ## sample.exe自动选择 Instant AI
28
28
 
29
- Python测量接口支持通过外部发射频率阈值选择采集方式:
29
+ 应用层应把下列三项作为全局采集卡设置,并在每次 `measure` 或 `dump` 时一起传入。
30
+ 推荐的出厂默认值为:
31
+
32
+ - `instant_ai_frequency_threshold=0.1` Hz:Instant/Buffered 切换阈值。
33
+ - `instant_ai_target_points_per_waveform=100`:每个完整波形的目标重建点数。
34
+ - `instant_ai_max_reliable_polling_hz=10`:驱动可靠软件轮询频率上限。
30
35
 
31
36
  ```python
37
+ from sample import sampler
38
+
32
39
  sampler.measure(
33
40
  number_of_waveforms=3,
34
- emitting_frequency=0.1,
35
- instant_ai_frequency_threshold=0.5,
41
+ emitting_frequency=0.05,
42
+ instant_ai_frequency_threshold=0.1,
43
+ instant_ai_target_points_per_waveform=100,
44
+ instant_ai_max_reliable_polling_hz=10,
36
45
  )
37
46
  ```
38
47
 
39
- 阈值默认为0,此时所有旧调用继续使用Buffered AI。阈值大于0时,发射频率小于等于阈值
40
- 选择legacy Instant AI;高于阈值选择原有Buffered AI。Buffered AI内部原有规则保持不变:
41
- 发射频率低于10Hz使用1MHz,否则使用20MHz。
48
+ 当阈值大于 0 且发射频率小于等于阈值时选择 legacy Instant AI;高于阈值时
49
+ 选择原有 Buffered AI。Python API 的阈值参数仍默认为 0,以保证未传新参数的旧程序继续
50
+ 使用 Buffered AI;新集成应显式传入上述三个推荐值。Buffered AI 原有规则保持不变:发射
51
+ 频率低于 10 Hz 使用 1 MHz,否则使用 20 MHz。
42
52
 
43
- Instant AI默认将每个等效完整波形重建为100点,平均次数来自
44
- `number_of_waveforms`。在0.1Hz、3次平均时主体采集时间约30秒。可显式调整目标点数:
53
+ Instant AI 只启动一次连续采集会话。若要得到 `N` 个完整波形,因开始相位未知,计划采集
54
+ 窗口固定为 `(N+1)/f` 秒,不把 `N` 个周期拆成独立任务。例如 `f=0.05 Hz`、`N=1`
55
+ 时计划采集 `(1+1)/0.05 = 40` 秒。实际轮询率为
56
+ `min(f * target_points, max_reliable_polling_hz)`。
57
+
58
+ 采集启动后可轮询进度或请求取消:
45
59
 
46
60
  ```python
47
- sampler.measure(
48
- number_of_waveforms=5,
49
- emitting_frequency=0.1,
50
- instant_ai_frequency_threshold=0.5,
51
- instant_ai_target_points_per_waveform=500,
52
- )
61
+ import time
62
+
63
+ while sampler.is_measuring:
64
+ progress = sampler.sampling_progress()
65
+ print(progress.elapsed_seconds, progress.planned_seconds,
66
+ progress.completed_cycles, progress.target_cycles,
67
+ progress.successful_reads, progress.late_reads)
68
+ # 用户取消时:
69
+ # sampler.cancel_sampling()
70
+ time.sleep(0.2)
71
+
72
+ result = sampler.query()
53
73
  ```
54
74
 
55
- 更低的发射频率不可能快于波形自身周期。Instant AI读取、相位覆盖或重建失败时直接返回
56
- 错误,不会自动回退到Buffered AI。本功能只支持legacy驱动。
75
+ `cancel_sampling()` 是取消请求,不是强制终止线程。真实采集卡的同步 `ReadAny()` 调用期间
76
+ 无法立即中断;取消会在该调用返回后生效。最终应继续轮询 `is_measuring` 并通过
77
+ `query()` 确认 `cancelled=True`。
78
+
79
+ `query()` 稳定公开 `error_category`、`retryable` 和 `cancelled`。Instant AI 采集失败的可重试类别
80
+ 为 `read`、`schedule`、`alignment` 和 `waveform_count`。此外,`state` 表示生命周期或并发冲突,
81
+ `state` 当前也是 `retryable=True`;调用方应等待当前测量结束后再试,不能同时启动另一项采集。
82
+ `config`、`coverage` 和 `cancelled` 必须立即停止。应用层可采用“每次测量最多尝试 3 次”的策略,
83
+ 但应以返回的 `retryable` 和 `error_category` 为准,不应匹配错误文本。每次采集失败后的重试都必须
84
+ 重新采集完整的 `(N+1)/f` 窗口。
85
+
86
+ Instant AI 错误不会自动回退到 Buffered AI。原始数据回放显式兼容 Instant AI V2、
87
+ Instant AI V1 和无标记 Buffered 三种格式;V2 保留计划/实际时间、读取成功状态和原生
88
+ 错误码。Instant AI 采集仅支持 legacy 驱动。
57
89
 
58
90
  ## Legacy Instant AI 轮询验证
59
91
 
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: half-sample
3
- Version: 0.1.19
3
+ Version: 0.1.20
4
4
  Summary: sample data and analysis
5
5
  Home-page: https://github.com/KD-Group/Half.Sample
6
6
  Author: kunde
@@ -21,6 +21,7 @@ class Result:
21
21
  "instant_ai_schedule_timeout": "Instant AI采集超时",
22
22
  "instant_ai_alignment_failed": "Instant AI波形对齐失败",
23
23
  "instant_ai_waveform_count_insufficient": "Instant AI完整波形数量不足",
24
+ "user_cancelled": "用户已取消",
24
25
 
25
26
  # 警告类错误
26
27
  "warning_intr_not_available": "中断资源不可用",
@@ -84,6 +85,18 @@ class Result:
84
85
  self.valid_length = 0 # 有效的波形点数(仅包含上升沿部分)
85
86
  self.number_of_waveforms = 0 # 波形平均次数
86
87
  self.acquisition_mode = ""
88
+ self.error_category = ""
89
+ self.retryable = False
90
+ self.cancelled = False
91
+ self.planned_seconds = 0.0
92
+ self.elapsed_seconds = 0.0
93
+ self.completed_cycles = 0
94
+ self.target_cycles = 0
95
+ self.successful_reads = 0
96
+ self.late_reads = 0
97
+ self.instant_ai_complete_waveforms = 0
98
+ self.instant_ai_planned_duration_seconds = 0.0
99
+ self.instant_ai_actual_duration_seconds = 0.0
87
100
  self.instant_ai_late_reads = 0
88
101
  self.instant_ai_interpolated_bins = 0
89
102
  self.wave = []
@@ -62,25 +62,37 @@ class Sampler:
62
62
 
63
63
  def measure(self, number_of_waveforms: int, emitting_frequency: float, auto_mode: bool = False,
64
64
  instant_ai_frequency_threshold: float = 0.0,
65
- instant_ai_target_points_per_waveform: int = 100) -> Result:
65
+ instant_ai_target_points_per_waveform: int = 100,
66
+ instant_ai_max_reliable_polling_hz: float = 10.0) -> Result:
66
67
  command = "to_measure {} {:.12g} {}".format(number_of_waveforms, emitting_frequency, auto_mode)
67
- if instant_ai_frequency_threshold != 0.0 or instant_ai_target_points_per_waveform != 100:
68
- command += " {:.12g} {}".format(
69
- instant_ai_frequency_threshold, instant_ai_target_points_per_waveform)
68
+ if (instant_ai_frequency_threshold != 0.0 or instant_ai_target_points_per_waveform != 100 or
69
+ instant_ai_max_reliable_polling_hz != 10.0):
70
+ command += " {:.12g} {} {:.12g}".format(
71
+ instant_ai_frequency_threshold, instant_ai_target_points_per_waveform,
72
+ instant_ai_max_reliable_polling_hz)
70
73
  return self.communicate(command)
71
74
 
72
75
  def dump(self, filename: str, number_of_waveforms: int, emitting_frequency: float,
73
76
  auto_mode: bool = False, instant_ai_frequency_threshold: float = 0.0,
74
- instant_ai_target_points_per_waveform: int = 100) -> Result:
77
+ instant_ai_target_points_per_waveform: int = 100,
78
+ instant_ai_max_reliable_polling_hz: float = 10.0) -> Result:
75
79
  command = "to_dump {} {} {:.12g} {}".format(filename, number_of_waveforms, emitting_frequency, auto_mode)
76
- if instant_ai_frequency_threshold != 0.0 or instant_ai_target_points_per_waveform != 100:
77
- command += " {:.12g} {}".format(
78
- instant_ai_frequency_threshold, instant_ai_target_points_per_waveform)
80
+ if (instant_ai_frequency_threshold != 0.0 or instant_ai_target_points_per_waveform != 100 or
81
+ instant_ai_max_reliable_polling_hz != 10.0):
82
+ command += " {:.12g} {} {:.12g}".format(
83
+ instant_ai_frequency_threshold, instant_ai_target_points_per_waveform,
84
+ instant_ai_max_reliable_polling_hz)
79
85
  return self.communicate(command)
80
86
 
81
87
  def process(self, filename: str) -> Result:
82
88
  return self.communicate("to_process {}".format(filename))
83
89
 
90
+ def sampling_progress(self) -> Result:
91
+ return self.communicate("to_sampling_progress")
92
+
93
+ def cancel_sampling(self) -> Result:
94
+ return self.communicate("to_cancel_sampling")
95
+
84
96
  def set_sampler(self, sampler_name: str) -> Result:
85
97
  return self.communicate("set_sampler {}".format(sampler_name))
86
98
 
@@ -2,7 +2,7 @@ import setuptools
2
2
 
3
3
  setuptools.setup(
4
4
  name="half_sample",
5
- version="0.1.19",
5
+ version="0.1.20",
6
6
  author="kunde",
7
7
  author_email="gzkunde@163.com",
8
8
  description="sample data and analysis",
Binary file
File without changes