summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArturs Artamonovs <dos21h@gmail.com>2023-07-20 18:14:15 +0100
committerArturs Artamonovs <dos21h@gmail.com>2023-07-20 18:14:15 +0100
commitb1bb81e8b8e187c914a68685a55a5b9dcba682c2 (patch)
tree1e9b6dffb8a8454e7edc8e64c8191257fb931c07
parent9c6cb97a447925411a6e346b98ba59b007615997 (diff)
downloadpyairspy-b1bb81e8b8e187c914a68685a55a5b9dcba682c2.tar.gz
pyairspy-b1bb81e8b8e187c914a68685a55a5b9dcba682c2.zip
Added check for library version. Writing test script
-rw-r--r--airspy/__init__.py6
-rw-r--r--airspy/libairspy.py9
-rw-r--r--test.py28
3 files changed, 39 insertions, 4 deletions
diff --git a/airspy/__init__.py b/airspy/__init__.py
index 95f6fac..1e451d4 100644
--- a/airspy/__init__.py
+++ b/airspy/__init__.py
@@ -1,5 +1,7 @@
-from .libairspy import libairspy
+from .libairspy import libairspy, airspy_lib_version_t, airspy_error,airspy_device_t_p, airspy_board_id
from .airspy import AirSpy
+from ctypes import *
+
+__all__ = ["libairspy", "AirSpy", "airspy_lib_version_t", "airspy_error","airspy_device_t_p", "airspy_board_id" ]
-__all__ = ["libairspy", "AirSpy" ] \ No newline at end of file
diff --git a/airspy/libairspy.py b/airspy/libairspy.py
index c5c391f..a642b98 100644
--- a/airspy/libairspy.py
+++ b/airspy/libairspy.py
@@ -169,6 +169,13 @@ airspy_sample_block_cb_fn = PYFUNCTYPE(c_int, POINTER(airspy_transfer_t))
f = libairspy.airspy_lib_version
f.restype, f.argtypes = None, [POINTER(airspy_lib_version_t)]
+#try to load the lib version if its wrong print out warning
+version = airspy_lib_version_t()
+libairspy.airspy_lib_version(byref(version))
+if False == ((int(version.major_version) == 1) and (int(version.minor_version) == 0) and (int(version.revision) == 11)):
+ print("Unsuported version of libairspy.")
+ print("Only supporting 1.0.11")
+ raise ImportError
#/* airspy_init() deprecated */
#extern ADDAPI int ADDCALL airspy_init(void);
@@ -288,7 +295,7 @@ f.restype, f.argtypes = c_int, [airspy_device_t_p, POINTER(c_uint8)]
#/* Parameter length shall be at least 128bytes to avoid possible string clipping */
#extern ADDAPI int ADDCALL airspy_version_string_read(struct airspy_device* device, char* version, uint8_t length);
-f = libairspy.airspy_board_id_read
+f = libairspy.airspy_version_string_read
f.restype, f.argtypes = c_int, [airspy_device_t_p, c_char_p, c_uint8]
#extern ADDAPI int ADDCALL airspy_board_partid_serialno_read(struct airspy_device* device, airspy_read_partid_serialno_t* read_partid_serialno);
diff --git a/test.py b/test.py
index cbc2c6e..b7afb4f 100644
--- a/test.py
+++ b/test.py
@@ -1,9 +1,35 @@
#!/usr/bin/python3
import os
-from airspy import *
from ctypes import *
import time
import sys
import wave
import struct
+try:
+ from airspy import *
+except ImportError:
+ print("Probably unsuported version of libairspy")
+ sys.exit(1)
+print("Check airspy version")
+device = airspy_device_t_p(None)
+
+p = airspy_lib_version_t()
+libairspy.airspy_lib_version(byref(p))
+print(p.major_version)
+print(p.minor_version)
+print(p.revision)
+
+result = libairspy.airspy_init()
+if (result != airspy_error.AIRSPY_SUCCESS):
+ print("Airspy init failed %s (%d)"%(libairspy.airspy_error_name(result), result))
+ sys.exit(1)
+
+result = libairspy.airspy_open(byref(device))
+
+board_id = c_uint8(airspy_board_id.AIRSPY_BOARD_ID_INVALID)
+#result = libairspy.airspy_board_id_read(device, byref(board_id))
+print("Board ID Number: %s "%(str(board_id)))
+
+
+libairspy.airspy_exit()