Code Monkey home page Code Monkey logo

python-can-sontheim's Introduction

python-can-sontheim

Latest Version on PyPi Supported Python implementations coverage Downloads on PePy

This module is a plugin for the python-can. module, that allows the use of CAN interfaces that rely on the Sontheim Industrie Elektronik (SIE) MTAPI drivers (windows only). These include the SIE CANfox (including rebranded versions such as that by IFM), SIE CANUSB, etc.

Installation

Install using pip:

$ pip install python-can-sontheim

Usage

In general, useage is largely the same as with the main python-can library, using the interface designation of "sontheim". When integrating the sontheim interface into scripts, it is possible to import constants, device deisgnations etc from the python-can-sontheim module using "import can_sontheim". For the majority of the use cases, using an SIE interface is as simple as amending any python-can examples with the lines shown below:

Create python-can bus with the SIE CANfox USB interface:

import can
from can_sontheim import devices

bus = can.Bus(interface="sontheim", channel=devices.CANfox.CAN1, bitrate=250000, echo=False)

Some examples are present in the python-can-sontheim/examples directory in the repository, and more complete documentation specific to the SIE interfaces and driver will be uploaded to this module in due course.

python-can-sontheim's People

Contributors

mattwoodhead avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

seipv

python-can-sontheim's Issues

module raises an exception when using detect_available_configs

Describe the bug
The can_sontheim module prevents the can.detect_available_configs function from the python-can library from working as it raises an exception

To Reproduce

  • install python-can-sontheim module
  • Run can.detect_available_configs()

Expected behavior
The sontehim bus should either be reported as available opr unavailable

Screenshots, Traceback, MRE

Cannot load SIE MT_API for Sontheim: The Sontheim API is currently only compatible with the 32 bit python interpreter
Traceback (most recent call last):

  File "C:\Python\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "c:\users\matth\documents\github\python-can-bluetooth\examples\bluetooth_tx_example.py", line 18, in <module>
    print(can.detect_available_configs())

  File "C:\Users\matth\AppData\Roaming\Python\Python39\site-packages\can\interface.py", line 176, in detect_available_configs
    bus_class._detect_available_configs()  # pylint: disable=protected-access

  File "c:\users\matth\documents\github\python-can-sontheim\can_sontheim\_canlib.py", line 406, in _detect_available_configs
    error_code = _CANLIB.canGetDeviceList(byref(devices_struct))

AttributeError: 'NoneType' object has no attribute 'canGetDeviceList'

Desktop (please complete the following information):

  • OS: Windows 10 64 bit
  • SIE Adapter: CANfox

Additional context
N/A

64 bit wrapper

Is your feature request related to a problem? Please describe.
The module currently relies upon a 32 bit DLL libray, meaning that a 64 bit installation of python cannot use the driver.

Describe the solution you'd like
Investigate some sort of wrapper that may allow the use of a 64 bit python installation to access the hardware drivers (e.g. MSL-LoadLib)

Describe alternatives you've considered
Keep library 32 bit only

Additional context
N/A

Cannot send non-extended IDs

All Can Sends have the Extended ID set to True even when the message has is_extended_id=False

Copied a local instant of can-sontheim/_canlib.py and edited some lines to correct

    def send(self, msg, timeout=None):

        assert msg.dlc <= 8

        msg_struct = CANMsgStruct()

        # configure the message. ID, Data length, ID type, message type
        msg_struct.l_id = c_long(msg.arbitration_id)
        msg_struct.by_len = msg.dlc
        if msg.is_extended_id:
            msg_struct.by_extended = c_ubyte(1)  # 00000001   Corrected to 1, was 2.
        else:
            msg_struct.by_extended = c_ubyte(0)  # 00000000   Corrected to 0, was 1. 
        if msg.is_remote_frame:
            msg_struct.by_remote = c_ubyte(1)  # 00000001
        else:
            msg_struct.by_remote = c_ubyte(0)  # 00000000

This correction enable non-extended id sends. Also tested extended_id and seems to work (traces in IFM Maintenance Tool confirms).

Will be using a local copy for my projects for the moment.

Thank you.

PyInstaller convert to Exe issue. Unknown interface type "canfox" or "sontheim"

Describe the bug
I have an application that runs fine in Python, but fails when passed through PyInstaller
Has anyone managed to get their application running through PyInstaller (one file or one directory)?

Could there be a problem in the package definition that PyInstaller does not link it correctly.
I'm trying to find information here before checking with PyInstaller for more troubleshooting.

Errors in console :
Error initializing CAN Bus : Unknown interface type "canfox"
Also tried interface="sontheim"
Both interface settings runs fine with Python, but fails when converted to an Executable.

Desktop (please complete the following information):

  • OS: Windows 10 64 bits
  • SIE Adapter: ifm EC21112 with ifm driver installed in Windows
  • Python 3.12.2 32 bits, also tried 3.11.8 - 32 bits
  • Visual Studio Code for IDE
  • running with a venv on the project
  • PyQt5, python-can, python-can-sontheim, pyinstaller
    

Additional context
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.