lenz-flashtool 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/.gitignore +2 -1
  2. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/PKG-INFO +27 -17
  3. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/README.md +13 -15
  4. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/__init__.py +9 -3
  5. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/biss/cli.py +1 -1
  6. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/biss/commands.py +6 -9
  7. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/__init__.py +4 -2
  8. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/core.py +289 -29
  9. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/hex_utils.py +91 -12
  10. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/operations.py +2 -2
  11. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/uart.py +161 -1
  12. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/pyproject.toml +32 -2
  13. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/LICENSE +0 -0
  14. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/biss/__init__.py +0 -0
  15. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/biss/crc.py +0 -0
  16. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/biss/registers.py +0 -0
  17. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/encproc/__init__.py +0 -0
  18. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/encproc/processing.py +0 -0
  19. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/errors.py +0 -0
  20. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/flashtool/logging.py +0 -0
  21. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/testing/__init__.py +0 -0
  22. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/testing/mock_flashtool.py +0 -0
  23. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/utils/__init__.py +0 -0
  24. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/utils/plot.py +0 -0
  25. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/utils/progress.py +0 -0
  26. {lenz_flashtool-0.1.0 → lenz_flashtool-0.1.2}/lenz_flashtool/utils/termcolors.py +0 -0
@@ -9,4 +9,5 @@ env/
9
9
  dist/
10
10
  build/
11
11
  _bak/
12
- *.log
12
+ *.log
13
+ *.ps1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lenz-flashtool
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: FlashTool library for BiSS C Firmware Update and Calibration by LENZ Encoders
5
5
  Project-URL: Homepage, https://github.com/lenzencoders/lenz-flashtool-lib
6
6
  Project-URL: Source, https://github.com/lenzencoders/lenz-flashtool-lib
@@ -29,22 +29,36 @@ License: MIT License
29
29
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
30
  SOFTWARE.
31
31
  License-File: LICENSE
32
- Keywords: angle,biss,encoder,flashtool,lenz
32
+ Keywords: angle,automation,biss,biss encoder,biss-c,calibration,embedded systems,encoder,firmware,flashtool,hardware,lenz,motion control,serial communication,servomotor
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Environment :: Console
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Intended Audience :: Manufacturing
33
37
  Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Natural Language :: English
34
39
  Classifier: Operating System :: OS Independent
35
40
  Classifier: Programming Language :: Python :: 3
41
+ Classifier: Topic :: Communications
42
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
43
+ Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
44
+ Classifier: Topic :: Software Development :: Embedded Systems
45
+ Classifier: Topic :: Software Development :: Libraries
46
+ Classifier: Topic :: System :: Hardware
47
+ Classifier: Topic :: Utilities
36
48
  Requires-Python: >=3.8
37
49
  Requires-Dist: numpy>=1.21.0
38
50
  Requires-Dist: pyserial>=3.5
39
51
  Description-Content-Type: text/markdown
40
52
 
41
-
42
53
  # lenz-flashtool
