This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Add RSA blocks #43
Open
dstrande
wants to merge
5
commits into
main
Choose a base branch
from
dallas/stu-196-add-rsa-api-and-fix-gallery-apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add RSA blocks #43
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64ed81d
Add RSA blocks
dstrande 132a5c0
Merge branch 'main' into dallas/stu-196-add-rsa-api-and-fix-gallery-apps
dstrande 05a7559
f405s
dstrande de8e21c
Merge branch 'dallas/stu-196-add-rsa-api-and-fix-gallery-apps' of htt…
dstrande e6501e6
Merge branch 'main' into dallas/stu-196-add-rsa-api-and-fix-gallery-apps
39bytes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
blocks/HARDWARE/SIGNAL_ANALYZERS/TEKTRONIX/RSA500/BLOCK_IQ_RSA500/BLOCK_IQ_RSA500.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
from flojoy import flojoy, DataContainer, OrderedPair | ||
from typing import Optional, TypedDict | ||
from flojoy.instruments.tektronix.RSA_API import * # noqa: F403 | ||
from ctypes import cdll, c_int, c_bool, c_double, c_float, byref | ||
from os import path | ||
import numpy as np | ||
|
||
|
||
class IQSplitOutput(TypedDict): | ||
I_real: OrderedPair | ||
Q_imag: OrderedPair | ||
|
||
|
||
@flojoy | ||
def BLOCK_IQ_RSA500( | ||
input: Optional[DataContainer] = None, | ||
center_freq: float = 100e6, | ||
ref_level: float = -30, | ||
record_length: float = 1e3, | ||
bandwidth: float = 5e5, | ||
) -> IQSplitOutput: | ||
"""Extract Block IQ measurement from a Tektronix RSA. | ||
|
||
This block should also work with compatible Tektronix RSAXXX instruments. | ||
|
||
Tested with RSA507a. | ||
|
||
Parameters | ||
---------- | ||
center_freq : float, default=100e6 | ||
The center frequency, in Hz. | ||
ref_level : float, default=-30 | ||
The reference level (the maximum y axis value), in dBm. | ||
record_length : float, default=1e3 | ||
The length to record (length of x axis), in ms. | ||
bandwidth : float, default=5e5 | ||
Resolution bandwidth, in Hz. | ||
|
||
Returns | ||
------- | ||
I_real: OrderedPair | ||
x: time | ||
y: power | ||
Q_imag: OrderedPair | ||
x: time | ||
y: power | ||
""" | ||
|
||
# Connect to RSA | ||
defau = "C:/Tektronix/RSA_API/lib/x64/RSA_API.dll" | ||
moved = "C:/Program Files/Tek/RSA_API/lib/x64/RSA_API.dll" | ||
if path.isfile(defau): | ||
rsa = cdll.LoadLibrary(defau) | ||
elif path.isfile(moved): | ||
rsa = cdll.LoadLibrary(moved) | ||
else: | ||
raise FileNotFoundError( | ||
"Cannot find RSA_API.dll. Download from: https://www.tek.com/en/products/spectrum-analyzers/rsa500" | ||
) | ||
|
||
numFound = c_int(0) | ||
intArray = c_int * DEVSRCH_MAX_NUM_DEVICES # noqa: F405 | ||
deviceIDs = intArray() | ||
deviceSerial = create_string_buffer(DEVSRCH_SERIAL_MAX_STRLEN) # noqa: F405 | ||
deviceType = create_string_buffer(DEVSRCH_TYPE_MAX_STRLEN) # noqa: F405 | ||
apiVersion = create_string_buffer(DEVINFO_MAX_STRLEN) # noqa: F405 | ||
|
||
rsa.DEVICE_GetAPIVersion(apiVersion) | ||
|
||
err_check(rsa.DEVICE_Search(byref(numFound), deviceIDs, deviceSerial, deviceType)) | ||
|
||
# note: the API can only currently access one at a time | ||
# Connects to first available | ||
err_check(rsa.DEVICE_Connect(deviceIDs[0])) | ||
rsa.CONFIG_Preset() | ||
|
||
# Configure spectrum | ||
cf = center_freq | ||
refLevel = ref_level | ||
iq_bw = bandwidth | ||
record_length | ||
record_length = int(record_length) | ||
rsa.CONFIG_SetCenterFreq(c_double(cf)) | ||
rsa.CONFIG_SetReferenceLevel(c_double(refLevel)) | ||
rsa.IQBLK_SetIQBandwidth(c_double(iq_bw)) | ||
rsa.IQBLK_SetIQRecordLength(c_int(record_length)) | ||
|
||
# Create array of time data for plotting IQ vs time | ||
iqSampleRate = c_double(0) | ||
rsa.IQBLK_GetIQSampleRate(byref(iqSampleRate)) | ||
time = np.linspace(0, record_length / iqSampleRate.value, record_length) | ||
|
||
# Acquire data | ||
record_length = int(record_length) | ||
ready = c_bool(False) | ||
iqArray = c_float * record_length | ||
iData = iqArray() | ||
qData = iqArray() | ||
outLength = 0 | ||
rsa.DEVICE_Run() | ||
rsa.IQBLK_AcquireIQData() | ||
while not ready.value: | ||
rsa.IQBLK_WaitForIQDataReady(c_int(100), byref(ready)) | ||
rsa.IQBLK_GetIQDataDeinterleaved( | ||
byref(iData), byref(qData), byref(c_int(outLength)), c_int(record_length) | ||
) | ||
rsa.DEVICE_Stop() | ||
rsa.DEVICE_Disconnect() | ||
|
||
return IQSplitOutput( | ||
I_real=OrderedPair(x=time, y=np.array(iData)), | ||
Q_imag=OrderedPair(x=time, y=np.array(qData)), | ||
) | ||
|
||
|
||
def err_check(rs): | ||
if ReturnStatus(rs) != ReturnStatus.noError: # noqa: F405 | ||
raise RSAError(ReturnStatus(rs).name) # noqa: F405 |
197 changes: 197 additions & 0 deletions
197
blocks/HARDWARE/SIGNAL_ANALYZERS/TEKTRONIX/RSA500/BLOCK_IQ_RSA500/app.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
{ | ||
"rfInstance": { | ||
"nodes": [ | ||
{ | ||
"width": 192, | ||
"height": 192, | ||
"id": "BLOCK_IQ_RSA500-33713d6b-4202-414e-b8a3-2d9870aa0c7e", | ||
"type": "HARDWARE", | ||
"data": { | ||
"id": "BLOCK_IQ_RSA500-33713d6b-4202-414e-b8a3-2d9870aa0c7e", | ||
"label": "BLOCK IQ RSA500", | ||
"func": "BLOCK_IQ_RSA500", | ||
"type": "HARDWARE", | ||
"ctrls": { | ||
"center_freq": { | ||
"type": "float", | ||
"default": 100000000, | ||
"desc": "The center frequency, in Hz.", | ||
"overload": null, | ||
"functionName": "BLOCK_IQ_RSA500", | ||
"param": "center_freq", | ||
"value": 99300000 | ||
}, | ||
"ref_level": { | ||
"type": "float", | ||
"default": -30, | ||
"desc": "The reference level (the maximum y axis value), in dBm.", | ||
"overload": null, | ||
"functionName": "BLOCK_IQ_RSA500", | ||
"param": "ref_level", | ||
"value": -30 | ||
}, | ||
"record_length": { | ||
"type": "float", | ||
"default": 1000, | ||
"desc": "The length to record (length of x axis), in ms.", | ||
"overload": null, | ||
"functionName": "BLOCK_IQ_RSA500", | ||
"param": "record_length", | ||
"value": 500 | ||
}, | ||
"bandwidth": { | ||
"type": "float", | ||
"default": 500000, | ||
"desc": "Resolution bandwidth, in Hz.", | ||
"overload": null, | ||
"functionName": "BLOCK_IQ_RSA500", | ||
"param": "bandwidth", | ||
"value": 500000 | ||
} | ||
}, | ||
"initCtrls": {}, | ||
"inputs": [ | ||
{ | ||
"name": "input", | ||
"id": "input", | ||
"type": "Any", | ||
"multiple": false, | ||
"desc": null | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
"name": "I_real", | ||
"id": "I_real", | ||
"type": "OrderedPair", | ||
"desc": "x: time\ny: power" | ||
}, | ||
{ | ||
"name": "Q_imag", | ||
"id": "Q_imag", | ||
"type": "OrderedPair", | ||
"desc": "x: time\ny: power" | ||
} | ||
], | ||
"path": "HARDWARE/SIGNAL_ANALYZERS/TEKTRONIX/RSA500/BLOCK_IQ_RSA500/BLOCK_IQ_RSA500.py" | ||
}, | ||
"position": { | ||
"x": -56.027539485865546, | ||
"y": -144.34132183199543 | ||
}, | ||
"selected": false, | ||
"positionAbsolute": { | ||
"x": -56.027539485865546, | ||
"y": -144.34132183199543 | ||
}, | ||
"dragging": true | ||
}, | ||
{ | ||
"width": 380, | ||
"height": 293, | ||
"id": "LINE-7f8f05d3-8628-400e-8b6b-5b5c01ac63bd", | ||
"type": "VISUALIZATION", | ||
"data": { | ||
"id": "LINE-7f8f05d3-8628-400e-8b6b-5b5c01ac63bd", | ||
"label": "LINE", | ||
"func": "LINE", | ||
"type": "VISUALIZATION", | ||
"ctrls": {}, | ||
"initCtrls": {}, | ||
"inputs": [ | ||
{ | ||
"name": "default", | ||
"id": "default", | ||
"type": "OrderedPair|DataFrame|Matrix|Vector", | ||
"multiple": false, | ||
"desc": "the DataContainer to be visualized" | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
"name": "default", | ||
"id": "default", | ||
"type": "Plotly", | ||
"desc": "the DataContainer containing the Plotly Line visualization of the input data" | ||
} | ||
], | ||
"path": "DATA/VISUALIZATION/PLOTLY/LINE/LINE.py" | ||
}, | ||
"position": { | ||
"x": 285.36059388919506, | ||
"y": -27.241936012938595 | ||
}, | ||
"selected": false, | ||
"positionAbsolute": { | ||
"x": 285.36059388919506, | ||
"y": -27.241936012938595 | ||
}, | ||
"dragging": true | ||
}, | ||
{ | ||
"width": 380, | ||
"height": 293, | ||
"id": "LINE-b386bedb-cff5-4f45-bd9a-88af92b4a933", | ||
"type": "VISUALIZATION", | ||
"data": { | ||
"id": "LINE-b386bedb-cff5-4f45-bd9a-88af92b4a933", | ||
"label": "LINE 1", | ||
"func": "LINE", | ||
"type": "VISUALIZATION", | ||
"ctrls": {}, | ||
"initCtrls": {}, | ||
"inputs": [ | ||
{ | ||
"name": "default", | ||
"id": "default", | ||
"type": "OrderedPair|DataFrame|Matrix|Vector", | ||
"multiple": false, | ||
"desc": "the DataContainer to be visualized" | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
"name": "default", | ||
"id": "default", | ||
"type": "Plotly", | ||
"desc": "the DataContainer containing the Plotly Line visualization of the input data" | ||
} | ||
], | ||
"path": "DATA/VISUALIZATION/PLOTLY/LINE/LINE.py" | ||
}, | ||
"position": { | ||
"x": 287.25605181479796, | ||
"y": -299.6107860259417 | ||
}, | ||
"selected": false, | ||
"positionAbsolute": { | ||
"x": 287.25605181479796, | ||
"y": -299.6107860259417 | ||
}, | ||
"dragging": true | ||
} | ||
], | ||
"edges": [ | ||
{ | ||
"source": "BLOCK_IQ_RSA500-33713d6b-4202-414e-b8a3-2d9870aa0c7e", | ||
"sourceHandle": "I_real", | ||
"target": "LINE-b386bedb-cff5-4f45-bd9a-88af92b4a933", | ||
"targetHandle": "default", | ||
"id": "reactflow__edge-BLOCK_IQ_RSA500-33713d6b-4202-414e-b8a3-2d9870aa0c7eI_real-LINE-b386bedb-cff5-4f45-bd9a-88af92b4a933default" | ||
}, | ||
{ | ||
"source": "BLOCK_IQ_RSA500-33713d6b-4202-414e-b8a3-2d9870aa0c7e", | ||
"sourceHandle": "Q_imag", | ||
"target": "LINE-7f8f05d3-8628-400e-8b6b-5b5c01ac63bd", | ||
"targetHandle": "default", | ||
"id": "reactflow__edge-BLOCK_IQ_RSA500-33713d6b-4202-414e-b8a3-2d9870aa0c7eQ_imag-LINE-7f8f05d3-8628-400e-8b6b-5b5c01ac63bddefault" | ||
} | ||
], | ||
"viewport": { | ||
"x": 948.751833426666, | ||
"y": 548.8961711096587, | ||
"zoom": 0.8898510191682055 | ||
} | ||
}, | ||
"textNodes": [] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this dll always located here? Also, this only works on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's only available for Windows. The default install location is the second one but I moved mine because I didn't want it on C: directly.