python api without server

  • 0 Replies
  • 20 Views
python api without server
« on: July 20, 2021, 10:22:06 PM »
I was wondering if anyone has an example of connecting directly to the scopefun via usb without using the server?  Either using the python api or directly with c code?  I would like to use this with a headless linux installation running on a raspberry pi, to just write the waveforms to disk.

Below is an example using python that doesn't work, but gives an idea of what I am trying to do.  It segmentation faults when it calls scopefunapi.sfHardwareOpen.

================================================

import scopefunapi
import time

szCapture = 16*1024*1024
szFrame   = 16*1024*1024

# setup
print "sfApiInit"
ret = scopefunapi.sfApiInit()
print "sfCreateSFContext",ret
ctx = scopefunapi.sfCreateSFContext()
print "sfApiCreateContext"
ret = scopefunapi.sfApiCreateContext(ctx,szCapture)
print "sfSetActive"
ret = scopefunapi.sfSetActive(ctx,1)
print "sfSetThreadSafe"
ret = scopefunapi.sfSetThreadSafe(ctx,1)
print "sfSetNetwork"
ret = scopefunapi.sfSetNetwork(ctx)
print "sfSetframe*"
ret = scopefunapi.sfSetFrameVersion(ctx,2)
ret = scopefunapi.sfSetFrameHeader(ctx,1024)
ret = scopefunapi.sfSetFrameData(ctx,1024)
ret = scopefunapi.sfSetFramePacket(ctx,(1024*1024))

raw_input("Press Enter to connect ...")

print "sfSetUsb"
#ret = scopefunapi.sfClientConnect(ctx,'127.0.0.1',42250)
ret = scopefunapi.sfSetUsb(ctx)
ret = scopefunapi.sfIsUsb(ctx)     
print "sfIsUsb", ret

usb1=scopefunapi.sfCreateSUsb()
usb1.idVendor=0x1d50
usb1.idProduct=0x6104
#usb1.idSerial=3
#usb1.xferSize=1024
#   uint         idVendor;
#   uint         idProduct;
#   uint         idSerial;
#   uint         timeoutEp2;
#   uint         timeoutEp4;
#   uint         timeoutEp6;
#   uint         xferSize;
#   SUsbGuid     guid;


print "sfHardwareOpen"
ret = scopefunapi.sfHardwareOpen(ctx, usb1, 2)
print "sfHardwareOpen done"
ret,temp = scopefunapi.sfHardwareIsOpened(ctx)     
print "sfHardwareIsOpened", ret, temp
   
# data structures
print "sfCreateSFrameData"
frame          = scopefunapi.sfCreateSFrameData(ctx,szFrame)


def sethw(xrange,VdivCh1,VdivCh2):
   #setup horizontal scale
   if   VdivCh1 == 1 :
      gvCh1=1430
      k1=0
   elif VdivCh1 == 2 :
      gvCh1=1788
      k1=0
   elif VdivCh1 == 3 :
      gvCh1=2138
      k1=0
   elif VdivCh1 == 4 :
      gvCh1=2604
      k1=0
   elif VdivCh1 == 5 :
      gvCh1=1426
      k1=1
   elif VdivCh1 == 6 :
      gvCh1=1784
      k1=1
   elif VdivCh1 == 7 :
      gvCh1=2252
      k1=1
   else:
      gvCh1=2634
      k1=1
   if   VdivCh2 == 1 :
      gvCh2=1424
      k2=0
   elif VdivCh2 == 2 :
      gvCh2=1772
      k2=0
   elif VdivCh2 == 3 :
      gvCh2=2128
      k2=0
   elif VdivCh2 == 4 :
      gvCh2=2590
      k2=0
   elif VdivCh2 == 5 :
      gvCh2=1420
      k2=1
   elif VdivCh2 == 6 :
      gvCh2=1770
      k2=1
   elif VdivCh2 == 7 :
      gvCh2=2242
      k2=1
   else:
      gvCh2=2618
      k2=1

   analogsw = 0b00110000 #DC coupling on both channels
   k1 = k1 << 1
   att = k1 | k2         #set ch1 and ch2 attenuation bits
   analogsw = analogsw | att
   
   #create SHardware2 object which contains configration data
   hardware2config = scopefunapi.sfCreateSHardware2()
   hardware2config.controlAddr           = 13
   hardware2config.controlData           = 0
   hardware2config.vgaina                = gvCh1
   hardware2config.vgainb                = gvCh2
   hardware2config.offseta               = 0
   hardware2config.offsetb               = 0
   hardware2config.analogswitch          = analogsw
   hardware2config.triggerMode           = 0  # 0=auto 1=normal
   hardware2config.triggerSource         = 0  # 0=A 1=B
   hardware2config.triggerSlope          = 0  # 0=rising 1=falling
   hardware2config.triggerLevel          = 0  # 0=0V
   hardware2config.triggerHis            = 3  # hystersis
   hardware2config.triggerPercent        = 0
   hardware2config.xRange                = xrange # sampling speed (0=4n, 1=8n, 2=20n, ...)
   hardware2config.holdoffH              = 0
   hardware2config.holdoffL              = 0
   hardware2config.sampleSizeH           = 0
   hardware2config.sampleSizeL           = 256

   ret = scopefunapi.sfHardwareConfig2(ctx,hardware2config) ###
   return 0

#setup hardware for first frame
sethw(1,6,6)    # 8 ns  50 mV
time.sleep(1)


# capture
print "sfEventCapture"
ret,transfered = scopefunapi.sfHardwareCapture(5,ctx,frame,1024)
               
# cleanup
raw_input("Press Enter to disconnect ...")

print "sfHardwareClose"
scopefunapi.sfHardwareClose(ctx)

print "sfApiExit"
scopefunapi.sfApiExit()