Code Monkey home page Code Monkey logo

caroa04's Introduction

caroa04

image

Python versions

Documentation Status

See Build Status on GitHub Actions

Library to control the CAROA04 CAN-IO expander device from eletechsup.

Installation

You can install caroa04 via pip from PyPI:

$ pip install caroa04

Usage

You can instantiate a CaroA04 object and start it to communicate with the device as follows.

from caroa04 import CaroA04

caro = CaroA04()
caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS1')  # start communication with device node ID 0xE0

caro.do1.phys = True  # set do1 state to True
print(caro.do1.phys)  # read do1 state
print(caro.di1.phys)  # read di1 state

print(caro.bitrate.phys)  # read current bitrate
caro.bitrate.phys = 500000  # set different baudrate (will require device power cycle)

print(caro.node_id.phys)  # read current address code
caro.node_id.phys = 0xE1  # set address code (will require device power cycle)

caro.stop()  # free the bus

In order to share the bus with other participants, you can assign the bus attribute of the CaroA04 object before starting it. You should simply then add CaroA04's listener to the existing bus' notifier.

import canopen
from caroa04 import CaroA04

nw = canopen.Network()
nw.connect(interface='pcan', bitrate=250000, channel='PCAN_USBBUS1')


caro = CaroA04()
caro.bus = nw.bus  # use the bus already started by canopen
nw.notifier.add_listener(caro.listener)  # add listener so that we can receive messages

caro.start(0xE0)  # start communication with node ID 0xE0
caro.stop()  # free the bus

Features

  • This library uses the python-can library to communicate with the device. Please refer to its documentation to know about all the CAN interfaces that can be used with this library (https://python-can.readthedocs.io/en/stable/)
  • The device has 4 digital outputs and 4 digital inputs. Hence the signals can be read/written by using the attributes of the CaroA04 class:
    • do1, do2, do3, do4 : digital output 1 to digital output 4
    • di1, di2, di3, di4 : digital input 1 to digital input 4
    • bitrate, node_id : bitrate and address code of the device
  • Each signal has a raw value and a physical value. For example, the device does not understand a bitrate in bps. It expects an enumeration that it will interpret. So it can either be set by writing its physical value (bitrate.phys = 250000) or by writing its raw value (bitrate.raw) as follows:
    • 0: 5 kbps
    • 1: 10 kbps
    • 2: 20 kbps
    • 3: 50 kbps
    • 4: 100 kbps
    • 5: 120 kbps
    • 6: 200 kbps
    • 7: 250 kbps
    • 8: 400 kbps
    • 9: 500 kbps
    • 10: 800 kbps
    • 11: 1000 kbps

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

caroa04's People

Contributors

supermete avatar

Watchers

 avatar

caroa04's Issues

stop and shutdown method could be merged

  • caroa04 version: 0.1.2
  • Python version: 3.10
  • Operating System: Windows

Description

We must call stop and shutdown methods if we want to properly stop the communication.
Both methods could be merged for simplicity.

No communication when bus is set before starting

  • caroa04 version: 0.1.2
  • Python version: 3.10
  • Operating System: Windows

Description

When caroa04 is instantiated and a bus that is already instantiated is assigner to it before starting, no communication can be done with the device.

What I Did

Assign the bus to CAN messages when started with a not None bus.

caro = CaroA04()
caro. bus = can.bus(interface='pcan', bitrate=250000, channel='PCAN_USBBUS2')
caro.start(0xE0, 'pcan')
caro.do1.phys = True  # DO1 is not set in the device here
print(caro.do1.phys)  # DO1 reads True anyway
caro.do1.phys = False
caro.shutdown()

Convert logging info to debug

  • caroa04 version: 1.0.1
  • Python version: 3.10
  • Operating System: Windows

Description

Logging info is printed for DI and parameters writing/reading. Convert it to debug.

In start method, interface parameter should be optional

  • caroa04 version: 1.0.0
  • Python version: 3.10
  • Operating System: Windows

Description

In start method, bitrate and channel parameters are optional, while interface is not for some reason. When the bus is assigned before starting the communication, the interface parameter is not useful, it should be made optional.

When connecting to a device with outputs already set, the first message resets the initially set outputs

  • caroa04 version: 1.0.2
  • Python version: 3.10
  • Operating System: Windows 10

Description

CaroA04 powered-on, with one of the digital outputs already active.
I use the lib to connect to it, then try to set any other digital output to True (not the one already set).
This sets the requested output but reset the output that was already set.

What I Did

caro = CaroA04()
caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS2')
caro.do1.phys = True
caro.stop()

caro = CaroA04()
caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS2')
caro.do2.phys = True  # this will reset do1 to False
caro.stop()

Can't share the bus with other participants

  • caroa04 version: 0.1.2
  • Python version: 3.10
  • Operating System: Windows

Description

When bus created by instantiating caroa04 is used by another network, other bus participants cannot receive messages while caroa04 is waiting on a reply from the device.

What I Did

import canopen
from caroa04 import CaroA04
import threading
import time

# init caroa04 object and start the bus
caro = CaroA04()
caro.start(0xE0, 'pcan', 250000, 'PCAN_USBBUS2')

# init another participant for the same bus
co_nw = canopen.Network()
node = co_nw.add_node(1, r"path/to/my.eds")
co_nw.bus = caro.bus

# use a thread to sollicitate the bus parallelly to caroa04
thread = threading.Thread(target=run_sdo, kwargs={'node': node})
thread.start()

# use the bus to communicate with the device at the same time than the canopen device
start = time.time()
while time.time() - start < 10:
  caro.do1.phys = True  # at this point we should see warnings/errors (no SDO response) caused by caroa04 waiting on replies from the device without notifying the other listeners
  time.sleep(0.3)
  print(caro.do1.phys)
  time.sleep(0.3)
  caro.do1.phys = False
  time.sleep(0.3)

thread.join()
caro.shutdown()

def run_sdo(**kwargs ):
  node = kwargs['node']
  start = time.time()
  while time.time() - start < 10:
    print(node.sdo[0x1008].raw)
    time.sleep(0.5)

    

Mistake in README

  • caroa04 version: 1.0.0
  • Python version: 3.10
  • Operating System: Windows

Description

In the code snippet from README.rst and README.md, the CaroA04 object is stopped using the shutdown method which was removed in latest release.

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.