Forums › TG Series Discussions › Trying to do sweep using the sa_api.dll and python and not working.
- This topic has 1 reply, 1 voice, and was last updated 8 years, 7 months ago by
akarthikeyan.
- AuthorPosts
akarthikeyanParticipantHi,
I am trying to do a sweep using sa_api.dll and python & ctypes and I am getting an error and python is getting killed when I call ‘saGetSweep’ function. Following is my program and error.
+++++++
Snippet
+++++++
import os
import sys
import ctypes as ctclass SA124B():
def __init__(self):
self.dllpath = os.path.join(os.getcwd(), ‘x64/sa_api.dll’)
self.sa = 0
self.deviceHandle = 0# Initialize
self.sa = ct.CDLL(self.dllpath)
print “Successfuly Initialized”# Open Device
def openDevice(self):
self.deviceHandle = ct.c_int(0)
deviceHandlePnt = ct.pointer(self.deviceHandle)
res = self.sa.saOpenDevice(deviceHandlePnt)
if res == 0:
print ‘Opened Device Successfully’
else:
print “Opening Device Failed”
sys.exit(0)# Get Serial Number
def getSerialNumber(self):
serialNo = ct.c_uint(0)
serialNoPnt = ct.pointer(serialNo)
self.sa.saGetSerialNumber(self.deviceHandle, serialNoPnt)
print ‘Serial Number: %s’ % str(serialNo.value)# Get Firmware Vesion
def getFirmwareVersion(self):
firmwareRev = ct.c_uint(0)
firmwareRevPnt = ct.pointer(firmwareRev)
self.sa.saGetFirmwareString(self.deviceHandle, firmwareRevPnt)
print ‘Firmware Revision: %s’ % str(firmwareRev.value)# Get Device Type
def getDeviceType(self):
devType = ct.c_uint(0)
devTypePnt = ct.pointer(devType)
self.sa.saGetDeviceType(self.deviceHandle, devTypePnt)
print ‘Device Type: %s’ % str(devType.value)# Get API Version
def getAPIVersion(self):
self.sa.saGetAPIVersion.restype = ct.c_char_p # Tell ctypes this function returns a pointer to a string
apiRevStr = self.sa.saGetAPIVersion(self.deviceHandle)
ret = ct.c_char_p(apiRevStr).value # Dereference pointer, extract string
print ‘API Version: %s’ % str(ret)# Configure Center Span
def cfgCeterSpan(self):
center = ct.c_double(915.0e6)
span = ct.c_double(1.0e6)
res = self.sa.saConfigCenterSpan(self.deviceHandle, center, span)
if res == 0:
print ‘Configured Center Span’
else:
print ‘Configuring Center Span Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)# Configure Acquisition
def cfgAcquisition(self):
detector = ct.c_uint(0)
scale = ct.c_uint(0)
res = self.sa.saConfigAcquisition(self.deviceHandle, detector, scale)
if res == 0:
print ‘Configured Acquisition’
else:
print ‘Configuring Acquisition Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)# Configure Level
def cfgLevel(self):
ref = ct.c_double(-10.0)
atten = ct.c_double(-1)
res = self.sa.saConfigLevel(self.deviceHandle, ref, atten)
if res == 0:
print ‘Configured Level’
else:
print ‘Configuring Level Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)# Configure Sweep Coupling
def cfgSweepCoupling(self):
rbw = ct.c_double(1.0e3)
vbw = ct.c_double(1.0e3)
rejection = ct.c_bool(True)
res = self.sa.saConfigSweepCoupling(self.deviceHandle, rbw, vbw, rejection)
if res == 0:
print ‘Configured Sweep Coupling’
else:
print ‘Configuring Sweep Coupling Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)# Initiate
def startSweep(self):
mode = ct.c_int(0)
flag = ct.c_uint(0)
res = self.sa.saInitiate(self.deviceHandle, mode, flag)
if res == 0:
print ‘Started Sweep’
else:
print ‘Start Sweep Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)# Get Sweep and Frame Characteristics
def getSweepInfo(self):
swlen = ct.c_int()
swlenPnt = ct.pointer(swlen)
sfreq = ct.c_double()
sfreqPnt = ct.pointer(sfreq)
binsz = ct.c_double()
binszPnt = ct.pointer(binsz)
res = self.sa.saQuerySweepInfo(self.deviceHandle, swlenPnt, sfreqPnt, binszPnt)
if res == 0:
print ‘Got Sweep Info’
print ‘Sweep Length: %s’ % str(swlen.value)
print ‘Start Frequency: %s’ % str(sfreq.value)
print ‘Bin Size: %s’ % str(binsz.value)min = ct.c_double(swlen.value)
minPnt = ct.pointer(min)
max = ct.c_double(swlen.value)
maxPnt = ct.pointer(max)
# res = self.sa.saGetSweep_64f(self.deviceHandle, minPnt, maxPnt)
start = ct.c_int32(500)
startPnt = ct.pointer(start)
stop = ct.c_int32(1000)
stopPnt = ct.pointer(stop)
res = self.sa.saGetPartialSweep_64f(self.deviceHandle, minPnt, maxPnt, startPnt, stopPnt)
print ‘result: %s’ % str(res)
if res == 0:
print ‘Got Sweep Results’
#print minPnt
#print min.value
#print ‘Minimum Point: %s’ % str(min.value)
#print ‘Maximum Point: %s’ % str(max.value)
else:
print ‘Get Sweep Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)
else:
print ‘Querying Sweep Info Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)def Abort(self):
res = self.sa.saAbort(self.deviceHandle)
if res == 0:
print ‘Aborted’
else:
print ‘Abort Failed: %s’ % str(res)
self.closeDevice()
sys.exit(0)def closeDevice(self):
res = self.sa.saCloseDevice(self.deviceHandle)
if res == 0:
print ‘Closed Device Successfully’
else:
print ‘Closing Device Failed: %s’ % str(res)
sys.exit(0)if __name__ == “__main__”:
sa = SA124B()
sa.openDevice()
#sa.getSerialNumber()
#sa.getFirmwareVersion()
#sa.getDeviceType()
#sa.getAPIVersion()
sa.cfgCeterSpan()
sa.cfgAcquisition()
sa.cfgLevel()
sa.cfgSweepCoupling()
sa.startSweep()
sa.getSweepInfo()
sa.getSweep()
sa.Abort()
sa.closeDevice()+++++++++
+++++++++
ERROR
+++++++++
Please find attached Error1.png and Error2.png.
+++++++++Attachments:
You must be logged in to view attached files.
akarthikeyanParticipantError2.png
Attachments:
You must be logged in to view attached files.- AuthorPosts
You must be logged in to reply to this topic.