Crazyradio in PRX mode

Post here to get support
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Crazyradio in PRX mode

Post by whoenig »

Unfortunately, that is not possible the way it used to be. In your example, self.cradio gets destroyed after the with statement ends and you can't use it in later code.
There are two options:
1. Just don't use my code! This is just an example. You can use the original Bitcraze version and just add the one function to switch to PRX mode. I think that is the easiest approach.
2. Use my code and update the user code. Basically, you would need to pass in the Crazyradio to the RadioDriver class. You would have the with-statement just in your main function and pass it down to all objects. If you re-use existing code this can be rather painful.

The only benefit of my version of the code (enforcing with statement) is that it is impossible to leak (which might require replugging the Crazyradio dongle). It is not required to call the close() function explicitly. However, the usage might become more complicated as it is in your example.
e-Rok
Beginner
Posts: 25
Joined: Fri Sep 12, 2014 4:30 pm

Re: Crazyradio in PRX mode

Post by e-Rok »

I agree, given the pre-existing code, this doesn't seem like a great use case for the with statement. That being said, would the example I gave set the self.cradio attribute for the entire scope of the class?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Crazyradio in PRX mode

Post by whoenig »

I guess you would have a variable named self.cradio, but it would be invalid to use outside of the with statement. The with-statement enforces that close() is called no matter how you leave the with-statement (e.g. proper cleanup even if an exception is thrown). I believe in your case you would have self.cradio, but outside of your function it will be already closed and therefore not usable anymore.
Post Reply