26
26
200 # Max. characters in frequency reference user setting string
27
27
)
28
28
_DEVINFO_MAX_STRLEN = 19 # Datetime substring length in user setting string
29
- _IQSTREAM_MAX_TRIGGERCOUNT = (
30
- 100 # Max. number of trigger events that can be reported by IQSTREAM_GetIQData
31
- )
29
+
32
30
# ENUMERATION TUPLES
33
31
34
32
_DEV_EVENT = ("OVERRANGE" , "TRIGGER" , "1PPS" )
@@ -121,8 +119,8 @@ class _IQStreamFileInfo(Structure):
121
119
class _IQStreamIQInfo (Structure ):
122
120
_fields_ = [
123
121
("timestamp" , c_uint64 ),
124
- ("triggerCount" , c_int32 ),
125
- ("triggerIndices" , c_int32 * _IQSTREAM_MAX_TRIGGERCOUNT ),
122
+ ("triggerCount" , c_int ),
123
+ ("triggerIndices" , POINTER ( c_int ) ),
126
124
("scaleFactor" , c_double ),
127
125
("acqStatus" , c_uint32 ),
128
126
]
@@ -135,7 +133,7 @@ class RSAError(Exception):
135
133
def __init__ (self , err_txt = "" ):
136
134
self .err_txt = err_txt
137
135
err = "RSA Error: {}" .format (self .err_txt )
138
- super (RSAError , self ).__init__ (err )
136
+ super ().__init__ (err )
139
137
140
138
141
139
class RSA :
@@ -2188,7 +2186,7 @@ def IQSTREAM_Tempfile_NoConfig(
2188
2186
IQ data, with each element in the form (I + j*Q)
2189
2187
iq_status : str (optional)
2190
2188
The status string for the IQ capture, as defined in
2191
- the documentation for IQSTREAM_StatusParser ().
2189
+ the documentation for IQSTREAMFileInfo_StatusParser ().
2192
2190
"""
2193
2191
# Configuration parameters
2194
2192
dest = _IQS_OUT_DEST [3 ] # Split SIQ format
@@ -2224,7 +2222,7 @@ def IQSTREAM_Tempfile_NoConfig(
2224
2222
2225
2223
# Check acquisition status
2226
2224
file_info = self .IQSTREAM_GetDiskFileInfo ()
2227
- iq_status = self .IQSTREAM_StatusParser (file_info , not return_status )
2225
+ iq_status = self .IQSTREAMFileInfo_StatusParser (file_info , not return_status )
2228
2226
2229
2227
self .DEVICE_Stop ()
2230
2228
@@ -2277,7 +2275,7 @@ def IQSTREAM_Tempfile(
2277
2275
IQ data, with each element in the form (I + j*Q)
2278
2276
iq_status : str (optional)
2279
2277
The status code for the IQ capture, as defined in
2280
- the documentation for IQSTREAM_StatusParser ().
2278
+ the documentation for IQSTREAMFileInfo_StatusParser ().
2281
2279
"""
2282
2280
# Configuration parameters
2283
2281
dest = _IQS_OUT_DEST [3 ] # Split SIQ format
@@ -2316,7 +2314,7 @@ def IQSTREAM_Tempfile(
2316
2314
2317
2315
# Check acquisition status
2318
2316
file_info = self .IQSTREAM_GetDiskFileInfo ()
2319
- iq_status = self .IQSTREAM_StatusParser (file_info , not return_status )
2317
+ iq_status = self .IQSTREAMFileInfo_StatusParser (file_info , not return_status )
2320
2318
2321
2319
self .DEVICE_Stop ()
2322
2320
@@ -2337,27 +2335,26 @@ def IQSTREAM_Tempfile(
2337
2335
return iq_data
2338
2336
2339
2337
@staticmethod
2340
- def IQSTREAM_StatusParser (
2341
- iq_stream_info : Union [_IQStreamFileInfo , _IQStreamIQInfo ], exit : bool = True
2342
- ):
2343
- """
2344
- Parse _IQStreamFileInfo or _IQStreamIQInfo to get acquisition status.
2345
-
2346
- Depending on the 'exit' parameter, this method will either raise an
2347
- error, or return a status string. Possible values for the
2348
- returned status indicator are:
2349
-
2350
- status | Definition
2351
- -------------------
2352
- 0 | No error
2353
- 1 | Input overrange.
2354
- 2 | USB data stream discontinuity.
2355
- 3 | Input buffer > 75% full.
2356
- 4 | Input buffer overflow. IQ Stream processing
2357
- | too slow. Data loss has occurred.
2358
- 5 | Output buffer > 75% full.
2359
- 6 | Output buffer overflow. File writing
2360
- | too slow. Data loss has occurred.
2338
+ def IQSTREAMFileInfo_StatusParser (
2339
+ iq_stream_info : _IQStreamFileInfo , exit : bool = True
2340
+ ) -> Union [None , str ]:
2341
+ """
2342
+ Parse an _IQStreamFileInfo struct to get the acquisition status.
2343
+
2344
+ Depending on the ``exit`` parameter, this method will either raise an
2345
+ error or return a status string. Possible values for the
2346
+ returned status string (when ``exit`` is False):
2347
+
2348
+ - No error
2349
+ - Input overrange.
2350
+ - USB data stream discontinuity.
2351
+ - Input buffer > 75% full.
2352
+ - Input buffer overflow. IQ Stream processing
2353
+ too slow. Data loss has occurred.
2354
+ - Output buffer > 75% full.
2355
+ - Output buffer overflow. File writing
2356
+ too slow. Data loss has occurred.
2357
+ - Invalid status code returned. Some always-zero bits are nonzero.
2361
2358
2362
2359
In the case of multiple status codes being returned, the status
2363
2360
string will contain all returned status strings, separated by line
@@ -2368,8 +2365,10 @@ def IQSTREAM_StatusParser(
2368
2365
iq_stream_info : _IQStreamFileInfo
2369
2366
The IQ streaming status information structure.
2370
2367
exit : bool
2371
- If True, raise an exception for any error status in the IQ stream.
2372
- If False, return a flag representing the error, without raising an exception.
2368
+ If True, raise an exception for any error or warning status in the
2369
+ IQ stream. Return None if there is no error or warning.
2370
+ If False, return a string indicating the status, without raising
2371
+ an exception.
2373
2372
2374
2373
Returns
2375
2374
-------
@@ -2379,21 +2378,22 @@ def IQSTREAM_StatusParser(
2379
2378
Raises
2380
2379
------
2381
2380
RSAError
2382
- If errors have occurred during IQ streaming, and exit is True.
2381
+ If errors or warnings have occurred during IQ streaming, and
2382
+ ``exit`` is True.
2383
2383
"""
2384
2384
status = iq_stream_info .acqStatus
2385
+ status_str = ""
2385
2386
2386
2387
# Handle no error case
2387
2388
if status == 0 :
2388
2389
if exit :
2389
2390
return
2390
2391
else :
2391
- return "No error."
2392
+ status_str += "No error."
2392
2393
else :
2393
2394
# Construct status string if status != 0
2394
- status_str = ""
2395
2395
if bool (status & 0x10000 ): # mask bit 16
2396
- status_str += "Input overrange\n . "
2396
+ status_str += "Input overrange. \n "
2397
2397
if bool (status & 0x20000 ): # mask bit 17
2398
2398
status_str += "USB data stream discontinuity.\n "
2399
2399
if bool (status & 0x40000 ): # mask bit 18
@@ -2406,12 +2406,95 @@ def IQSTREAM_StatusParser(
2406
2406
if bool (status & 0x200000 ): # mask bit 21
2407
2407
status_str += "Output buffer overflow. File writing too slow, "
2408
2408
status_str += "data loss has occurred.\n "
2409
+ if bool (status & 0xFFC00000 ):
2410
+ status_str += (
2411
+ "Invalid status code returned. Some always-zero bits are nonzero."
2412
+ )
2409
2413
if exit :
2410
2414
# Raise error with full string if configured
2411
2415
raise RSAError (status_str )
2416
+ return status_str
2417
+
2418
+ @staticmethod
2419
+ def IQSTREAMIQInfo_StatusParser (
2420
+ iq_stream_info : _IQStreamIQInfo , exit : bool = True
2421
+ ) -> Union [None , str ]:
2422
+ """
2423
+ Parse an _IQStreamIQInfo struct to get the acquisition status.
2424
+
2425
+ Depending on the ``exit`` parameter, this method will either raise an
2426
+ error or return a status string. Possible values for the
2427
+ returned status string (when ``exit`` is False):
2428
+
2429
+ - No error
2430
+ - Input overrange.
2431
+ - USB data stream discontinuity.
2432
+ - Input buffer > 75% full.
2433
+ - Input buffer overflow. IQ Stream processing
2434
+ too slow. Data loss has occurred.
2435
+ - Output buffer > 75% full.
2436
+ - Output buffer overflow. File writing
2437
+ too slow. Data loss has occurred.
2438
+ - Invalid status code returned. Some always-zero bits are nonzero.
2439
+
2440
+ In the case of multiple status codes being returned, the status
2441
+ string will contain all returned status strings, separated by line
2442
+ breaks.
2443
+
2444
+ Parameters
2445
+ ----------
2446
+ iq_stream_info : _IQStreamIQInfo
2447
+ The IQ streaming status information structure.
2448
+ exit : bool
2449
+ If True, raise an exception for any error or warning status in the
2450
+ IQ stream. Return None if there is no error or warning.
2451
+ If False, return a string indicating the status, without raising
2452
+ an exception.
2453
+
2454
+ Returns
2455
+ -------
2456
+ status: str
2457
+ A string containing all returned status messages.
2458
+
2459
+ Raises
2460
+ ------
2461
+ RSAError
2462
+ If errors or warnings have occurred during IQ streaming, and
2463
+ ``exit`` is True.
2464
+ """
2465
+ status = iq_stream_info .acqStatus
2466
+ status_str = ""
2467
+
2468
+ # Handle no error case
2469
+ if status == 0 :
2470
+ if exit :
2471
+ return
2412
2472
else :
2413
- # Or just return the status string
2414
- return status_str
2473
+ status_str += "No error."
2474
+ else :
2475
+ # Construct status string if status != 0
2476
+ if bool (status & 0x10000 ): # mask bit 16
2477
+ status_str += "Input overrange.\n "
2478
+ if bool (status & 0x20000 ): # mask bit 17
2479
+ status_str += "USB data stream discontinuity.\n "
2480
+ if bool (status & 0x40000 ): # mask bit 18
2481
+ status_str += "Input buffer > 75{} full.\n " .format ("%" )
2482
+ if bool (status & 0x80000 ): # mask bit 19
2483
+ status_str += "Input buffer overflow. IQStream processing too"
2484
+ status_str += " slow, data loss has occurred.\n "
2485
+ if bool (status & 0x100000 ): # mask bit 20
2486
+ status_str += "Output buffer > 75{} full.\n " .format ("%" )
2487
+ if bool (status & 0x200000 ): # mask bit 21
2488
+ status_str += "Output buffer overflow. File writing too slow, "
2489
+ status_str += "data loss has occurred.\n "
2490
+ if bool (status & 0xFFC00000 ):
2491
+ status_str += (
2492
+ "Invalid status code returned. Some always-zero bits are nonzero."
2493
+ )
2494
+ if exit :
2495
+ # Raise error with full string if configured
2496
+ raise RSAError (status_str )
2497
+ return f"{ status_str } , { status = } "
2415
2498
2416
2499
def SPECTRUM_Acquire (
2417
2500
self , trace : str = "Trace1" , trace_points : int = 801 , timeout_msec : int = 50
@@ -2564,7 +2647,7 @@ def IQSTREAM_Acquire(
2564
2647
IQ data, with each element in the form (I + j*Q)
2565
2648
iq_status : str (optional)
2566
2649
The status string for the IQ capture, as defined in
2567
- the documentation for IQSTREAM_StatusParser ().
2650
+ the documentation for IQSTREAMIQInfo_StatusParser ().
2568
2651
"""
2569
2652
dest = _IQS_OUT_DEST [0 ] # Client
2570
2653
dtype = _IQS_OUT_DTYPE [0 ] # Single
@@ -2618,7 +2701,7 @@ def IQSTREAM_Acquire(
2618
2701
assert len (iqdata ) == iq_samples_requested
2619
2702
2620
2703
if return_status :
2621
- iq_status = self .IQSTREAM_StatusParser (iqinfo , not return_status )
2704
+ iq_status = self .IQSTREAMIQInfo_StatusParser (iqinfo , not return_status )
2622
2705
return iqdata , iq_status
2623
2706
else :
2624
2707
return iqdata
0 commit comments