Greetings,
I followed this guide here:
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000oyaHCAQ&l=en-US
And I was attempting to send a few parameters to python from Labview, run a query using pyodbc, and then return the results into an array.
Here is my Labview program:
![2025-02-11 13_11_07-DB - CAEN DGTZ Profile - Read for Viewer.vi Front Panel _.png 2025-02-11 13_11_07-DB - CAEN DGTZ Profile - Read for Viewer.vi Front Panel _.png]()
As the guide shows I created a cluster of my datatytpes and put them into a 1D array.
I tried to remove the strings and just do simple integer returns, but that yields the same error. I'm not sure why Labview seems to be erroring for no reason on this data return. Any advice or critique would be greatly appreciated.
Here is what I am returning from Python, it is a list of tuples similar to the guide above:
[('default', 4128, 'Record Length Ch 1', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 4136, 'Input Dynamic Range Ch 1', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 4384, 'Record Length Ch 2', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 4392, 'Input Dynamic Range Ch 2', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 4640, 'Record Length Ch 3', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 4648, 'Input Dynamic Range Ch 3', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 4896, 'Record Length Ch 4', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 4904, 'Input Dynamic Range Ch 4', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 5152, 'Record Length Ch 5', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 5160, 'Input Dynamic Range Ch 5', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 5408, 'Record Length Ch 6', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 5416, 'Input Dynamic Range Ch 6', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 5664, 'Record Length Ch 7', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 5672, 'Input Dynamic Range Ch 7', 0, 'Vpp', 'RW', 'init', 'Initial entry'), ('default', 5920, 'Record Length Ch 8', 128, 'samples', 'RW', 'init', 'Initial entry'), ('default', 5928, 'Input Dynamic Range Ch 8', 0, 'Vpp', 'RW', 'init', 'Initial entry')]
Here is a snippet of my Python:
#This is the main script of the GPAS database connectivity
#import modules
importpyodbc
fromdatetimeimportdatetime
#set the connection info
conn_str="DSN=GPAS"
#connect to database and create cursor
cnxn=pyodbc.connect(conn_str)
crsr=cnxn.cursor()
####################################################################################################################
####################################################################################################################
defCAEN_DT5730_read_profile(Profile_Name, Mode, Group_Name😞
#build the query
query="""
WITH RankedEntries AS (
SELECT
*,
ROW_NUMBER() OVER (
PARTITION BY Register_Address
ORDER BY Timestamp DESC
) AS RowNum
FROM
GP_CAEN_DT5730_Profile
WHERE
Profile_Name LIKE ?
AND Mode LIKE ?
AND Group_Name LIKE ?
)
SELECT
Profile_Name,
Register_Address,
Register_Name,
Register_Value,
Units,
Mode,
Group_Name,
Change_Log
FROM
RankedEntries
WHERE
RowNum = 1
"""
#execute the query
try:
crsr.execute(query, Profile_Name, Mode, Group_Name)
exceptExceptionase:
print(f"Error executing query: {e}")
return []
# Fetch all
returncrsr.fetchall()