From 23ab1a435006bffaa43c981a73984768d6080f1d Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:41:39 +0200 Subject: [PATCH 01/28] Add packaging of project --- Example/write_and_read.py | 2 +- README.md | 4 +++- pyproject.toml | 43 ++++++++++++++++++++++++++++++++++ requirements.txt | 1 - src/py_acr122u/__init__.py | 1 + src/{ => py_acr122u}/error.py | 0 src/{ => py_acr122u}/main.py | 2 +- src/{ => py_acr122u}/nfc.py | 2 +- src/{ => py_acr122u}/option.py | 0 src/{ => py_acr122u}/utils.py | 0 10 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt create mode 100644 src/py_acr122u/__init__.py rename src/{ => py_acr122u}/error.py (100%) rename src/{ => py_acr122u}/main.py (70%) rename src/{ => py_acr122u}/nfc.py (99%) rename src/{ => py_acr122u}/option.py (100%) rename src/{ => py_acr122u}/utils.py (100%) diff --git a/Example/write_and_read.py b/Example/write_and_read.py index 4c89944..e0fbf2b 100644 --- a/Example/write_and_read.py +++ b/Example/write_and_read.py @@ -1,4 +1,4 @@ -from src import nfc +from src.py_acr122u import nfc reader = nfc.Reader() diff --git a/README.md b/README.md index 72c6d0d..25d100b 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,10 @@ This is a python library for the ACR122U NFC reader - pip install -r requirements.txt ## Usage + ```python -from src import nfc + +from py_acr122u import nfc reader = nfc.Reader() reader.print_data(reader.get_uid()) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..bfce962 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[build-system] +requires = ["setuptools>=61.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "py-acr122u" +version = "1.0.0" +description = "This is a python library for the ACR122U NFC reader" +readme = "README.md" +authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] +license = { file = "LICENSE" } +classifiers = [ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", +] +keywords = ["nfc", "acs", "acr122u"] +dependencies = [ + "pyscard>=2.0.7", +] +requires-python = ">=3.11" + +[project.optional-dependencies] +dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] + +[project.urls] +Homepage = "https://github.com/robertdijk/py-acr122u" + +[tool.bumpver] +current_version = "1.0.0" +version_pattern = "MAJOR.MINOR.PATCH" +commit_message = "Bump version {old_version} -> {new_version}" +commit = true +tag = true +push = false + +[tool.bumpver.file_patterns] +"pyproject.toml" = [ + 'current_version = "{version}"', + 'version = "{version}"', +] +"src/py_acr122u/__init__.py" = ["{version}"] + diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index b67b53d..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pyscard \ No newline at end of file diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py new file mode 100644 index 0000000..5a6bc65 --- /dev/null +++ b/src/py_acr122u/__init__.py @@ -0,0 +1 @@ +__version__ = "2.0.0" \ No newline at end of file diff --git a/src/error.py b/src/py_acr122u/error.py similarity index 100% rename from src/error.py rename to src/py_acr122u/error.py diff --git a/src/main.py b/src/py_acr122u/main.py similarity index 70% rename from src/main.py rename to src/py_acr122u/main.py index cacfa90..89be969 100644 --- a/src/main.py +++ b/src/py_acr122u/main.py @@ -1,4 +1,4 @@ -from src import nfc +from src.py_acr122u import nfc reader = nfc.Reader() reader.print_data(reader.get_uid()) diff --git a/src/nfc.py b/src/py_acr122u/nfc.py similarity index 99% rename from src/nfc.py rename to src/py_acr122u/nfc.py index 5119ce0..10aa1f9 100644 --- a/src/nfc.py +++ b/src/py_acr122u/nfc.py @@ -2,7 +2,7 @@ from smartcard.util import toHexString from smartcard.ATR import ATR -from src import utils, option, error +from src.py_acr122u import utils, error, option class Reader: diff --git a/src/option.py b/src/py_acr122u/option.py similarity index 100% rename from src/option.py rename to src/py_acr122u/option.py diff --git a/src/utils.py b/src/py_acr122u/utils.py similarity index 100% rename from src/utils.py rename to src/py_acr122u/utils.py From 393f5add0d1aef803ffe8dc39afb3cb0a7862b18 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:42:05 +0200 Subject: [PATCH 02/28] Bump version 1.0.0 -> 1.1.0 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bfce962..80bd069 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "1.0.0" +version = "1.1.0" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "1.0.0" +current_version = "1.1.0" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 5a6bc65..ff1068c 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "2.0.0" \ No newline at end of file +__version__ = "1.1.0" \ No newline at end of file From cfe93fe62f75805b2d03409388560713993864ba Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:49:35 +0200 Subject: [PATCH 03/28] Add automatic release of package --- .github/workflows/publish-to-pypi.yml | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/publish-to-pypi.yml diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..26bb757 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,41 @@ +name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI + +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + build-n-publish: + name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Install pypa/build + run: >- + python -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: >- + python -m + build + --sdist + --wheel + --outdir dist/ + . +# - name: Publish distribution 📦 to Test PyPI +# uses: pypa/gh-action-pypi-publish@release/v1 +# with: +# password: ${{ secrets.TEST_PYPI_API_TOKEN }} +# repository-url: https://test.pypi.org/legacy/ + - name: Publish distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file From 403be527a3b7a787c740749445dc3d6b6709a5ef Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:49:39 +0200 Subject: [PATCH 04/28] Bump version 1.1.0 -> 1.1.1 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 80bd069..9736870 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "1.1.0" +version = "1.1.1" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "1.1.0" +current_version = "1.1.1" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index ff1068c..545d07d 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "1.1.0" \ No newline at end of file +__version__ = "1.1.1" \ No newline at end of file From 1ae4b056a18bfa9a6b69f89cb222cbf1488502be Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:53:20 +0200 Subject: [PATCH 05/28] Add releasing to real pypi --- .github/workflows/publish-to-pypi.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 26bb757..3020311 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -29,11 +29,11 @@ jobs: --wheel --outdir dist/ . -# - name: Publish distribution 📦 to Test PyPI -# uses: pypa/gh-action-pypi-publish@release/v1 -# with: -# password: ${{ secrets.TEST_PYPI_API_TOKEN }} -# repository-url: https://test.pypi.org/legacy/ + - name: Publish distribution 📦 to Test PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ - name: Publish distribution 📦 to PyPI if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 From 87e52852dd067e955c6cac2aa05fce5d182d5e07 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:53:26 +0200 Subject: [PATCH 06/28] Bump version 1.1.1 -> 1.1.2 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9736870..6d95de8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "1.1.1" +version = "1.1.2" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "1.1.1" +current_version = "1.1.2" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 545d07d..5da0b9a 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "1.1.1" \ No newline at end of file +__version__ = "1.1.2" \ No newline at end of file From 14f199d180753505f439583faafde5011f3f8aaf Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:58:38 +0200 Subject: [PATCH 07/28] Move connect to separate method --- src/py_acr122u/nfc.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index 10aa1f9..24194f1 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -21,15 +21,18 @@ def instantiate_reader(): reader = readers[0] c = reader.createConnection() + return reader, c + + def connect(self): + """connect to the card + only works if a card is on the reader""" try: - c.connect() + self.connection.connect() except: raise error.NoCommunication( "The reader has been deleted and no communication is now possible. Smartcard error code : 0x7FEFFF97" "\nHint: try to connect a card to the reader") - return reader, c - def command(self, mode, arguments=None): """send a payload to the reader From d15eb0cffb608ebd4534cc7f396b5575d1f5b2e1 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 11:58:44 +0200 Subject: [PATCH 08/28] Fix code style --- src/py_acr122u/nfc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index 24194f1..f029d45 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -55,7 +55,8 @@ def command(self, mode, arguments=None): payload = option.options.get(mode) if not payload: - raise error.OptionOutOfRange("Option do not exist\nHint: try to call help(nfc.Reader().command) to see all options") + raise error.OptionOutOfRange( + "Option do not exist\nHint: try to call help(nfc.Reader().command) to see all options") payload = utils.replace_arguments(payload, arguments) result = self.connection.transmit(payload) @@ -211,5 +212,5 @@ def print_data(data): @staticmethod def print_sw1_sw2(sw1, sw2): - print(f"sw1 : {sw1} {hex(sw1)}\n" - f"sw2 : {sw2} {hex(sw2)}") + print(f"sw1 : {sw1} {hex(sw1)}\n" + f"sw2 : {sw2} {hex(sw2)}") From 6ef3b4735b5af2ec49d26acf46c9a0eca4c56246 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:11:30 +0200 Subject: [PATCH 09/28] Update Example --- Example/write_and_read.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Example/write_and_read.py b/Example/write_and_read.py index e0fbf2b..4e76842 100644 --- a/Example/write_and_read.py +++ b/Example/write_and_read.py @@ -1,6 +1,7 @@ -from src.py_acr122u import nfc +from py_acr122u import nfc reader = nfc.Reader() +reader.connect() reader.load_authentication_data(0x01, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]) reader.authentication(0x00, 0x61, 0x01) @@ -29,5 +30,6 @@ def read(r, position, number): def read_16(r, position, number): return r.read_binary_blocks(position, number) + write(reader, 0x01, 0x20, [0x00 for i in range(16)]) print(read(reader, 0x01, 0x20)) From 62f752532bda8249be0d48274da09d64ff26eaee Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:11:45 +0200 Subject: [PATCH 10/28] Add badges to README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25d100b..d7859d5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # PY-ACR122U - + +![PyPI - License](https://img.shields.io/pypi/v/py-acr122u) +![PyPI - License](https://img.shields.io/pypi/l/py-acr122u) +![PyPI - License](https://img.shields.io/pypi/dm/py-acr122u) +![PyPI - License](https://img.shields.io/pypi/pyversions/py-acr122u) +![PyPI - License](https://img.shields.io/pypi/wheel/py-acr122u) + + This is a python library for the ACR122U NFC reader From cacc4127e6d40d4c777c8abb1cb7ebe5b9985664 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:13:35 +0200 Subject: [PATCH 11/28] Update README.md --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d7859d5..2d1e508 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@ # PY-ACR122U - ![PyPI - License](https://img.shields.io/pypi/v/py-acr122u) ![PyPI - License](https://img.shields.io/pypi/l/py-acr122u) ![PyPI - License](https://img.shields.io/pypi/dm/py-acr122u) ![PyPI - License](https://img.shields.io/pypi/pyversions/py-acr122u) ![PyPI - License](https://img.shields.io/pypi/wheel/py-acr122u) - - This is a python library for the ACR122U NFC reader ## Installation -- git clone https://github.com/Flowtter/py-acr122u.git -- cd py-acr122u -- pip install -r requirements.txt + +```shell +pip install py-acr122u +``` ## Usage @@ -23,7 +21,7 @@ This is a python library for the ACR122U NFC reader from py_acr122u import nfc reader = nfc.Reader() +reader.connect() reader.print_data(reader.get_uid()) reader.info() ``` -- python main.py From 695a37ecd18017b4f2326d754c4772450c79ca8d Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:13:53 +0200 Subject: [PATCH 12/28] Bump version 1.1.2 -> 2.0.0 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6d95de8..ae225fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "1.1.2" +version = "2.0.0" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "1.1.2" +current_version = "2.0.0" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 5da0b9a..5a6bc65 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "1.1.2" \ No newline at end of file +__version__ = "2.0.0" \ No newline at end of file From 4a6ee6a49ef734021bf857e14bdeda2198650552 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:18:27 +0200 Subject: [PATCH 13/28] Add links to README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2d1e508..85c2700 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # PY-ACR122U -![PyPI - License](https://img.shields.io/pypi/v/py-acr122u) -![PyPI - License](https://img.shields.io/pypi/l/py-acr122u) -![PyPI - License](https://img.shields.io/pypi/dm/py-acr122u) -![PyPI - License](https://img.shields.io/pypi/pyversions/py-acr122u) -![PyPI - License](https://img.shields.io/pypi/wheel/py-acr122u) +[![PyPI - Version](https://img.shields.io/pypi/v/py-acr122u)](https://pypi.org/project/py-acr122u/) +[![PyPI - License](https://img.shields.io/pypi/l/py-acr122u)](https://pypi.org/project/py-acr122u/) +[![PyPI - Downloads](https://img.shields.io/pypi/dm/py-acr122u)](https://pypi.org/project/py-acr122u/) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/py-acr122u)](https://pypi.org/project/py-acr122u/) +[![PyPI - Wheel](https://img.shields.io/pypi/wheel/py-acr122u)](https://pypi.org/project/py-acr122u/) This is a python library for the ACR122U NFC reader From 0db2dbbb29108dcc4e7a3b679fbb99db88642880 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:18:33 +0200 Subject: [PATCH 14/28] Bump version 2.0.0 -> 2.0.1 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ae225fa..77398b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "2.0.0" +version = "2.0.1" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "2.0.0" +current_version = "2.0.1" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 5a6bc65..5719d15 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "2.0.0" \ No newline at end of file +__version__ = "2.0.1" \ No newline at end of file From c39d5c4a46091e4bde7de8cc2229b8c27305c0a7 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 12:22:29 +0200 Subject: [PATCH 15/28] Fix led_control option --- src/py_acr122u/option.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/py_acr122u/option.py b/src/py_acr122u/option.py index 4441525..9f4f1e5 100644 --- a/src/py_acr122u/option.py +++ b/src/py_acr122u/option.py @@ -5,7 +5,7 @@ "authentication": [0xFF, 0x88, 0x00, -1, -1, -1], "read_binary_blocks": [0xFF, 0xB0, 0x00, -1, -1], "update_binary_blocks": [0xFF, 0xD6, 0x00, -1, -1, -1], - "led-control": [0xFF, 0x00, 0x40, -1, -0x04, -1, -1, -1, -1], + "led_control": [0xFF, 0x00, 0x40, -1, -0x04, -1, -1, -1, -1], "get_picc_version": [0xFF, 0x00, 0x50, 0x00, 0x00], "set_picc_version": [0xFF, 0x00, 0x51, -1, 0x00], "buzzer_sound": [0xFF, 0x00, 0x52, -1, 0x00], @@ -18,7 +18,7 @@ "auth": "authentication", "rbb": "read_binary_blocks", "ubb": "update_binary_blocks", - "ld": "led-control", + "ld": "led_control", "gpv": "get_picc_version", "spv": "set_picc_version", "b": "buzzer_sound_mute", From 3be3b0677e22609dcf44b9e45c9a661950bd9dde Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:03:09 +0200 Subject: [PATCH 16/28] Fix protocol error --- src/py_acr122u/nfc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index f029d45..7b05278 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -1,4 +1,5 @@ import smartcard.System +from smartcard.CardConnection import CardConnection from smartcard.util import toHexString from smartcard.ATR import ATR @@ -59,7 +60,7 @@ def command(self, mode, arguments=None): "Option do not exist\nHint: try to call help(nfc.Reader().command) to see all options") payload = utils.replace_arguments(payload, arguments) - result = self.connection.transmit(payload) + result = self.connection.transmit(payload, protocol=CardConnection.T1_protocol) if len(result) == 3: data, sw1, sw2 = result From 455eb192363ee806f2590a6e96b5768f31e526f6 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:05:00 +0200 Subject: [PATCH 17/28] Add PICC and direct transmit commands --- src/py_acr122u/error.py | 11 ++++++++++ src/py_acr122u/nfc.py | 44 +++++++++++++++++++++++++++++++++++++++- src/py_acr122u/option.py | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/py_acr122u/error.py b/src/py_acr122u/error.py index c2d4694..59e6f01 100644 --- a/src/py_acr122u/error.py +++ b/src/py_acr122u/error.py @@ -45,3 +45,14 @@ class InstructionFailed(Error): def __init__(self, message): self.message = message + + +class BitOutOfRange(Error): + """Exception raised when you try to set a bit that does not exsist + + Attributes: + message -- explanation of the error + """ + + def __init__(self, message): + self.message = message diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index 7b05278..922c5eb 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -1,9 +1,11 @@ +from typing import List + import smartcard.System from smartcard.CardConnection import CardConnection from smartcard.util import toHexString from smartcard.ATR import ATR -from src.py_acr122u import utils, error, option +from . import utils, error, option class Reader: @@ -195,6 +197,46 @@ def set_timeout(self, timeout_parameter): 0x01""" self.command("set_timeout", [timeout_parameter]) + def direct_transmit(self, payload: List[int]): + """send the payload to the tag or reader. + using this you can send messages directly to the PN532 chip + doc available here: https://www.nxp.com/docs/en/user-guide/141520.pdf + + Attributes: + payload: the payload to send to the PN532 chip + + Example: + [0xd4, 0x60, 0xFF, 0x02, 0x10] + """ + return self.command("direct_transmit", [len(payload), payload]) + + def set_auto_polling(self, enabled: bool): + """enable or disable Auto PICC Polling + + Attributes: + enabled: True to enable, False to disable + + """ + self.set_picc_bit(7, enabled) + + def set_picc_bit(self, bit: int, value: bool): + """set a PICC bit to update the PICC operating parameter as described in section 6.5 + of API-ACR122U-2.02.pdf + + Attributes: + bit: the bit to set + value: True for 1, False for 0 + """ + if bit < 0 or bit > 7: + raise error.BitOutOfRange(f"Bit {bit} is not in the picc operating parameter") + + picc = self.get_picc_version()[1] + if value: + picc |= 1 << bit + else: + picc &= ~ (1 << bit) + self.set_picc_version(picc) + def info(self): """print the type of the card on the reader""" atr = ATR(self.connection.getATR()) diff --git a/src/py_acr122u/option.py b/src/py_acr122u/option.py index 9f4f1e5..1247fb2 100644 --- a/src/py_acr122u/option.py +++ b/src/py_acr122u/option.py @@ -10,6 +10,7 @@ "set_picc_version": [0xFF, 0x00, 0x51, -1, 0x00], "buzzer_sound": [0xFF, 0x00, 0x52, -1, 0x00], "set_timeout": [0xFF, 0x00, 0x41, -1, 0x00], + "direct_transmit": [0xFF, 0x00, 0x00, 0x00, -1, -1] } alias = { "gu": "get_uid", From 6f3efda1c4412a49a831b7d1e95ef11d5a366e00 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:05:08 +0200 Subject: [PATCH 18/28] Add PICC bit tests --- pyproject.toml | 10 +++++++- tests/set_picc_bit_test.py | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/set_picc_bit_test.py diff --git a/pyproject.toml b/pyproject.toml index 77398b1..640b909 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ dependencies = [ requires-python = ">=3.11" [project.optional-dependencies] -dev = ["black", "bumpver", "isort", "pip-tools", "pytest"] +dev = ["black", "bumpver", "isort", "pip-tools", "pytest", "pytest-mock"] [project.urls] Homepage = "https://github.com/robertdijk/py-acr122u" @@ -41,3 +41,11 @@ push = false ] "src/py_acr122u/__init__.py" = ["{version}"] +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-ra -q" +testpaths = [ + "tests", + "integration", +] + diff --git a/tests/set_picc_bit_test.py b/tests/set_picc_bit_test.py new file mode 100644 index 0000000..714eaba --- /dev/null +++ b/tests/set_picc_bit_test.py @@ -0,0 +1,49 @@ +import pytest + +from py_acr122u import error +from py_acr122u.nfc import Reader + + +@pytest.mark.parametrize("bit", [0, 1, 2, 3, 4, 5, 6, 7]) +def test_picc_bit_range_pass(bit, mocker): + mocker.patch("py_acr122u.nfc.Reader.instantiate_reader", return_value=(None, None)) + mocker.patch("py_acr122u.nfc.Reader.get_picc_version", return_value=(144, 255)) + mocker.patch("py_acr122u.nfc.Reader.set_picc_version") + r = Reader() + + r.set_picc_bit(bit, False) + r.set_picc_bit(bit, True) + + +@pytest.mark.parametrize("bit", [-2, -1, 8, 9, 10]) +def test_picc_bit_range_fail(bit, mocker): + mocker.patch("py_acr122u.nfc.Reader.instantiate_reader", return_value=(None, None)) + mocker.patch("py_acr122u.nfc.Reader.get_picc_version", return_value=(144, 255)) + mocker.patch("py_acr122u.nfc.Reader.set_picc_version") + r = Reader() + + with pytest.raises(error.BitOutOfRange): + r.set_picc_bit(bit, False) + with pytest.raises(error.BitOutOfRange): + r.set_picc_bit(bit, True) + + +@pytest.mark.parametrize("old_picc, bit, value, new_picc", [ + (0b00000000, 0, True, 0b00000001), + (0b00000000, 0, False, 0b00000000), + (0b00000000, 1, True, 0b00000010), + (0b00000000, 1, False, 0b00000000), + (0b11111111, 0, True, 0b11111111), + (0b11111111, 0, False, 0b11111110), + (0b11111111, 1, True, 0b11111111), + (0b11111111, 1, False, 0b11111101), +]) +def test_picc_bit_set_bit(old_picc, bit, value, new_picc, mocker): + mocker.patch("py_acr122u.nfc.Reader.instantiate_reader", return_value=(None, None)) + mocker.patch("py_acr122u.nfc.Reader.get_picc_version", return_value=(144, old_picc)) + mock_set_picc = mocker.patch("py_acr122u.nfc.Reader.set_picc_version") + r = Reader() + + r.set_picc_bit(bit, value) + + mock_set_picc.assert_called_with(new_picc) From c66759b2f532dbb0e8153ddc0a0b4d8678409a77 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:05:31 +0200 Subject: [PATCH 19/28] Add convenient methods to control buzzer and leds --- src/py_acr122u/nfc.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index 922c5eb..37cfcdc 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -237,6 +237,18 @@ def set_picc_bit(self, bit: int, value: bool): picc &= ~ (1 << bit) self.set_picc_version(picc) + def mute_buzzer(self): + """mute the buzzer for when a card is scanned""" + self.buzzer_sound(0x00) + + def unmute_buzzer(self): + """unmute the buzzer for when a card is scanned""" + self.buzzer_sound(0xFF) + + def reset_lights(self): + """turn the red and green LED off""" + self.led_control(0b00110000, 0x00, 0x00, 0x00, 0x00) + def info(self): """print the type of the card on the reader""" atr = ATR(self.connection.getATR()) From e9807ad09e3edff37979e3d53a212170dcba728b Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:05:48 +0200 Subject: [PATCH 20/28] Bump version 2.0.1 -> 2.1.0 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 640b909..8aefe80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "2.0.1" +version = "2.1.0" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest", "pytest-mock"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "2.0.1" +current_version = "2.1.0" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 5719d15..dac7778 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "2.0.1" \ No newline at end of file +__version__ = "2.1.0" \ No newline at end of file From d6b12137dfed247b8277d02049f9b5b4362fde7c Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:55:37 +0200 Subject: [PATCH 21/28] Add PN532 representation and in auto poll method --- src/py_acr122u/nfc.py | 69 ++++++++++++++++++++++++++++++++++++++ src/py_acr122u/option.py | 3 ++ tests/in_auto_poll_test.py | 45 +++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/in_auto_poll_test.py diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index 37cfcdc..d7d3847 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -13,6 +13,7 @@ def __init__(self): """create an ACR122U object doc available here: http://downloads.acs.com.hk/drivers/en/API-ACR122U-2.02.pdf""" self.reader_name, self.connection = self.instantiate_reader() + self.pn532 = self._PN532(self) @staticmethod def instantiate_reader(): @@ -269,3 +270,71 @@ def print_data(data): def print_sw1_sw2(sw1, sw2): print(f"sw1 : {sw1} {hex(sw1)}\n" f"sw2 : {sw2} {hex(sw2)}") + + class _PN532: + """the PN532 chip inside the ACR122U + Methods in the class can be used to communicate with the chip + see docs at: https://www.nxp.com/docs/en/user-guide/141520.pdf + """ + + def __init__(self, acr122u): + """create a PN532 object + + Attributes: + acr122u: the reader used to communicate with the chip (i.e. the reader the chip is in) + """ + self.acr122u: Reader = acr122u + + def transmit(self, payload: List[int]): + """send a payload to the chip + + Attributes: + payload: the payload to send + + Returns: + the response from the chip + """ + return self.acr122u.direct_transmit(payload) + + def command(self, mode, arguments=None): + """send a command to the chip + + Attributes: + mode: key value of option.pn532_options + arguments: replace `-1` in the payload by arguments + + Returns: + the response from the chip + """ + payload = option.pn532_options.get(mode) + + if not payload: + raise error.OptionOutOfRange( + "Option do not exist\nHint: try to call help(nfc.Reader().command) to see all options") + + payload = utils.replace_arguments(payload, arguments) + result = self.transmit(payload) + + return result + + def in_auto_poll(self, poll_nr: int, period: int, type1: int, *types): + """ + this command is used to poll card(s) / target(s) of specified Type present in the RF field. + docs: https://www.nxp.com/docs/en/user-guide/141520.pdf section 7.3.13 + + Attributes: + poll_nr - specifies the number of polling (one polling is a polling for each Type j) + 0x01: 0xFE:1 up to 254 polling + 0xFF: Endless polling + period - (0x01 – 0x0F) indicates the polling period in units of 150 ms + type1 - indicates the mandatory target type to be polled at the 1st time + types - indicate the optional target types to be polled at the 2nd up to the Nth time (N ≤ 15). + + + Returns: + the response from the chip + """ + arguments = [poll_nr, period, type1] + list(types) + + data = self.command("in_auto_poll", arguments) + return data \ No newline at end of file diff --git a/src/py_acr122u/option.py b/src/py_acr122u/option.py index 1247fb2..0d97d75 100644 --- a/src/py_acr122u/option.py +++ b/src/py_acr122u/option.py @@ -38,3 +38,6 @@ "F0 11": "FeliCa 212K", "F0 12": "FeliCa 424K" } +pn532_options = { + "in_auto_poll": [0xD4, 0x60, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], +} diff --git a/tests/in_auto_poll_test.py b/tests/in_auto_poll_test.py new file mode 100644 index 0000000..ced59cb --- /dev/null +++ b/tests/in_auto_poll_test.py @@ -0,0 +1,45 @@ +import pytest + +from py_acr122u.nfc import Reader + + +@pytest.fixture +def reader(mocker) -> Reader: + mocker.patch("py_acr122u.nfc.Reader.instantiate_reader", return_value=(None, None)) + r = Reader() + return r + +@pytest.mark.parametrize("transmitted, poll_nr, period, type1", [ + ([0xD4, 0x60, 0xFF, 0x01, 0x10], 0xff, 0x01, 0x10), + ([0xD4, 0x60, 0x01, 0x02, 0x40], 0x01, 0x02, 0x40), + ([0xD4, 0x60, 0xFE, 0x0F, 0x50], 0xFE, 0x0F, 0x50), +]) +def test_in_aut_poll_commands(transmitted, poll_nr, period, type1, reader, mocker): + mock_transmit = mocker.patch("py_acr122u.nfc.Reader._PN532.transmit") + + reader.pn532.in_auto_poll(poll_nr, period, type1,) + + mock_transmit.assert_called_with(transmitted) + +@pytest.mark.parametrize("transmitted, poll_nr, period, type1, type2", [ + ([0xD4, 0x60, 0xFF, 0x01, 0x10, 0x20], 0xff, 0x01, 0x10, 0x20), + ([0xD4, 0x60, 0x01, 0x02, 0x40, 0x20], 0x01, 0x02, 0x40, 0x20), + ([0xD4, 0x60, 0xFE, 0x0F, 0x50, 0x20], 0xFE, 0x0F, 0x50, 0x20), +]) +def test_in_aut_poll_commands_more_types(transmitted, poll_nr, period, type1, type2, reader, mocker): + mock_transmit = mocker.patch("py_acr122u.nfc.Reader._PN532.transmit") + + reader.pn532.in_auto_poll(poll_nr, period, type1, type2) + + mock_transmit.assert_called_with(transmitted) +@pytest.mark.parametrize("transmitted, poll_nr, period, type1, type2, type3", [ + ([0xD4, 0x60, 0xFF, 0x01, 0x10, 0x20, 0x15], 0xff, 0x01, 0x10, 0x20, 0x15), + ([0xD4, 0x60, 0x01, 0x02, 0x40, 0x20, 0x15], 0x01, 0x02, 0x40, 0x20, 0x15), + ([0xD4, 0x60, 0xFE, 0x0F, 0x50, 0x20, 0x15], 0xFE, 0x0F, 0x50, 0x20, 0x15), +]) +def test_in_aut_poll_commands_even_more_types(transmitted, poll_nr, period, type1, type2, type3, reader, mocker): + mock_transmit = mocker.patch("py_acr122u.nfc.Reader._PN532.transmit") + + reader.pn532.in_auto_poll(poll_nr, period, type1, type2, type3) + + mock_transmit.assert_called_with(transmitted) \ No newline at end of file From cef03e3590a78fbd6129f17350a2bf24fe40e8da Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 14:55:49 +0200 Subject: [PATCH 22/28] Bump version 2.1.0 -> 2.2.0 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8aefe80..b8f2a94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "2.1.0" +version = "2.2.0" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest", "pytest-mock"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "2.1.0" +current_version = "2.2.0" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index dac7778..1f8197c 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "2.1.0" \ No newline at end of file +__version__ = "2.2.0" \ No newline at end of file From 921b58ef3504955a2332216d717196c0b3faafdd Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 15:50:32 +0200 Subject: [PATCH 23/28] Fix reset lights --- src/py_acr122u/nfc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index d7d3847..9b418ce 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -248,7 +248,7 @@ def unmute_buzzer(self): def reset_lights(self): """turn the red and green LED off""" - self.led_control(0b00110000, 0x00, 0x00, 0x00, 0x00) + self.led_control(0b00001100, 0x00, 0x00, 0x00, 0x00) def info(self): """print the type of the card on the reader""" From 7fed8663f08db14a669f4e4b1d2779645c077b94 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Sun, 2 Apr 2023 15:50:46 +0200 Subject: [PATCH 24/28] Bump version 2.2.0 -> 2.2.1 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b8f2a94..5d65803 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "2.2.0" +version = "2.2.1" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest", "pytest-mock"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "2.2.0" +current_version = "2.2.1" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 1f8197c..161cd2e 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "2.2.0" \ No newline at end of file +__version__ = "2.2.1" \ No newline at end of file From 5bfb1e2a0d7b011c969dec0b1dc995aa1f388441 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Tue, 4 Apr 2023 11:45:12 +0200 Subject: [PATCH 25/28] Fix keyword --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5d65803..80020db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", ] -keywords = ["nfc", "acs", "acr122u"] +keywords = ["nfc", "acr", "acr122u"] dependencies = [ "pyscard>=2.0.7", ] From 67bf72c557f5c38a984c385572f23ed7513c1165 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Tue, 4 Apr 2023 11:45:20 +0200 Subject: [PATCH 26/28] Remove unused main file --- src/py_acr122u/main.py | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/py_acr122u/main.py diff --git a/src/py_acr122u/main.py b/src/py_acr122u/main.py deleted file mode 100644 index 89be969..0000000 --- a/src/py_acr122u/main.py +++ /dev/null @@ -1,5 +0,0 @@ -from src.py_acr122u import nfc - -reader = nfc.Reader() -reader.print_data(reader.get_uid()) -reader.info() From 56fb8fb81278696398afde700d6bd60d2c1d7778 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Tue, 4 Apr 2023 12:00:25 +0200 Subject: [PATCH 27/28] Add use of logger --- src/py_acr122u/nfc.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/py_acr122u/nfc.py b/src/py_acr122u/nfc.py index 9b418ce..4194ad7 100644 --- a/src/py_acr122u/nfc.py +++ b/src/py_acr122u/nfc.py @@ -7,6 +7,10 @@ from . import utils, error, option +import logging + +logger = logging.getLogger(__name__) + class Reader: def __init__(self): @@ -19,12 +23,16 @@ def __init__(self): def instantiate_reader(): readers = smartcard.System.readers() + logger.debug(f"Available readers: {readers}") + if len(readers) == 0: raise error.NoReader("No readers available") reader = readers[0] c = reader.createConnection() + logger.info(f"Using reader {reader}") + return reader, c def connect(self): @@ -32,6 +40,7 @@ def connect(self): only works if a card is on the reader""" try: self.connection.connect() + logger.debug("Reader connected") except: raise error.NoCommunication( "The reader has been deleted and no communication is now possible. Smartcard error code : 0x7FEFFF97" @@ -63,6 +72,7 @@ def command(self, mode, arguments=None): "Option do not exist\nHint: try to call help(nfc.Reader().command) to see all options") payload = utils.replace_arguments(payload, arguments) + logger.debug(f"Transmitting {payload}") result = self.connection.transmit(payload, protocol=CardConnection.T1_protocol) if len(result) == 3: @@ -73,7 +83,8 @@ def command(self, mode, arguments=None): if [sw1, sw2] == option.answers.get("fail"): raise error.InstructionFailed(f"Instruction {mode} failed") - print(f"success: {mode}") + logger.debug(f"Success: {mode}, result: {result}") + if data: return data @@ -85,6 +96,7 @@ def custom(self, payload): Format: CLA INS P1 P2 P3 Lc Data Le""" + logger.debug(f"Transmitting {payload}") result = self.connection.transmit(payload) if len(result) == 3: @@ -95,6 +107,8 @@ def custom(self, payload): if [sw1, sw2] == option.answers.get("fail"): raise error.InstructionFailed(f"Payload {payload} failed") + logger.debug(f"Success transmitting payload: {payload}") + def get_uid(self): """get the uid of the card""" return self.command("get_uid") @@ -294,6 +308,7 @@ def transmit(self, payload: List[int]): Returns: the response from the chip """ + logger.debug(f"Transmitting payload {payload} to PN532") return self.acr122u.direct_transmit(payload) def command(self, mode, arguments=None): @@ -337,4 +352,4 @@ def in_auto_poll(self, poll_nr: int, period: int, type1: int, *types): arguments = [poll_nr, period, type1] + list(types) data = self.command("in_auto_poll", arguments) - return data \ No newline at end of file + return data From b64495efd9cfe2086b2e7a2830850914f80f7de4 Mon Sep 17 00:00:00 2001 From: Robert van Dijk Date: Tue, 4 Apr 2023 12:00:35 +0200 Subject: [PATCH 28/28] Bump version 2.2.1 -> 2.3.0 --- pyproject.toml | 4 ++-- src/py_acr122u/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 80020db..606b947 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "py-acr122u" -version = "2.2.1" +version = "2.3.0" description = "This is a python library for the ACR122U NFC reader" readme = "README.md" authors = [{ name = "Robert van Dijk", email = "contact@robertvandijk.nl" }] @@ -27,7 +27,7 @@ dev = ["black", "bumpver", "isort", "pip-tools", "pytest", "pytest-mock"] Homepage = "https://github.com/robertdijk/py-acr122u" [tool.bumpver] -current_version = "2.2.1" +current_version = "2.3.0" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/py_acr122u/__init__.py b/src/py_acr122u/__init__.py index 161cd2e..59124ba 100644 --- a/src/py_acr122u/__init__.py +++ b/src/py_acr122u/__init__.py @@ -1 +1 @@ -__version__ = "2.2.1" \ No newline at end of file +__version__ = "2.3.0" \ No newline at end of file