Browse Source

added delay to fix issue w/ missing datapoint which occurs only when commands are scripted back to back...

curiousmuch 2 years ago
parent
commit
e8e319d534

+ 0 - 0
curiousmeasurements/util/__init__.py


+ 5 - 0
curiousmeasurements/util/rftools.py

@@ -0,0 +1,5 @@
+import numpy as np 
+
+def mag2db(x):
+    return 20*np.log10(np.abs(x))
+

+ 4 - 0
curiousmeasurements/vna/NanoVNA_V2.py

@@ -290,6 +290,10 @@ class NanoVNA_V2_H4:
         self._s11 = [complex()] * self.points
         self._s21 = [complex()] * self.points
 
+        # insert delay 
+        time.sleep(1)   # TODO: review, unsure why this is required, but if it's not performed the next sweep
+                        # is missing a data points
+
     def get_sweep(self) -> List:
         reg = self.read_registers()
         self.freq_start = reg["sweepStartHz"]

+ 26 - 44
curiousmeasurements/vna/VNA.py

@@ -16,75 +16,57 @@
 #
 #  You should have received a copy of the GNU General Public License
 #  along with this program.  If not, see <https://www.gnu.org/licenses/>.
-import logging
-from collections import OrderedDict
-from time import sleep
-from typing import List, Iterator
-from Serial import Interface, drain_serial
 
-logger = logging.getLogger(__name__)
+from .Hardware import get_interfaces
+from .NanoVNA_V2 import NanoVNA_V2_H4
 
+class MetaVna(type):
+    def __call__(cls, *args, **kwargs):
+        return super(MetaVna, NanoVNA_V2_H4).__call__(*args, **kwargs)        
 
-class VNA:
-    name = "VNA"
-    wait = 0.05
+class Vna:
+    name = "Vna" 
 
-    def __init__(self, iface: Interface):
-        self.iface = iface
-        self.valid_freq = None
-        self.valid_power = None
-        self.valid_bw = None
-        self.valid_points = None
+    def __init__(self, *args, **kwargs):
+        super(Vna, self).__init__(*args, **kwargs)
 
         
-        self.freq_start = None
-        self.power = None 
-        self.points = None 
-        self.bw = None
-        
     def connect(self) -> bool:
-        self.iface.open() 
-        return self.iface.isOpen()
+        assert NotImplementedError('Device does not support this method') 
 
     def disconnect(self) -> bool: 
-        self.iface.close()
-        return not self.iface.isOpen()
-
-    def reconnect(self) -> bool: 
-        self.iface.close()
-        sleep(self.wait)
-        self.iface.open()
-        return self.iface.isOpen()
+         assert NotImplementedError('Device does not support this method') 
 
     def set_bw(self): 
-        pass 
+        assert NotImplementedError('Device does not support this method') 
 
     def set_sweep(self, freq_start: float, freq_end: float, points: int):
-        pass
+        assert NotImplementedError('Device does not support this method') 
 
     def get_bw(self) -> float: 
-        pass 
+        assert NotImplementedError('Device does not support this method') 
 
-    def get_sweep(self) -> List: 
-        pass 
+    def get_sweep(self) -> list: 
+        assert NotImplementedError('Device does not support this method') 
 
-    def get_info(self) -> Dict: 
-        pass 
+    def get_info(self) -> dict: 
+        assert NotImplementedError('Device does not support this method') 
 
-    def run(self) -> List: 
-        pass 
+    def measure(self) -> list: 
+        assert NotImplementedError('Device does not support this method') 
 
     def set_power(self, power: float): 
-        pass 
+        assert NotImplementedError('Device does not support this method') 
+ 
 
     def get_power(self) -> float: 
-        pass
+        assert NotImplementedError('Device does not support this method') 
 
-    def set_cal(self): 
-        pass 
+    def set_cal(self):  
+        assert NotImplementedError('Device does not support this method') 
 
     def get_cal(self): 
-        pass 
+        assert NotImplementedError('Device does not support this method')