naboo-py 0.1.0__py3-none-any.whl

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.
naboo/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .client import NabooClient, discover_naboo_resource
2
+
3
+ __version__ = "0.1.0"
4
+ __all__ = ["NabooClient", "discover_naboo_resource"]
naboo/client.py ADDED
@@ -0,0 +1,93 @@
1
+ import argparse
2
+ import sys
3
+ import time
4
+ from typing import List, Tuple
5
+
6
+ import pyvisa
7
+
8
+
9
+ class NabooClient:
10
+ """High-level pyvisa client for the Naboo SCPI digital output controller."""
11
+
12
+ CHANNEL_COUNT = 9
13
+
14
+ def __init__(self, resource_name: str, timeout_ms: int = 2000) -> None:
15
+ self._rm = pyvisa.ResourceManager()
16
+ self.inst = self._rm.open_resource(resource_name)
17
+ self.inst.timeout = timeout_ms
18
+ self.inst.write_termination = "\n"
19
+ self.inst.read_termination = "\n"
20
+
21
+ def close(self) -> None:
22
+ self.inst.close()
23
+ self._rm.close()
24
+
25
+ def __enter__(self) -> "NabooClient":
26
+ return self
27
+
28
+ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
29
+ self.close()
30
+
31
+ def idn(self) -> str:
32
+ return self.inst.query("*IDN?").strip()
33
+
34
+ def queue_on(self, channel: int, duration_ms: int = 0) -> None:
35
+ self._validate_channel(channel)
36
+ self.inst.write(f"DIGital:ON {channel},{duration_ms}")
37
+
38
+ def queue_off(self, channel: int, duration_ms: int = 0) -> None:
39
+ self._validate_channel(channel)
40
+ self.inst.write(f"DIGital:OFF {channel},{duration_ms}")
41
+
42
+ def clear_queues(self) -> None:
43
+ self.inst.write("DIGital:CLEar")
44
+
45
+ def execute(self) -> None:
46
+ self.inst.write("DIGital:EXECute")
47
+
48
+ def execution_bitmap(self) -> int:
49
+ return int(self.inst.query("DIGital:EXECute:STATe?").strip())
50
+
51
+ def pin_state(self, channel: int) -> int:
52
+ self._validate_channel(channel)
53
+ return int(self.inst.query(f"DIGital:STATe? {channel}").strip())
54
+
55
+ def get_queue(self, channel: int) -> List[Tuple[int, int]]:
56
+ self._validate_channel(channel)
57
+ raw = self.inst.query(f"DIGital:QUEue? {channel}").strip()
58
+ if raw == "0" or raw == "":
59
+ return []
60
+
61
+ parts = [int(x) for x in raw.split(",")]
62
+ if len(parts) % 2 != 0:
63
+ raise ValueError(f"Unexpected queue response format: {raw!r}")
64
+
65
+ return [(parts[i], parts[i + 1]) for i in range(0, len(parts), 2)]
66
+
67
+ def wait_until_idle(self, poll_interval_s: float = 0.05, max_wait_s: float = 10.0) -> None:
68
+ deadline = time.monotonic() + max_wait_s
69
+ while self.execution_bitmap() != 0:
70
+ if time.monotonic() > deadline:
71
+ raise TimeoutError("Timed out waiting for Naboo execution_bitmap to return to 0.")
72
+ time.sleep(poll_interval_s)
73
+
74
+ @classmethod
75
+ def _validate_channel(cls, channel: int) -> None:
76
+ if not 1 <= channel <= cls.CHANNEL_COUNT:
77
+ raise ValueError(f"Channel must be between 1 and {cls.CHANNEL_COUNT}, got {channel}")
78
+
79
+
80
+ def discover_naboo_resource() -> str:
81
+ rm = pyvisa.ResourceManager()
82
+ try:
83
+ resources = rm.list_resources()
84
+ if not resources:
85
+ raise RuntimeError("No VISA resources found. Check USB connection and drivers.")
86
+ print("Discovered VISA resources:", resources)
87
+ for res in resources:
88
+ if "USB" in res.upper():
89
+ return res
90
+ return resources[0]
91
+ finally:
92
+ rm.close()
93
+
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.5
2
+ Name: naboo-py
3
+ Version: 0.1.0
4
+ Summary: An python support lib for the Naboo SCPI Device
5
+ Project-URL: Homepage, https://github.com/you/mypackage
6
+ Author-email: Henrique Domiciano <henriquedomiciano@yahoo.com>
7
+ License: MIT
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.9
12
+ Requires-Dist: future>=1.0.0
13
+ Requires-Dist: iso8601>=2.1.0
14
+ Requires-Dist: pyserial>=3.5
15
+ Requires-Dist: pyusb>=1.3.1
16
+ Requires-Dist: pyvisa-py>=0.7.2
17
+ Requires-Dist: pyvisa>=1.14.1
18
+ Requires-Dist: pyyaml>=6.0.3
19
+ Requires-Dist: serial>=0.0.97
20
+ Requires-Dist: typing-extensions>=4.16.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ ### Python Lib support of naboo SCPI device.
26
+
27
+
@@ -0,0 +1,5 @@
1
+ naboo/__init__.py,sha256=kzFj1dTr6qCpC7WvO762yZQjoeVabYRLxRyQqFCrhR4,132
2
+ naboo/client.py,sha256=0jrPs3W5vVa04yzKPI0M0_MgIrq3iVbqVMUS4jAF0PA,3090
3
+ naboo_py-0.1.0.dist-info/METADATA,sha256=KbfglmJm5VDZklbSwJQ0zXDBUQTNGYZG5bf6k1uIZ7Q,835
4
+ naboo_py-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ naboo_py-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any