Python API

  • 3 Replies
  • 3841 Views
Python API
« on: March 26, 2020, 06:01:04 PM »
HI. Need a quick into into the python api.
How do i run the capture.py...
after installing the deb software package the scope softwatre runs but python has no package sfscopefun api.

*

Dejan

  • *****
  • 150
    • View Profile
Re: Python API
« Reply #1 on: March 28, 2020, 09:48:44 PM »
Hi, the scopefunapi.py was missing in the linux release. We have released a new version which includes the api for linux. Please download the latest version (2.0.16) and let me know if any issues.

The "scopefunapi.py" can be found in "/usr/share/api"

First run the sfServer64r application
Then run sfScope64r and go to settings -> Connection -> select Mode: Client<>Server and click connect.
In the sfScope64r select Open, Upload firmware and start Capture, then run python capture.py in terminal.
Python version must be 2.7.x
« Last Edit: March 28, 2020, 09:55:55 PM by Dejan »

Re: Python API
« Reply #2 on: April 02, 2020, 09:35:39 PM »
Thanks.

Looking at the capture.py i see the code for getting a frame


  while(1):
    print "sfHardwareCaptureFrame - header(1024)"
    ret,transfered = scopefunapi.sfHardwareCapture(ctx,frame,1024,1)
    print "sfHardwareCaptureFrame - data(multiple of 1024)"
    ret,transfered = scopefunapi.sfHardwareCapture(ctx,frame,40960,2)
    if transfered == 40960:


It appears as we first get the header at 1024 bytes. then the frame at 40960bytes...
But only use the data when 40960 bytes were actually transferred.
What happens to the partial frames? Why discard them?

I assume getting a single frame means a complete capture from when the scope was triggered to however many samples it can store. (ignoring the offset due to pre-trigger)
That being said. why is it not always the maximum size? So that it contains the maximum number of samples?

The data also does not appear to be framed in any way. so while i get the header followed by the frame. If for some reason the data is offset I have no way of re-synchronizing to the find the next header/frame.

What am i missing here?

*

Dejan

  • *****
  • 150
    • View Profile
Re: Python API
« Reply #3 on: April 03, 2020, 07:50:27 AM »
Quote
It appears as we first get the header at 1024 bytes. then the frame at 40960bytes...
But only use the data when 40960 bytes were actually transferred.
What happens to the partial frames? Why discard them?

Data is accumulated not discarded. Data will be accumulated until 40960 bytes are transferred.

Quote
I assume getting a single frame means a complete capture from when the scope was triggered to however many samples it can store. (ignoring the offset due to pre-trigger)
That being said. why is it not always the maximum size? So that it contains the maximum number of samples?

A single frame means a complete capture from when the scope was triggered to the selected number of samples. In this case the selected number of samples is 10k. If you want to capture more samples, then you can change the number of samples via GUI or in the Python script by sending the config data to the hardware. The structure of the configuration registers can be found here.

Quote
The data also does not appear to be framed in any way. so while i get the header followed by the frame. If for some reason the data is offset I have no way of re-synchronizing to the find the next header/frame.

The frame is structured  (header+data).  Header is fixed to 1024 bytes which is also the USB packet size. After the header comes the data which must be multiple of USB packet size. That being said, you can't read less than one USB packet which is 1024 Bytes. For example, if you have a frame with 10000 samples then you need to capture 10000 x 4 Bytes (+ padding to reach the USB packet size) = 40000 Bytes + padding 960 Bytes = 40960 bytes. Padding is dummy data sent by the FPGA to fill the USB packet.

Then next frame will be structured the same as previous (header + data). This is fixed, so you must always read the complete frame to stay synchronized  to the beginning of the frame. The number of samples that were captured in a frame can also be read from the header.
« Last Edit: April 03, 2020, 08:03:19 AM by Dejan »