Usage#

This section provides examples of using lenz-flashtool for firmware updates, calibration, and CLI operations.

Firmware Update#

Update firmware on a BiSS C encoder device:

import logging
import lenz_flashtool as lenz

lenz.init_logging('flashtool.log', logging.INFO, logging.DEBUG)
with lenz.FlashTool(port_description_prefixes=('XR21V')) as ft:
   lenz.biss_send_hex("SAB039_1_1_4.hex", pbar=True)

Note

The function lenz.biss_send_hex() from the lenz_flashtool.operations module is used here, not the FlashTool() class method.

Using the CLI:

python -m lenz_flashtool.biss.cli sendhexfile .\SAB039_1_1_4.hex y

Calibration#

The following example performs amplitude calibration on a LENZ encoder. The encoder’s rotor must complete one full turn during the process.

import logging
import time
import lenz_flashtool as lenz

lenz.init_logging('flashtool.log', logging.INFO, logging.DEBUG)
with lenz.FlashTool(port_description_prefixes=('XR21V')) as ft:
   ft.encoder_power_cycle()
   ft.biss_write_command('unlocksetup')
   ft.biss_write_command('cleardiflut')
   ft.biss_write_command('unlockflash')
   ft.biss_write_command('ampcalibrate')
   logging.info("Waiting Signal Amplitude Calibration...")
   while ((ft.biss_addr_read(0x4A, 2).view('uint16') & 0xC0) != 128):
      time.sleep(0.2)
   logging.info("Signal Amplitude Calibration Finished")

For more examples, explore the lenz-flashtool Library API Reference or refer to Getting Started.