문제

I'm trying to query my USB dongle (NooElec R820T SDR) to determine what frequency it's tuned to. I want to make the unit test configure call to see if the device is properly adjusted and working. I could simply use:

self.comp.frequency = 1000000 
print self.comp.frequency

to set the value and print it out. However, I want to ask the hardware instead of the component. The RH manual has something like this:

# In this example, freqMHz is a defined property.
def onconfigure_prop_freqMHz(self, oldval, newval):
print "On Configure to value " + str(newval) 
self.freqMHz = newval
self.port_labInterface_out.setFrequencyMHz(self.freqMHz)

I think this bit still only calls on the component value and not the hardware itself. Is it possible to use RH to query the device directly?

Thanks in advance.

도움이 되었습니까?

해결책

Without seeing the code for the component, I can only make assumptions, but it seems that when you set the center frequency of the component, it will eventually set the frequency of the hardware, probably when the call to self.port_labInterface_out.setFrequencyMHz() occurs. When this occurs, it probably then asks the device what frequency it was actually set to, and sets the frequency of the component to reflect this before returning from the setFrequencyMHz call.

However, like I said, those are assumptions. Using the librtlsdr library and the ctypes module, you may be able to call the functions that the component itself is most likely calling, namely rtlsdr_open to get a reference to the device, rtlsdr_set_center_freq to set the center frequency, and rtlsdr_get_center_freq to get the center frequency of the device. The biggest problems with this approach are:

  1. That you will have to create a python ctypes version of the rtlsdr_dev struct used by these calls in order to pass a reference around
  2. Since the component already has a reference to the device, the rtlsdr_open in your unit test will fail

You could get around the first problem, which is more an inconvenience than a problem, by using cunit or cppunit for your unit tests, allowing you to reuse the struct defined in the rtlsdr library.

The second problem is a limitation of the rtlsdr library and/or libusb. This almost certainly means you won't be able to accomplish your original goal of querying the device directly

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top