fviard / sllurp

Python client for LLRP-based RFID readers. Private fork.
GNU General Public License v3.0
7 stars 3 forks source link

Start scanning after connect after packit in class #5

Closed edmondhk closed 4 years ago

edmondhk commented 4 years ago

I pack the reader logic in a class so my project is like UI -RFID.py(The class) Call sllurp here

When I create the RFID class, it start to scan already, before I call the join which I comment out while debugging.

Here is my testing code UI:

import RFID
scanning = RFID.Rfid("testing.db")
print(scanning.scan())

RFID.py:

from sllurp.llrp import LLRPReaderConfig, LLRPReaderClient, LLRP_DEFAULT_PORT
class Rfid():
    def __init__(self, dbname):
        //////Some db init and config
        config = LLRPReaderConfig()
        config.update_config({'impinj_reports': True, 'report_every_n_tags': 1,
                              'impinj_tag_content_selector': {'EnableRFPhaseAngle': True, 'EnablePeakRSSI': True,
                                                              'EnableRFDopplerFrequency': False}})

        self.reader = LLRPReaderClient(READER_IP_ADDRESS, LLRP_DEFAULT_PORT, config)
        self.reader.add_tag_report_callback(self.tag_report_cb)
        self.reader.connect()

        print("initialized")

    def tag_report_cb(reader, space, tag_reports):
        print("Call back")
        ////More db and logic
papapel commented 4 years ago

Hello,

I am not sure I fully understood your issue.

Check out the attribute start_inventory of the LLRPReaderConfig in sllurp/llrp.py file. It is set to True by default. It means the scan (I assume you mean the inventory) will start automatically after opening connection with the reader.

Check out the line 105 of this commit: https://github.com/fviard/sllurp/pull/4/commits/5ea181b6925b1e23e9cf286e2f80ad8cb829a82e I wrapped sllurp within a class.

fviard commented 4 years ago

Yes, as explained by @papapel , the "connect()" call both connect to the reader, and initiate the inventory immediately.

Similarly, you use disconnect to stop the inventory and that will disconnect from the reader at the same time.

That is not too great, but at the moment, sllurp is a big state machine, and working like that ensure to only hold a connection to a reader when we are using it.

As an additional example, you can have a look at how the inventory is performed with the "sllurp" cli: https://github.com/fviard/sllurp/blob/develop_untwisted_next/sllurp/verb/inventory.py

And btw, maybe you have misunderstood the meaning of the "join":

edmond1992 commented 4 years ago

Yes, as explained by @papapel , the "connect()" call both connect to the reader, and initiate the inventory immediately.

Similarly, you use disconnect to stop the inventory and that will disconnect from the reader at the same time.

That is not too great, but at the moment, sllurp is a big state machine, and working like that ensure to only hold a connection to a reader when we are using it.

As an additional example, you can have a look at how the inventory is performed with the "sllurp" cli: https://github.com/fviard/sllurp/blob/develop_untwisted_next/sllurp/verb/inventory.py

And btw, maybe you have misunderstood the meaning of the "join":

* When you connect, the inventory starts and will work alone asynchronously

* So, that means that your main loop/code, will continue immediately after this is started.

* If you have nothing else in your code, you will reach the end of your script, and your program will exit alone, as the reader thread is running in the background

* So, the "join" is kind of a "wait indefinitely until the reader is disconnected or connection lost". That is it's only purpose.

Thank you and @papapel . Good to know it is completely normal I guess I will add a little "switch" in my class to switch "on" the callback function or just skip it. As my application is pretty static, which just need to do inventory for 1 sec after receiving the

BTW. @fviard is right, I misunderstand the join function because of this.

try:
    # Block forever or until a disconnection of the reader
    reader.join(None)
except (KeyboardInterrupt, SystemExit):
    # catch ctrl-C and stop inventory before disconnecting
    reader.disconnect()