54
+ [![PyPI Version](https://img.shields.io/pypi/v/lenz-flashtool)](https://pypi.org/project/lenz-flashtool/)
43
55
 
44
56
  FlashTool library for BiSS C Firmware Update and Calibration by LENZ Encoders.
45
57
 
46
58
  This is the source repository for the `lenz-flashtool` Python package, designed to interface with LENZ BiSS C encoders for firmware updates, calibration, and data reading. It provides a `FlashTool` class and utility functions for working with encoder hardware, including hex file manipulation and color formatting utilities.
47
59
 
60
+ [**📚 Full Documentation: flashtool.lenzencoders.com**](https://flashtool.lenzencoders.com)
61
+
48
62
  ## Features
49
63
 
50
64
  - Control LENZ BiSS C encoders via serial communication.
@@ -54,14 +68,14 @@ This is the source repository for the `lenz-flashtool` Python package, designed
54
68
 
55
69
  ## Installation
56
70
 
57
- ### From local folder
71
+ ### From PyPI (Recommended)
58
72
  ```bash
59
- pip install .
73
+ pip install lenz-flashtool
60
74
  ```
61
75
 
62
- ### From PyPI
76
+ ### From local folder
63
77
  ```bash
64
- pip install lenz-flashtool
78
+ pip install .
65
79
  ```
66
80
 
67
81
  ### From GitHub
@@ -84,12 +98,12 @@ from lenz_flashtool import FlashTool, init_logging
84
98
  # Set up logging
85
99
  #
86
100
  # Level Integer Value
87
- # logging.CRITICAL 50
88
- # logging.ERROR 40
89
- # logging.WARNING 30
90
- # logging.INFO 20
91
- # logging.DEBUG 10
92
- # logging.NOTSET 0
101
+ # logging.CRITICAL 50
102
+ # logging.ERROR 40
103
+ # logging.WARNING 30
104
+ # logging.INFO 20
105
+ # logging.DEBUG 10
106
+ # logging.NOTSET 0
93
107
  init_logging(logfilename="flashtool.log", stdout_level=20, file_level=10)
94
108
 
95
109
  # Initialize FlashTool
@@ -142,7 +156,3 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
142
156
  ## Contact
143
157
 
144
158
  For support or inquiries, contact LENZ ENCODERS at [info@lenzencoders.com](mailto:devs@lenzencoders.com).
145
- ```
146
-
147
-
148
-
@@ -1,10 +1,12 @@
1
-
2
1
  # lenz-flashtool
2
+ [![PyPI Version](https://img.shields.io/pypi/v/lenz-flashtool)](https://pypi.org/project/lenz-flashtool/)
3
3
 
4
4
  FlashTool library for BiSS C Firmware Update and Calibration by LENZ Encoders.
5
5
 
6
6
  This is the source repository for the `lenz-flashtool` Python package, designed to interface with LENZ BiSS C encoders for firmware updates, calibration, and data reading. It provides a `FlashTool` class and utility functions for working with encoder hardware, including hex file manipulation and color formatting utilities.
7
7
 
8
+ [**📚 Full Documentation: flashtool.lenzencoders.com**](https://flashtool.lenzencoders.com)
9
+
8
10
  ## Features
9
11
 
10
12
  - Control LENZ BiSS C encoders via serial communication.
@@ -14,14 +16,14 @@ This is the source repository for the `lenz-flashtool` Python package, designed
14
16
 
15
17
  ## Installation
16
18
 
17
- ### From local folder
19
+ ### From PyPI (Recommended)
18
20
  ```bash
19
- pip install .
21
+ pip install lenz-flashtool
20
22
  ```
21
23
 
22
- ### From PyPI
24
+ ### From local folder
23
25
  ```bash
24
- pip install lenz-flashtool
26
+ pip install .
25
27
  ```
26
28
 
27
29
  ### From GitHub
@@ -44,12 +46,12 @@ from lenz_flashtool import FlashTool, init_logging
44
46
  # Set up logging
45
47
  #
46
48
  # Level Integer Value
47
- # logging.CRITICAL 50
48
- # logging.ERROR 40
49
- # logging.WARNING 30
50
- # logging.INFO 20
51
- # logging.DEBUG 10
52
- # logging.NOTSET 0
49
+ # logging.CRITICAL 50
50
+ # logging.ERROR 40
51
+ # logging.WARNING 30
52
+ # logging.INFO 20
53
+ # logging.DEBUG 10
54
+ # logging.NOTSET 0
53
55
  init_logging(logfilename="flashtool.log", stdout_level=20, file_level=10)
54
56
 
55
57
  # Initialize FlashTool
@@ -102,7 +104,3 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
102
104
  ## Contact
103
105
 
104
106
  For support or inquiries, contact LENZ ENCODERS at [info@lenzencoders.com](mailto:devs@lenzencoders.com).
105
- ```
106
-
107
-
108
-
@@ -31,7 +31,10 @@ from .flashtool import (
31
31
  get_nonce,
32
32
  _readhex,
33
33
  biss_send_hex,
34
- biss_send_dif
34
+ biss_send_dif,
35
+ calculate_checksum,
36
+ dif2hex,
37
+ prep_hex
35
38
  )
36
39
  from .testing import MockFlashTool
37
40
  from .encproc import LenzEncoderProcessor
@@ -56,13 +59,16 @@ __all__ = [
56
59
  'generate_hex_line',
57
60
  'init_logging',
58
61
  'get_nonce',
62
+ 'calculate_checksum',
59
63
  '_readhex',
60
64
  'biss_send_dif',
61
65
  'biss_send_hex',
62
66
  'plot',
63
67
  'plot2',
64
- 'TermColors'
68
+ 'TermColors',
69
+ 'dif2hex',
70
+ 'prep_hex'
65
71
  ]
66
72
 
67
- __version__ = "0.1.0"
73
+ __version__ = "0.1.2"
68
74
  __author__ = "LENZ ENCODERS"
@@ -223,7 +223,7 @@ class BiSSCommandLine:
223
223
  biss_commands[command][0] & 0xFF,
224
224
  (biss_commands[command][0] >> 8) & 0xFF
225
225
  ]
226
- self.ft.biss_write_word(BiSSBank.CMD_REG_INDEX, 0, cmd_data)
226
+ self.ft.biss_write_word(BiSSBank.CMD_REG_INDEX, cmd_data)
227
227
  time.sleep(0.3)
228
228
  self.ft.biss_read_flags()
229
229
 
@@ -146,12 +146,9 @@ def interpret_error_flags(error_int: int) -> list:
146
146
  List[str]: A list of active error flags based on the set bits in the input integer.
147
147
  If no flags are set, returns ["No error flags set"].
148
148
  """
149
- active_flags = []
150
-
151
- for bit_pos, flag_name in ERROR_FLAGS.items():
152
- if error_int & (1 << bit_pos):
153
- active_flags.append(flag_name)
154
-
155
- if active_flags:
156
- return active_flags
157
- return ["No error flags set"]
149
+ error_int = int(error_int)
150
+ active_flags = [
151
+ flag_name for bit_pos, flag_name in ERROR_FLAGS.items()
152
+ if error_int & (1 << bit_pos)
153
+ ]
154
+ return active_flags or ["No error flags set"]
@@ -20,7 +20,7 @@ Author:
20
20
  from .uart import UartCmd
21
21
  from .core import FlashTool
22
22
  from .logging import init_logging
23
- from .hex_utils import get_nonce, generate_hex_line, calculate_checksum, _readhex
23
+ from .hex_utils import get_nonce, generate_hex_line, calculate_checksum, _readhex, dif2hex, prep_hex
24
24
  from .errors import FlashToolError
25
25
  from .operations import biss_send_dif, biss_send_hex
26
26
  __all__ = [
@@ -33,5 +33,7 @@ __all__ = [
33
33
  'FlashToolError',
34
34
  '_readhex',
35
35
  'biss_send_dif',
36
- 'biss_send_hex'
36
+ 'biss_send_hex',
37
+ "dif2hex",
38
+ "prep_hex"
37
39
  ]
@@ -27,7 +27,7 @@ import serial.tools.list_ports
27
27
  import numpy as np
28
28
  from ..biss import (
29
29
  biss_commands, interpret_biss_commandstate, interpret_error_flags,
30
- BiSSBank
30
+ BiSSBank,
31
31
  )
32
32
  from .uart import UartCmd
33
33
  from .errors import FlashToolError
@@ -300,7 +300,9 @@ class FlashTool:
300
300
  >>> ft._write_to_port(b'\\x01\\x00@\\x0b\\xff\\xb5') # Power off encoder on channel 2
301
301
  """
302
302
  try:
303
+ self.__port.reset_output_buffer()
303
304
  self.__port.write(data)
305
+ self.__port.flush()
304
306
  except (serial.SerialException, OSError) as e:
305
307
  logger.error("Port write failed: %s", e)
306
308
  raise FlashToolError(f"Hardware communication failed: {e}") from e
@@ -476,7 +478,7 @@ class FlashTool:
476
478
  """
477
479
  # logger.debug(f'Uploading {hex_line} to the FlashTool.')
478
480
  tx_row = bytes.fromhex(hex_line[1:])
479
- # logger.debug(tx_row)
481
+ logger.debug(tx_row.hex())
480
482
  self._write_to_port(tx_row)
481
483
  return tx_row
482
484
 
@@ -619,6 +621,7 @@ class FlashTool:
619
621
  array([0x01, 0x00], dtype=uint8)
620
622
  """
621
623
  self._write_to_port(generate_byte_line(BiSSBank.STATE_FLAG_REG_INDEX, UartCmd.HEX_READ_CMD, [1, 2]))
624
+ self.__port.reset_input_buffer()
622
625
  time.sleep(0.01)
623
626
 
624
627
  if self.__port.in_waiting >= 1:
@@ -660,7 +663,8 @@ class FlashTool:
660
663
  ...
661
664
  """
662
665
  self.biss_set_bank(bissbank)
663
- self.__port.flushInput()
666
+ # self.__port.flushInput()
667
+ self.__port.reset_input_buffer()
664
668
  self._write_to_port(
665
669
  generate_byte_line(0, UartCmd.HEX_READ_CMD,
666
670
  [item for item in list(range(BiSSBank.REGISTER_PLUS_FIXED_BANK_SIZE))]))
@@ -749,7 +753,7 @@ class FlashTool:
749
753
  """
750
754
  logger.debug('Sending POWER_ON command to the encoder')
751
755
  tx_row = bytes.fromhex(generate_hex_line(0, UartCmd.CMD_CH1_POWER_ON, [0])[1:])
752
- # logger.debug(tx_row)
756
+ logger.debug(tx_row.hex())
753
757
  self._write_to_port(tx_row)
754
758
 
755
759
  def encoder_power_cycle(self) -> None:
@@ -807,8 +811,9 @@ class FlashTool:
807
811
  tx_row = bytes.fromhex(generate_hex_line(0, UartCmd.CMD_NVRST, [0])[1:])
808
812
  # logger.debug(tx_row)
809
813
  self._write_to_port(tx_row)
814
+ time.sleep(0.01)
810
815
 
811
- def select_SPI_channel(self, channel: np.uint8) -> None:
816
+ def select_spi_channel(self, channel: np.uint8) -> None:
812
817
  """
813
818
  Select SPI communication channel.
814
819
 
@@ -849,42 +854,57 @@ class FlashTool:
849
854
  self.__port.write(tx_row)
850
855
  self.__port.flush()
851
856
 
852
- def select_FlashTool_mode(self, mode: np.uint8):
857
+ def select_flashtool_mode(self, mode: np.uint8):
853
858
  """
854
859
  Select FlashTool mode.
855
860
 
856
- Sends a SELECT Flashtool mode command to the FlashTool.
857
-
858
- There are three modes:
859
- 0 --> BISS_MODE_SPI_SPI.
860
- 1 --> BISS_MODE_AB_UART.
861
- 2 --> BISS_MODE_SPI_UART_IRS.
862
- 3 --> BISS_MODE_AB_SPI.
861
+ Sends a SELECT FLASHTOOL MODE command to configure the communication protocol
862
+ for both channels of the FlashTool.
863
+
864
+ Available modes:
865
+ 0 (BISS_MODE_SPI_SPI):
866
+ Channel 1: SPI, Channel 2: SPI
867
+ 1 (BISS_MODE_AB_UART):
868
+ Channel 1: AB signal, Channel 2: UART
869
+ 2 (BISS_MODE_SPI_UART_IRS):
870
+ Channel 1: SPI, Channel 2: UART for IRS encoders
871
+ 3 (BISS_MODE_AB_SPI):
872
+ Channel 1: AB signal, Channel 2: SPI
873
+ 4 (BISS_MODE_DEFAULT_SPI):
874
+ Default mode - Channel 1: Without communication, Channel 2: SPI
863
875
 
864
876
  Args:
865
- mode (uint8): The mode number (must be 0, 1, 2, 3).
877
+ mode (np.uint8): The communication mode number (0-4)
878
+ - 0: SPI on both channels
879
+ - 1: AB sginal + UART
880
+ - 2: SPI + UART for IRS encoders
881
+ - 3: AB signal + SPI
882
+ - 4: Without communication + SPI
866
883
 
867
884
  Returns:
868
885
  None
869
886
 
870
887
  Raises:
871
- ValueError: If the mode is not 0, 1, 2, 3.
888
+ ValueError: If the mode is not in range 0-4
889
+ TypeError: If the mode is not convertible to np.uint8
872
890
 
873
891
  Example:
874
892
  >>> ft = FlashTool()
875
- >>> ft.select_FlashTool_mode(0)
893
+ >>> ft.select_flashtool_mode(0) # Sets SPI on both channels
894
+ >>> ft.select_flashtool_mode(2) # Sets SPI + UART for IRS encoders
876
895
  """
877
896
  mode = np.uint8(mode)
878
- valid_modes = {np.uint8(0), np.uint8(1), np.uint8(2), np.uint8(3)}
897
+ valid_modes = {np.uint8(0), np.uint8(1), np.uint8(2), np.uint8(3), np.uint8(4)}
879
898
  if mode not in valid_modes:
880
899
  raise ValueError(f"Invalid mode: {mode}. Must be one of the {valid_modes} (0: BISS_MODE_SPI_SPI, 1: \
881
- BISS_MODE_AB_UART, 2: BISS_MODE_SPI_UART_IRS, 3: BISS_MODE_AB_SPI).")
900
+ BISS_MODE_AB_UART, 2: BISS_MODE_SPI_UART_IRS, 3: BISS_MODE_AB_SPI, 4: BISS_MODE_DEFAULT_SPI).")
882
901
 
883
902
  mode_descriptions = {
884
903
  0: "BISS_MODE_SPI_SPI",
885
904
  1: "BISS_MODE_AB_UART",
886
905
  2: "BISS_MODE_SPI_UART_IRS",
887
- 3: "BISS_MODE_AB_SPI"
906
+ 3: "BISS_MODE_AB_SPI",
907
+ 4: "BISS_MODE_DEFAULT_SPI"
888
908
  }
889
909
  logger.info(f"Selected FlashTool mode: {mode} - {mode_descriptions[mode]}")
890
910
 
@@ -893,6 +913,91 @@ class FlashTool:
893
913
  self.__port.reset_output_buffer()
894
914
  self.__port.write(tx_row)
895
915
  self.__port.flush()
916
+ time.sleep(0.05)
917
+
918
+ def select_FlashTool_current_sensor_mode(self, mode: np.uint8):
919
+ """
920
+ Select FlashTool Current sensor mode.
921
+
922
+ Sends a SELECT Current sensor mode command to the FlashTool.
923
+
924
+ There are two modes:
925
+ 0 --> CURRENT_SENSOR_MODE_DISABLE.
926
+ 1 --> CURRENT_SENSOR_MODE_ENABLE.
927
+
928
+ Args:
929
+ mode (uint8): The mode number (must be 0, 1).
930
+
931
+ Returns:
932
+ None
933
+
934
+ Raises:
935
+ ValueError: If the mode is not 0, 1.
936
+
937
+ Example:
938
+ >>> ft = FlashTool()
939
+ >>> ft.select_FlashTool_current_sensor_mode(0)
940
+ """
941
+ mode = np.uint8(mode)
942
+ valid_modes = {np.uint8(0), np.uint8(1)}
943
+ if mode not in valid_modes:
944
+ raise ValueError(f"Invalid mode: {mode}. Must be one of the {valid_modes} (0: CURRENT_SENSOR_MODE_DISABLE, 1: \
945
+ CURRENT_SENSOR_MODE_ENABLE).")
946
+
947
+ mode_descriptions = {
948
+ 0: "CURRENT_SENSOR_MODE_DISABLE",
949
+ 1: "CURRENT_SENSOR_MODE_ENABLE"
950
+ }
951
+ logger.info(f"Selected current sensor mode: {mode} - {mode_descriptions[mode]}")
952
+
953
+ tx_row = bytes.fromhex(generate_hex_line(0, UartCmd.CMD_SELECT_FLASHTOOL_CURRENT_SENSOR_MODE, [mode])[1:])
954
+ logger.debug(tx_row.hex())
955
+ self.__port.reset_output_buffer()
956
+ self.__port.write(tx_row)
957
+ self.__port.flush()
958
+
959
+ def select_spi_ch1_mode(self, mode: np.uint8) -> None:
960
+ """
961
+ Select SPI channel 1 mode.
962
+
963
+ Sends a SELECT channel 1 SPI mode command to the FlashTool.
964
+
965
+ There are three modes:
966
+ 0 --> CH1_LENZ_BISS;
967
+ 1 --> CH1_LIR_SSI;
968
+ 2 --> CH1_LIR_BISS_21B
969
+
970
+ Args:
971
+ mode (uint8): The mode number (must be 0 or 1 or 2).
972
+
973
+ Returns:
974
+ None
975
+
976
+ Raises:
977
+ ValueError: If the mode is not 0 or 1 or 2.
978
+
979
+ Example:
980
+ >>> ft = FlashTool()
981
+ >>> ft.select_spi_ch1_mode(0)
982
+ """
983
+ mode = np.uint8(mode)
984
+ valid_channels = {np.uint8(0), np.uint8(1), np.uint8(2)}
985
+ if mode not in valid_channels:
986
+ raise ValueError(f"Invalid mode: {mode}. Must be one of the {valid_channels} (0: CH1_LENZ_BISS, 1: \
987
+ CH1_LIR_SSI, 2: CH1_LIR_BISS_21B).")
988
+
989
+ channel_descriptions = {
990
+ 0: "CH1_LENZ_BISS",
991
+ 1: "CH1_LIR_SSI",
992
+ 2: "CH1_LIR_BISS_21B"
993
+ }
994
+ logger.info(f"Selected SPI channel 1 Mode: {mode} - {channel_descriptions[mode]}")
995
+
996
+ tx_row = bytes.fromhex(generate_hex_line(0, UartCmd.CMD_SELECT_CH1_MODE, [mode])[1:])
997
+ # logger.debug(tx_row)
998
+ self.__port.reset_output_buffer()
999
+ self.__port.write(tx_row)
1000
+ self.__port.flush()
896
1001
 
897
1002
  def read_data(self, read_time: float) -> np.ndarray:
898
1003
  """
@@ -1145,6 +1250,7 @@ class FlashTool:
1145
1250
  """
1146
1251
  try:
1147
1252
  self._write_to_port(generate_byte_line(BiSSBank.FIXED_ADDRESSES_START_INDEX, UartCmd.HEX_READ_CMD, list(range(64))))
1253
+ self.__port.reset_input_buffer()
1148
1254
  time.sleep(0.1)
1149
1255
  cor = BiSSBank.FIXED_ADDRESSES_START_INDEX
1150
1256
  enc_ver_answ_uint8 = self.port_read(BiSSBank.FIXED_BANK_SIZE)
@@ -1444,7 +1550,7 @@ class FlashTool:
1444
1550
  try:
1445
1551
  state_flags = self.biss_read_state_flags()
1446
1552
  logger.debug("State flags raw data: %s", state_flags)
1447
- flags = (state_flags[1] << 8) | state_flags[0]
1553
+ flags = (np.uint16(state_flags[1]) << 8) | state_flags[0]
1448
1554
  interpreted_flags = interpret_error_flags(flags)
1449
1555
  logger.info("Interpreted error flags: %s", interpreted_flags)
1450
1556
  command_state = self.biss_read_command_state()[0]
@@ -1473,14 +1579,44 @@ class FlashTool:
1473
1579
  [2119664]: 45° 30' 15"
1474
1580
  """
1475
1581
  degree_sign = "\N{DEGREE SIGN}"
1476
- _, ans = self.read_data_enc1_enc2_SPI(0.01, False)
1477
- res = 2**24
1478
- ang = int(ans[0]) * 360 / res
1479
- degrs = int(ang)
1480
- mins = int((ang - degrs) * 60)
1481
- secs = int((ang - degrs - (mins / 60)) * 3600)
1482
- sys.stdout.write("\r" + f'[{ans[0]}]: \t {str(degrs):>3}{degree_sign} {str(mins):2}\' {str(secs):2}\"' + '\t\t')
1483
- logger.debug(f'[{ans[0]}]: \t {str(degrs):>3}{degree_sign} {str(mins):2}\' {str(secs):2}\"')
1582
+ try:
1583
+ # _, ans = self.read_data_enc1_enc2_SPI(0.01, False)
1584
+ ans, _ = self.read_data_enc1_AB_enc2_SPI(0.01, False)
1585
+ if not ans.any() or len(ans) < 1:
1586
+ logger.error("No valid data received from encoder")
1587
+ return
1588
+
1589
+ raw_value = int(ans[0])
1590
+ resolution = 2**24
1591
+ total_degrees = raw_value * 360.0 / resolution
1592
+
1593
+ degrees = int(total_degrees)
1594
+ remaining = total_degrees - degrees
1595
+ minutes = int(remaining * 60)
1596
+ seconds = round((remaining * 60 - minutes) * 60, 2)
1597
+
1598
+ output = (f"[{raw_value}]: \t"
1599
+ f"{degrees:>3}{degree_sign} "
1600
+ f"{minutes:02d}' "
1601
+ f"{seconds:05.2f}\"")
1602
+
1603
+ sys.stdout.write("\r" + output + " " * 10)
1604
+ logger.debug(output)
1605
+
1606
+ except ValueError as e:
1607
+ logger.error(f"Invalid encoder data: {e}")
1608
+ except Exception as e:
1609
+ logger.error(f"Error reading angle: {e}")
1610
+
1611
+ # degree_sign = "\N{DEGREE SIGN}"
1612
+ # _, ans = self.read_data_enc1_enc2_SPI(0.01, False)
1613
+ # res = 2**24
1614
+ # ang = int(ans[0]) * 360 / res
1615
+ # degrs = int(ang)
1616
+ # mins = int((ang - degrs) * 60)
1617
+ # secs = int((ang - degrs - (mins / 60)) * 3600)
1618
+ # sys.stdout.write("\r" + f'[{ans[0]}]: \t {str(degrs):>3}{degree_sign} {str(mins):2}\' {str(secs):2}\"' + '\t\t')
1619
+ # logger.debug(f'[{ans[0]}]: \t {str(degrs):>3}{degree_sign} {str(mins):2}\' {str(secs):2}\"')
1484
1620
 
1485
1621
  def biss_zeroing(self) -> None:
1486
1622
  """
@@ -1663,7 +1799,7 @@ class FlashTool:
1663
1799
  else:
1664
1800
  self.biss_write_command('load2k')
1665
1801
 
1666
- time.sleep(0.25)
1802
+ time.sleep(1.25)
1667
1803
 
1668
1804
  if not self.biss_read_flags_flashCRC()[0]:
1669
1805
  success = True
@@ -1678,3 +1814,127 @@ class FlashTool:
1678
1814
  sys.exit(1)
1679
1815
 
1680
1816
  logger.info(" Done uploading!")
1817
+
1818
+ def read_enc2_current(self) -> tuple[str, float] | bool:
1819
+ """
1820
+ Read current of the encoder on channel 2.
1821
+
1822
+ Args:
1823
+ None
1824
+
1825
+ Returns:
1826
+ tuple[str, int]: If successful, returns:
1827
+ - str: Encoder2 current in hexadecimal format
1828
+ - float: Current in mA
1829
+ bool: False if operation fails (CRC error, no response, etc.)
1830
+ """
1831
+ try:
1832
+ self.__port.reset_output_buffer()
1833
+ self.__port.reset_input_buffer()
1834
+ self.__port.write(generate_byte_line(0, UartCmd.HEX_READ_ENC2_CURRENT, list(range(UartCmd.RX_DATA_LENGTH_CURRENT))))
1835
+ self.__port.flush()
1836
+
1837
+ enc_ans = self.__port.read(UartCmd.RX_DATA_LENGTH_CURRENT + UartCmd.PKG_INFO_LENGTH)
1838
+
1839
+ logger.debug(enc_ans.hex())
1840
+
1841
+ if not enc_ans:
1842
+ logger.error("No response from encoder!")
1843
+ return False
1844
+
1845
+ enc_data_np = np.array(list(enc_ans), dtype='uint8')
1846
+
1847
+ if (enc_data_np[0] != enc_data_np.size - UartCmd.PKG_INFO_LENGTH) or \
1848
+ (enc_data_np[3] != UartCmd.HEX_READ_ENC2_CURRENT + UartCmd.CMD_VAL_ADD):
1849
+ logger.error("Invalid response structure from encoder!")
1850
+ return False
1851
+
1852
+ calculated_crc = calculate_checksum(enc_ans[0:-1].hex())
1853
+ if calculated_crc != enc_data_np[-1]:
1854
+ logger.error(f"CRC mismatch: calculated {calculated_crc}, expected {enc_data_np[-1]}")
1855
+ return False
1856
+
1857
+ logger.debug("CRC check passed.")
1858
+
1859
+ enc2_current = enc_ans[4:4+UartCmd.RX_DATA_LENGTH_CURRENT]
1860
+
1861
+ data_hex = enc2_current.hex()
1862
+
1863
+ ans_enc2_current_ma = int.from_bytes(enc2_current, byteorder='little', signed=False) / 1000
1864
+
1865
+ return data_hex, ans_enc2_current_ma
1866
+
1867
+ except Exception as e:
1868
+ logger.error(f"Error reading encoder current: {str(e)}", exc_info=True)
1869
+ return False
1870
+
1871
+ def read_current_angle_enc_SPI(self) -> tuple[str, list[int]] | bool:
1872
+ """
1873
+ Read current angle encoder via SPI over USB.
1874
+
1875
+ Returns:
1876
+ tuple[str, list[int]]: If successful, returns:
1877
+ - str: Encoder angle in hexadecimal format
1878
+ - list[int]: Angle parts [degrees, minutes, seconds]
1879
+ bool: False if operation fails (CRC error, no response, etc.)
1880
+ """
1881
+ CMD_VAL_ADD = 16
1882
+ RX_DATA_LENGTH = 4
1883
+ PKG_INFO_LENGTH = 5 # 5 bytes: length | address_l | address_h | cmd+0x10 | crc [-1]
1884
+ DEGREE_SIGN = "\N{DEGREE SIGN}"
1885
+
1886
+ try:
1887
+ self.__port.reset_output_buffer()
1888
+ self.__port.reset_input_buffer()
1889
+ self.__port.write(generate_byte_line(0, UartCmd.HEX_READ_CURRENT_ANGLE_ENC_SPI, list(range(RX_DATA_LENGTH))))
1890
+ self.__port.flush()
1891
+
1892
+ enc_ans = self.__port.read(RX_DATA_LENGTH + PKG_INFO_LENGTH)
1893
+ # print(f"{enc_ans.hex()}")
1894
+
1895
+ if not enc_ans:
1896
+ logger.error("No response from IRS encoder!")
1897
+ return False
1898
+
1899
+ enc_data_np = np.array(list(enc_ans), dtype='uint8')
1900
+
1901
+ if (enc_data_np[0] != enc_data_np.size - PKG_INFO_LENGTH) or \
1902
+ (enc_data_np[3] != UartCmd.HEX_READ_CURRENT_ANGLE_ENC_SPI + CMD_VAL_ADD):
1903
+ logger.error("Invalid response structure from IRS encoder!")
1904
+ return False
1905
+
1906
+ calculated_crc = calculate_checksum(enc_ans[0:-1].hex())
1907
+ if calculated_crc != enc_data_np[-1]:
1908
+ logger.error(f"CRC mismatch: calculated {calculated_crc}, expected {enc_data_np[-1]}")
1909
+ return False
1910
+
1911
+ logger.debug("CRC check passed.")
1912
+
1913
+ angle_data = enc_ans[4:4+RX_DATA_LENGTH]
1914
+
1915
+ data_hex = angle_data.hex()
1916
+
1917
+ ans_angle = int.from_bytes(angle_data[:3], byteorder='little', signed=False)
1918
+
1919
+ angle_raw = (
1920
+ int(data_hex[4:6], 16) * 65536 +
1921
+ int(data_hex[2:4], 16) * 256 +
1922
+ int(data_hex[0:2], 16)
1923
+ )
1924
+ angle_deg = angle_raw * 360 / 2**24
1925
+
1926
+ degrees = int(angle_deg)
1927
+ remaining = angle_deg - degrees
1928
+ minutes = int(remaining * 60)
1929
+ seconds = int((remaining * 60 - minutes) * 60)
1930
+
1931
+ logger.info(
1932
+ f"[{ans_angle}]: {degrees:>3}{DEGREE_SIGN} "
1933
+ f"{minutes:02d}' {seconds:02d}\""
1934
+ )
1935
+
1936
+ return ans_angle, [degrees, minutes, seconds]
1937
+
1938
+ except Exception as e:
1939
+ logger.error(f"Error reading encoder angle: {str(e)}", exc_info=True)
1940
+ return False
@@ -765,19 +765,92 @@ def _readhex(filepath: str) -> list[str]:
765
765
  return dataframe
766
766
 
767
767
 
768
- def prep_hex(filepath: str) -> None:
768
+ def dif2hex(DifTable: bytes, filename: str, start_page: int) -> None:
769
+ """
770
+ Convert a Diff table to Intel HEX format and save to a file.
771
+
772
+ This function takes a byte array representing a Diff table, converts it to Intel HEX format
773
+ with proper address handling and checksums, and writes the result to the specified file.
774
+ The output includes extended address records, data records, a CRC32 record, and an end-of-file record.
775
+
776
+ Args:
777
+ DifTable: The input byte array containing the data to be converted.
778
+ filename: The path of the output file where the HEX data will be written.
779
+ start_page: The starting page number used to calculate the initial address offset.
780
+ Each page is 2048 bytes (0x800).
781
+
782
+ Returns:
783
+ None: The function writes the result to a file but doesn't return anything.
784
+
785
+ The function handles:
786
+ - 64KB address boundary crossing with extended address records
787
+ - Proper checksum calculation for all record types
788
+ - Generation of data records with 16 bytes per line (standard HEX format)
789
+ - Addition of a CRC32 record (type 0x03) at the end of the file
790
+ - Proper end-of-file marker
791
+
792
+ Example:
793
+ >>> data = bytes([0x01, 0x02, 0x03, 0x04])
794
+ >>> dif2hex(data, "output.hex", 24)
795
+ # Creates output.hex with the converted data
796
+ """
797
+ CRC_RECORD_TYPE = '03'
798
+ lower_addr = 0x800 * start_page # (0x800 = 2048) bytes -- page size
799
+ upper_addr = 0x0800 # Initial upper address
800
+ base_addr = (upper_addr << 16) | lower_addr
801
+ data = bytearray(DifTable)
802
+ hex_file_content = []
803
+ current_upper_addr = upper_addr
804
+
805
+ # Initial extended address record
806
+ extended_addr_record = f":02000004{current_upper_addr:04X}{((~(2 + 4 + (current_upper_addr >> 8) + (current_upper_addr & 0xFF)) + 1) & 0xFF):02X}"
807
+ hex_file_content.append(extended_addr_record)
808
+
809
+ for i in range(0, len(data), 16):
810
+ chunk = data[i:i+16]
811
+ byte_count = len(chunk)
812
+ addr = base_addr + i
813
+ new_upper_addr = (addr >> 16) & 0xFFFF
814
+
815
+ # Check 64 KB boundary
816
+ if new_upper_addr != current_upper_addr:
817
+ current_upper_addr = new_upper_addr
818
+ extended_addr_record = f":02000004{current_upper_addr:04X}{((~(2 + 4 + (current_upper_addr >> 8) + (current_upper_addr & 0xFF)) + 1) & 0xFF):02X}"
819
+ hex_file_content.append(extended_addr_record)
820
+
821
+ record_type = 0
822
+ address_field = addr & 0xFFFF # Lower 16 bits of address
823
+ checksum = byte_count + (address_field >> 8) + (address_field & 0xFF) + record_type + sum(chunk)
824
+ data_record = f":{byte_count:02X}{address_field:04X}{record_type:02X}" + \
825
+ ''.join(f"{b:02X}" for b in chunk) + \
826
+ f"{(256 - checksum % 256) % 256:02X}"
827
+ hex_file_content.append(data_record)
828
+
829
+ crc_record = f"040000{CRC_RECORD_TYPE}{binascii.crc32(data):08X}"
830
+ hex_file_content.append(f":{crc_record}{calculate_checksum(crc_record):02X}")
831
+ hex_file_content.append(":00000001FF")
832
+
833
+ with open(filename, "w") as output:
834
+ for row in hex_file_content:
835
+ output.write(str(row).upper() + '\n')
836
+
837
+
838
+ def prep_hex(filepath: str, section_id: int, count: int, desc: str) -> None:
769
839
  """
770
840
  Main function to prepare HEX file for firmware update.
771
841
 
772
842
  Args:
773
- filepath: Path to input HEX file
843
+ filepath: Path to the input HEX file to be processed
844
+ section_id: Memory section identifier (used to calculate base address)
845
+ count: Number of bytes in the section that need hash protection
846
+ desc: Description tag used to locate the hash file (format: lenz_hash_{desc}.bin)
774
847
 
775
848
  Returns:
776
- None (writes output to <filename>_op.hex)
849
+ None: Writes the processed output to <input_filename>_op.hex
777
850
 
778
851
  Raises:
779
- FileNotFoundError: If input file doesn't exist
780
- IOError: If there are file access issues
852
+ FileNotFoundError: If either the input HEX file or hash binary file doesn't exist
853
+ IOError: If there are file access/permission issues
781
854
  """
782
855
  try:
783
856
  inputhexfile = _readhex(filepath)
@@ -790,14 +863,21 @@ def prep_hex(filepath: str) -> None:
790
863
 
791
864
  print("Input hexfile:", filepath)
792
865
  filename, _ = path.splitext(filepath)
793
- # TODO move hashes to the function args
794
- hashes = [(24, 6144, 'actis')]
795
866
  hash_bytes = []
796
- for section_id, count, desc in hashes:
797
- base_offset = section_id << 5
798
- with open(f'lenz_hash_{desc}.bin', "rb") as f:
867
+ base_offset = section_id << 5
868
+ hash_filename = f'lenz_hash_{desc}.bin'
869
+ try:
870
+ with open(hash_filename, "rb") as f:
799
871
  for _ in range(base_offset, base_offset + ((count >> 6) or 1)):
800
872
  hash_bytes.append(f.read(64))
873
+
874
+ except FileNotFoundError:
875
+ sys.stderr.write(f"Error: Hash file '{hash_filename}' not found.\n")
876
+ sys.exit(1)
877
+ except IOError as e:
878
+ sys.stderr.write(f"Error reading hash file: {e}\n")
879
+ sys.exit(1)
880
+
801
881
  hexdata = []
802
882
  fullhexdataout = []
803
883
  hexdata_parts = (len(inputhexfile) - 4) // 128 + 1
@@ -832,11 +912,10 @@ def prep_hex(filepath: str) -> None:
832
912
  output_filepath = f"{filename}_op.hex"
833
913
  try:
834
914
  with open(output_filepath, "w") as output:
835
- print("Output:", output_filepath)
915
+ print("Successfully generated output:", output_filepath)
836
916
  for hexdataout in fullhexdataout:
837
917
  for cell in hexdataout:
838
918
  output.write(cell.upper() + '\n')
839
- # print("\n")
840
919
  except Exception as e:
841
920
  sys.stderr.write(f"Error writing output file: {e}\n")
842
921
  sys.exit(1)
@@ -96,12 +96,12 @@ def biss_send_hex(file_path: str, nonce: Optional[int] = None, pbar: Optional[An
96
96
  # ft.biss_read_registers(BISS_BANK_SERV)
97
97
  # print('=====')
98
98
  ft.send_data_to_device(pages, crc_values, page_numbers, START_PAGE, END_PAGE, pbar)
99
- ft.read_flags()
99
+ ft.biss_read_flags()
100
100
  sleep(0.2)
101
101
  logger.info('Sending \'run\' command...')
102
102
  ft.biss_write_command("run")
103
103
  sleep(0.4)
104
- ft.read_flags()
104
+ ft.biss_read_flags()
105
105
  ft.close()
106
106
 
107
107
 
@@ -22,6 +22,32 @@ class UartCmd(IntEnum):
22
22
  channel selection, and data communication with the FlashTool hardware.
23
23
  """
24
24
 
25
+ PKG_INFO_LENGTH = 0x05
26
+ """int: Packet INFO constant structure length of 5 bytes
27
+ Request Packet:
28
+ [DUMMY_DATA_SIZE][REG_ADDR][ CMD ][DUMMY_DATA][CHECKSUM]
29
+ [ 1 byte ][2 bytes ][1 byte][----------][ 1 byte ]
30
+ Response Packet:
31
+ [DUMMY_DATA_SIZE][REG_ADDR][CMD+CMD_VAL_ADD][DUMMY_DATA][CHECKSUM]
32
+ [ 1 byte ][2 bytes ][ 1 byte ][----------][ 1 byte ]
33
+ """
34
+
35
+ RX_DATA_LENGTH_IRS = 0xFC
36
+ """int: Data length for command:
37
+ HEX_IRS_ENC_WRITE_READ_CMD: 0x0F
38
+ """
39
+
40
+ RX_DATA_LENGTH_CURRENT = 0x04
41
+ """int: Data length for commands:
42
+ HEX_READ_ENC2_CURRENT: 0x12
43
+ """
44
+
45
+ CMD_VAL_ADD = 0x10
46
+ """int: Value that added to CMD in Repsonse Packet
47
+ Response:
48
+ [DUMMY_DATA_SIZE][REG_ADDR][CMD+CMD_VAL_ADD][DUMMY_DATA][CHECKSUM]
49
+ """
50
+
25
51
  CMD_POWER_OFF = 0x0B
26
52
  """int: Command to power off encoder on channel 2.
27
53
 
@@ -125,12 +151,13 @@ class UartCmd(IntEnum):
125
151
  0x01 for BISS_MODE_AB_UART,
126
152
  0x02 for BISS_MODE_SPI_UART_IRS,
127
153
  0x03 for BISS_MODE_AB_SPI
154
+ 0x04 for BISS_MODE_DEFAULT_SPI
128
155
  - Defines all subsequent communications via SPI, AB (incremental), UART for channels 1 and 2 until changed
129
156
  - Address in packet doesn't matter
130
157
 
131
158
  Note:
132
159
  FlashTool mode is persistent until changed or power cycled
133
- Default: BISS_MODE_SPI_SPI (0x00)
160
+ Default: BISS_MODE_DEFAULT_SPI (0x04) - Channel 1: Without communication, Channel 2: SPI
134
161
 
135
162
  Packet Structure:
136
163
  Request: [01][REG_ADDR][0x01][CHANNEL_BYTE][CHECKSUM]
@@ -140,6 +167,94 @@ class UartCmd(IntEnum):
140
167
  >>> :0100000100FE Select FlashTool mode - BISS_MODE_SPI_SPI
141
168
  """
142
169
 
170
+ CMD_SELECT_FLASHTOOL_CURRENT_SENSOR_MODE = 0x11
171
+ """int: Command to select FlashTool current sensor mode.
172
+
173
+ Black FlashTool has Current Sensor mode.
174
+ Green FlashTool has NOT Current Sensor mode.
175
+
176
+ Usage:
177
+ - Sent before any channel-specific operations
178
+ - Parameter:
179
+ 0x00 for CURRENT_SENSOR_MODE_DISABLE,
180
+ 0x01 for CURRENT_SENSOR_MODE_ENABLE
181
+ - Defines all subsequent communications via SPI, AB (incremental), UART for channels 1 and 2 until changed
182
+ - Address in packet doesn't matter
183
+
184
+ Note:
185
+ FlashTool current sensor mode is persistent until changed or power cycled
186
+ Default: CURRENT_SENSOR_MODE_ENABLE (0x01)
187
+
188
+ Packet Structure:
189
+ Request: [01][REG_ADDR][0x11][CHANNEL_BYTE][CHECKSUM]
190
+ Where CHANNEL_BYTE is 0x00 or 0x01
191
+
192
+ Example:
193
+ >>> :0100001101ed Select current sensor mode - CURRENT_SENSOR_MODE_ENABLE
194
+ """
195
+
196
+ CMD_SELECT_CH1_MODE = 0x0E
197
+ """ Command to select FlashTool channel 1 SPI mode.
198
+ Works for BISS_MODE_SPI_SPI.
199
+
200
+ Usage:
201
+ - Sent before any channel-specific operations
202
+ - Parameter:
203
+ 0x00 for CH1_LENZ_BISS,
204
+ 0x01 for CH1_LIR_SSI,
205
+ 0x02 for CH1_LIR_BISS_21B
206
+ - Defines all subsequent communications via SPI for channel 1
207
+ - Address in packet doesn't matter
208
+
209
+ Note:
210
+ FlashTool current sensor mode is persistent until changed or power cycled
211
+ Default: CH1_LENZ_BISS (0x00)
212
+
213
+ Packet Structure:
214
+ Request: [01][REG_ADDR][0x0E][CHANNEL_BYTE][CHECKSUM]
215
+ Where CHANNEL_BYTE is 0x00 or 0x01 or 0x02
216
+
217
+ Example:
218
+ >>> :0100000e02ef Select channel 1 SPI mode - CH1_LENZ_BISS
219
+ """
220
+
221
+ HEX_READ_ENC2_CURRENT = 0x12
222
+ """int: Command to read current from encoder on channel 2.
223
+
224
+ Usage:
225
+ - Single data frame
226
+ - Requires encoder to be powered on
227
+ - Returns one measurement frame in each response packet
228
+ - Address in packet doesn't matter
229
+
230
+ Packet Structure:
231
+ Request: [DUMMY_DATA_SIZE][REG_ADDR][0x12][DUMMY_DATA][CHECKSUM]
232
+
233
+ Where:
234
+
235
+ - DUMMY_DATA_SIZE: 4 bytes
236
+
237
+ Example Request Packet Structure:
238
+ >>> 0400001200010203e4
239
+
240
+ Response Format:
241
+ Data frame contains:
242
+
243
+ >>> [Header][DataFrame][Checksum]
244
+
245
+ Where:
246
+
247
+ - Header: `[0x04, 0x00, 0x00, 0x22]` (fixed pattern)
248
+ - DataFrame: 1 measurement frame (4 bytes):
249
+
250
+ >>> [ENC2_CURRENT_HIGH][ENC2_CURRENT_MID][ENC2_CURRENT_LOW]
251
+
252
+ - Checksum: 1 byte (sum of first 8 bytes modulo ...)
253
+
254
+ Example Response Packet Structure:
255
+ >>> 04 00 00 22 [frame] [checksum]
256
+ """
257
+
143
258
  CMD_NVRST = 0x83 # Command to reset the FlashTool
144
259
  """int: Command to perform a non-volatile reset of the FlashTool.
145
260
 
@@ -172,6 +287,51 @@ class UartCmd(IntEnum):
172
287
  >>> :0100400D05AD
173
288
  """
174
289
 
290
+ HEX_IRS_ENC_WRITE_READ_CMD = 0x0F
291
+ """int: Command to write data to encoder registers.
292
+
293
+ Usage:
294
+ - Used for configuration and parameter setting
295
+
296
+ Packet Structure:
297
+ Request: [DATA_SIZE][REG_ADDR][0x0D][DATA_MSB][DATA_LSB][CHECKSUM]
298
+ Response: None
299
+
300
+ Example:
301
+ >>> :0100400D05AD
302
+ """
303
+
304
+ HEX_READ_CURRENT_ANGLE_ENC_SPI = 0x10
305
+ """int: Command to read current angle data from encoder via SPI.
306
+
307
+ Usage:
308
+ - Single data frame for encoder reading
309
+ - Requires encoder to be powered on
310
+ - Returns one measurement frame in each response packet
311
+
312
+ Response Format:
313
+ Data frame contains:
314
+
315
+ >>> [Header][DataFrame][Checksum]
316
+
317
+ Where:
318
+
319
+ - Header: `[0x04, 0x00, 0x00, 0x20]` (fixed pattern)
320
+ - DataFrame: 1 measurement frame (8 bytes):
321
+
322
+ >>> [ENC2_LOW][ENC2_MID][ENC2_HIGH][ENC2_COUNTER]
323
+
324
+ - Checksum: 1 byte (sum of first 12 bytes modulo ...)
325
+
326
+ Data Interpretation:
327
+ >>> Encoder Angle = (HIGH << 16) | (MID << 8) | LOW
328
+
329
+ Counter = Single byte turn counter
330
+
331
+ Example Packet Structure:
332
+ >>> 04 00 00 20 [1 frame...] [checksum]
333
+ """
334
+
175
335
  HEX_READ_ANGLE_TWO_ENC_SPI = 0x80
176
336
  """int: Command to read angle data from two encoders via SPI.
177
337
 
@@ -4,17 +4,47 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "lenz-flashtool"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  description = "FlashTool library for BiSS C Firmware Update and Calibration by LENZ Encoders"
9
9
  readme = "README.md"
10
10
  authors = [{name = "LENZ ENCODERS", email = "devs@lenzencoders.com"}]
11
11
  license = {file = "LICENSE"}
12
- keywords = ["biss", "lenz", "encoder", "flashtool", "angle"]
12
+ keywords = [
13
+ "biss",
14
+ "lenz",
15
+ "flashtool",
16
+ "biss-c",
17
+ "biss encoder",
18
+ "angle",
19
+ "servomotor",
20
+ "encoder",
21
+ "firmware",
22
+ "calibration",
23
+ "serial communication",
24
+ "embedded systems",
25
+ "hardware",
26
+ "automation",
27
+ "motion control"
28
+ ]
13
29
  requires-python = ">=3.8"
14
30
  classifiers = [
15
31
  "Programming Language :: Python :: 3",
16
32
  "License :: OSI Approved :: MIT License",
17
33
  "Operating System :: OS Independent",
34
+ "Intended Audience :: Developers",
35
+ "Intended Audience :: Manufacturing",
36
+ "Topic :: Software Development :: Embedded Systems",
37
+ "Topic :: Software Development :: Libraries",
38
+ "Topic :: System :: Hardware",
39
+ "Topic :: Utilities",
40
+ "Topic :: Communications",
41
+ "Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
42
+ "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
43
+ "Topic :: Utilities",
44
+ "Environment :: Console",
45
+ "Development Status :: 4 - Beta",
46
+ "Natural Language :: English",
47
+
18
48
  ]
19
49
  dependencies = [
20
50
  "pyserial>=3.5",
File without changes