Python Forum
Erreur Code access violation reading 0x00000004 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Erreur Code access violation reading 0x00000004 (/thread-28233.html)



Erreur Code access violation reading 0x00000004 - yan_mhb - Jul-10-2020

Hello,

I code on the idle python version 3.8.3 and I receive this error message "OSError: exception: access violation reading 0x00000004" Angry Angry Angry that does not manage to resolve I went through all the functions in the imported library and I find not "canopenchannel" I think it is hidden and I do not have access
for information I use windows 7 professional.


from canlib import canlib, Frame
from canlib.canlib import ChannelData


def setUpChannel(channel=0,
                 openFlags=canlib.canOPEN_ACCEPT_VIRTUAL,
                 bitrate=canlib.canBITRATE_500K,
                 bitrateFlags=canlib.canDRIVER_NORMAL):
    ch = canlib.openChannel(channel, openFlags)
    print("Using channel: %s, EAN: %s" % (ChannelData(channel).device_name,
                                          ChannelData(channel).card_upc_no)
                                              )
    ch.setBusOutputControl(bitrateFlags)
    ch.setBusParams(bitrate)
    ch.busOn()
    return ch


def tearDownChannel(ch):
    ch.busOff()
    ch.close()


print("canlib version:", canlib.dllversion())

ch0 = setUpChannel(channel=0)
ch1 = setUpChannel(channel=1)

frame = Frame(id_=100, data=[1, 2, 3, 4], flags=canlib.canMSG_EXT)
ch1.write(frame)

while True:
    try:
        frame = ch0.read()
        print(frame)
        break
    except (canlib.canNoMsg) as ex:
        pass
    except (canlib.canError) as ex:
        print(ex)

tearDownChannel(ch0)
tearDownChannel(ch1)
error:

Traceback (most recent call last):
File "D:\Esss.py", line 25, in <module>
ch0 = setUpChannel(0)
File "D:\Esss.py", line 8, in setUpChannel
ch = canlib.openChannel(0,openFlags)
File "D:\Softs\lib\site-packages\canlib\canlib\channel.py", line 58, in openChannel
ch = Channel(channel, flags)
File "D:\Softs\lib\site-packages\canlib\canlib\channel.py", line 120, in __init__
self.handle = dll.canOpenChannel(channel_number, flags)
OSError: exception: access violation reading 0x00000004
>>>