intrepidcs / python_ics

Library for interfacing with Intrepid devices in Python
MIT License
61 stars 29 forks source link

Windows fatal exception: access violation #118

Closed zhihongliuus closed 2 years ago

zhihongliuus commented 2 years ago

Device: ValueCAN 4x4 Issue happened when running: data = ics_msg.ExtraDataPtr[: ics_msg.NumberBytesData]

Full code:

import ics

def _ics_msg_to_message(ics_msg):
    is_fd = ics_msg.Protocol == ics.SPY_PROTOCOL_CANFD

    if is_fd:
        if ics_msg.ExtraDataPtrEnabled:
            data = ics_msg.ExtraDataPtr[: ics_msg.NumberBytesData]
        else:
            data = ics_msg.Data[: ics_msg.NumberBytesData]

        return ics_msg.ArbIDOrHeader, data

def get_serial_number(device):
    if int("AA0000", 36) < device.SerialNumber < int("ZZZZZZ", 36):
        return ics.base36enc(device.SerialNumber)
    else:
        return str(device.SerialNumber)

def get_device(serial):
    devices = ics.find_devices()
    for device in devices:
        if get_serial_number(device) == str(serial):
            return device

if __name__ == "__main__":
    dev = get_device('V46671')
    ics.open_device(dev)
    while True:
        messages, errors = ics.get_messages(dev)
        for msg in messages:
            if msg.ExtraDataPtrEnabled:
                print(hex(msg.ArbIDOrHeader), msg.NumberBytesData)
            print(_ics_msg_to_message(msg))

Result:

Windows fatal exception: access violation

Current thread 0x000049c8 (most recent call first): File "C:/debug.py", line 9 in _ics_msg_to_message

drebbe-intrepid commented 2 years ago

@zhihongliuus Please try the latest releases as there were some changes/fixes around the ExtraDataPtr recently. Please re-open this if this is still an issue.