This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LMK3H0102: Communication using python on windows environment

Part Number: LMK3H0102
Other Parts Discussed in Thread: USB2ANY

Tool/software:

Hi,

I'm trying to write commands using python and windows, the goal is to load a few presets options and toggle between them while running other program.

I've used device.set_raw_data_handler(data_received) - and tried to write the device from TICS PRO software, logged the relevant data.

here's a part of my program, in this example the OUT0 should be off,

writing to address 0x07

data: 0x6501 to turn off

default data is 0x6503:



import pywinusb.hid as hid

# Vendor ID and Product ID of your device
VID = 0x2047
PID = 0x301

# I2C address of the device
I2C_ADDRESS = 0x69
REPORT_ID = 0x00

# Find the device
filter = hid.HidDeviceFilter(vendor_id=VID, product_id=PID)
devices = filter.get_devices()

if devices:
device = devices[0]
device.open()
device.set_raw_data_handler(data_received)
report = device.find_output_reports()

Toff = [63, 10, 84, 43, 2, 2, 0, 31, 0, 7, 101, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 128, 101, 3, 62, 150, 48, 255, 4, 240, 0, 0, 232, 0, 133, 202, 169, 93, 2, 53, 217, 94, 8, 220, 130, 15, 217, 43, 72, 59, 143, 158, 89, 144, 93, 124, 4, 27, 0, 0, 0, 16]

device.send_output_report(Toff)

I don't get any errors but the writing doesn't work. couldn't find any API of documentation to understand the command structure.

would appreciate your support to understand the structure or how to properly set command / load exported values from TICS PRO

  • Orel,

    Have you successfully written from and read to the device through the TICS Pro software, before writing raw packets with the USB2ANY? The LMK3H0102 can be operated in OTP mode, where the I2C interface is not active.

    Thanks,

    Kadeem

  • Writing raw HID packets to the USB2ANY is making this a lot harder than it needs to be. As far as I know, we've never released documentation on the HID command structure. If you absolutely must go this route, I can dig up some old python example code that demonstrates how to structure the USB2ANY HID packets. It can be done, but I strongly advise against it.

    The much easier way to do this is by simply wrapping the USB2ANY DLL included in TICS Pro. See here for example code demonstrating how to wrap the DLL and basics of communicating with the APIs (using a SPI example, but the open/close and finding controllers, as well as the typical structure of buffered I/O, should be applicable to I2C). The USB2ANY SDK found here includes an API manual for the DLL functions. I2C is conceptually more difficult than SPI because of the possibility of repeated start transactions, so the functions you probably want to look at are u2aI2C_Configure, u2aI2C_InternalRead and u2aI2C_InternalWrite.

    Other worthwhile things to note:

    • The API manual is not the version shipped with TICS Pro, but it's mostly the same API. We haven't made many significant changes, just included a couple more enums in SPI transactions to allow for 3-byte and 4-byte chip select toggles (enum values 6 and 5 respectively).
    • The HID packet overhead takes up 12 bytes out of every transaction. Raw read and write on I2C can write up to 48 bytes in the buffer at once. InternalWrite and InternalRead reserves two bytes for the address at the beginning, so the longest buffer you can write in one internal transaction is 46 bytes.
    • Because LMK3H0102 supports block reads and writes, you'll want to write or read as many data values at once as possible to minimize the HID latency overhead. It's a little non-trivial to write a function that takes the list of addresses to be written and the size of the data and maximum data buffers, and return the set of sizes that can be written to each buffer.

    ---

    Now, there's a separate issue: none of this uses TICS Pro at all.

    TICS Pro also wraps the USB2ANY DLL under the hood (in C#), and has an abstraction layer for registers and data over the inputs to the APIs to simplify communication. TICS Pro actually includes a separate socket server automation option with a client server pre-written in python for your usage, if you'd prefer to keep the application open and have the GUI available while automating - we tend to do this internally since it lets us check other states visually very quickly, and since some things take longer to automate than just clicking through a few times in the GUI. Take a look at C:\Program Files (x86)\Texas Instruments\TICS Pro\TICSProTCP.py for the client code - you can copy this file to your python path or your working directory and use it to work at the layer of field abstractions (one or more spans in the register map belonging to a specific function) rather than register or raw bytes levels.

  • I found  C:\Program Files (x86)\Texas Instruments\TICS Pro\TICSProTCP.py and used it.
    Not exactly what I wanted since I'm depended on TICS Pro installation, but it works.
    Thank you!