A Python wrapper for libhackrf
Find a file
陈豪 | Jacob Chen 79e6cdf4c8
Merge pull request #1 from Grissess/master
Allow library path to be specified in env
2020-03-18 10:19:53 +08:00
.gitignore Initial commit 2014-12-25 11:39:52 +08:00
examples.py rx data should be char rather than unsigned char 2015-01-05 20:36:58 +08:00
pylibhackrf.py Allow library path to be specified in env 2019-07-29 21:03:58 -04:00
README.md Update README.md 2015-02-10 14:55:37 +08:00

pyhackrf-ctypes

pyhackrf-ctypes is a Python wrapper for libhackrf.
I create this project because I want a simple Python interface to my hackrf board and pyusb is too slow for hackrf.

Dependencies

  • libusb,NumPy

  • Python 2.7.x/3.3+

  • libhackrf

      sudo apt-get install python-dev,libusb-1.0-0 
    

Examples

import pylibhackrf ,ctypes

hackrf = pylibhackrf.HackRf()

if hackrf.is_open == False:
    hackrf.setup()
    hackrf.set_freq(100 * 1000 * 1000)
    hackrf.set_sample_rate(8 * 1000 * 1000)
    hackrf.set_amp_enable(False)
    hackrf.set_lna_gain(16)
    hackrf.set_vga_gain(20)    
    hackrf.set_baseband_filter_bandwidth(1 * 1000 * 1000)  

def callback_fun(hackrf_transfer):
    array_type = (ctypes.c_byte*length)
    values = ctypes.cast(hackrf_transfer.contents.buffer, ctypes.POINTER(array_type)).contents
    #iq data here
    iq = hackrf.packed_bytes_to_iq(values)    
    return 0

hackrf.start_rx_mode(callback_fun)

Todo

There are a few remaining functions in libhackrf haven't been wrapped.

License

Do What The Fuck You Want To Public License.