{"id":21116636,"url":"https://github.com/canopennode/canopenlinux","last_synced_at":"2025-04-04T19:12:07.232Z","repository":{"id":38740903,"uuid":"364541281","full_name":"CANopenNode/CANopenLinux","owner":"CANopenNode","description":" CANopenNode on Linux devices","archived":false,"fork":false,"pushed_at":"2025-03-01T17:29:44.000Z","size":71,"stargazers_count":127,"open_issues_count":12,"forks_count":56,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T18:14:53.166Z","etag":null,"topics":["canopen","canopennode","commander","embedded","gateway","linux","realtime"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CANopenNode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["paypal.me/jnz022"]}},"created_at":"2021-05-05T10:35:54.000Z","updated_at":"2025-03-22T14:51:07.000Z","dependencies_parsed_at":"2024-10-27T18:13:48.183Z","dependency_job_id":"0714181f-b4e2-4675-8b53-8a91238baa48","html_url":"https://github.com/CANopenNode/CANopenLinux","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CANopenNode%2FCANopenLinux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CANopenNode%2FCANopenLinux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CANopenNode%2FCANopenLinux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CANopenNode%2FCANopenLinux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CANopenNode","download_url":"https://codeload.github.com/CANopenNode/CANopenLinux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234923,"owners_count":20905854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["canopen","canopennode","commander","embedded","gateway","linux","realtime"],"created_at":"2024-11-20T02:32:03.680Z","updated_at":"2025-04-04T19:12:07.214Z","avatar_url":"https://github.com/CANopenNode.png","language":"C","funding_links":["paypal.me/jnz022"],"categories":[],"sub_categories":[],"readme":"CANopenLinux                                               {#readmeCANopenLinux}\n============\n\nCANopenLinux is a CANopen stack running on Linux devices.\n\nIt is based on [CANopenNode](https://github.com/CANopenNode/CANopenNode), which is free and open source CANopen Stack and is included as a git submodule.\n\nCANopen is the internationally standardized (EN 50325-4) ([CiA301](http://can-cia.org/standardization/technical-documents)) CAN-based higher-layer protocol for embedded control system. For more information on CANopen see http://www.can-cia.org/.\n\nCANopenLinux homepage is https://github.com/CANopenNode/CANopenLinux\n\n\nGetting or updating the project\n-------------------------------\nClone the project from git repository and get submodules:\n\n    git clone https://github.com/CANopenNode/CANopenLinux.git\n    cd CANopenLinux\n    git submodule init\n    git submodule update\n\nUpdate the project:\n\n    cd CANopenLinux\n    git pull # or: git fetch; inspect the changes (gitk); git merge\n    git submodule update\n\n\nUsage\n-----\nSupport for CAN interface is part of the Linux kernel, so called [SocketCAN](https://en.wikipedia.org/wiki/SocketCAN). CANopenNode runs on top of SocketCAN, so it should be able to run on any Linux machine, it depends on configuration of the kernel. Examples below was tested on Debian based machines, including Ubuntu and Raspberry PI. It is possible to run tests described below without real CAN interface, because Linux kernel already contains virtual CAN interface.\n\nWindows or Mac users, who don't have Linux installed, can use [VirtualBox](https://www.virtualbox.org/) and install [Ubuntu](https://ubuntu.com/download/desktop) or similar. To get confortable you may like to enroll [Introduction to Linux](https://training.linuxfoundation.org/training/introduction-to-linux/).\n\n\n### CAN interfaces\n#### Virtual CAN interface\nIt can connect multiple programs inside Linux machine. It can be activated by the following commands:\n\n    sudo modprobe vcan\n    sudo ip link add dev can0 type vcan\n    sudo ip link set up can0\n\n#### USB, PCI or similar CAN interface\nThere are several CAN interfaces on the market which works with Linux SocketCAN. See [Linux kernel source](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/net/can), Kconfig files, for supported interfaces by the Linux kernel. For example [EMS CPC-USB](https://www.ems-wuensche.com/?post_type=product\u0026p=746) or [PCAN-USB FD](http://www.peak-system.com/PCAN-USB-FD.365.0.html?\u0026L=1). Usually such interface is started with:\n\n    sudo ip link set up can0 type can bitrate 250000\n\n#### Serial slcan interface\nMost cheap CAN interface, for example [USBtin](http://www.fischl.de/usbtin/). It may not be fast enough and may lose messages. Usually it is started with (-s5=250kbps):\n\n    sudo slcand -f -o -c -s5 /dev/ttyACM0 can0\n    sudo ip link set up can0\n\n#### CAN capes for Raspberry PI or similar\nRPI may work wit some of the USB CAN interfaces or with CAN shield like [this](https://www.sg-electronic-systems.com/ecommerce/12-can-bus-shield). CAN shield may not be fast enough and may lose messages.\n\n\n### CAN utilities\n[SocketCAN userspace utilities and tools](https://github.com/linux-can/can-utils) contains several useful command line tools for CAN in Linux. Install with:\n\n    sudo apt-get install can-utils\n\nIn own terminal run candump to display all CAN messages with timestamp:\n\n    candump -td -a can0\n\n\n### Running CANopenLinux device\nCompile:\n\n    cd CANopenLinux\n    make\n\nInstall (copy `canopend` application to the `/usr/bin/` directory):\n\n    sudo make install\n\nDisplay options:\n\n    canopend --help\n\nRun on can0 device with CANopen NodeID = 4:\n\n    canopend can0 -i 4\n\nIf NodeID is not specified, then CANopen LSS protocol may be used. Program can be finished by pressing Ctrl+c or with CANopen reset node command.\n\nAfter connecting the CANopen Linux device into the CAN(open) network, bootup message is visible. By default device uses Object Dictionary from `CANopenNode/example`, which contains only communication parameters. With the external CANopen tool all parameters can be accessed and CANopen Linux device can be configured (For example write heartbeat producer time in object 0x1017,0).\n\nWhen CANopen Linux device is first connected to the CANopen network it shows bootup message and emergency message, because of missing storage files. To avoid emergency message it is necessary to trigger saveAll command (write correct code into parameter 0x1010,1 with SDO command) and restart the program.\n\nNote also, if there are multiple instances of canopend running from the same directory, storage path should be specified for each.\n\n\n### CANopen ASCII command interface\nCANopenNode includes CANopen ASCII command interface (gateway) specified by standard CiA309-3. It can be used as a commander for other CANopen devices: NMT master, LSS master, SDO client, etc. In CANopen Linux device command interface is available by default.\n\nTo use ASCII command interface on canopend directly just run it with `-c \"stdio\"` and type the commands followed by enter in it.\n\n    canopend can0 -i 1 -c \"stdio\"\n    help\n    1 write 0x1010 1 vs save\n    1 reset node\n\nTo create CANopen Linux commander device on local socket run:\n\n    canopend can0 -i 1 -c \"local-/tmp/CO_command_socket\"\n\n#### cocomm\nCANopenLinux/cocomm directory contains a small command line program, which establishes socket connection with `canopend` (CANopen Linux commander device). It sends standardized CANopen commands (CiA309-3) to gateway and prints the responses to stdout and stderr. See [cocomm/README.md](cocomm/README.md) for usage.\n\n#### Accessing ASCII command interface with Python\nHere is an example of simplified Python program, which works similar as `cocomm` described above (`canoped` serves on local socket). Run the program and type `1 r 0x1018 0 u16` for example.\n\n```python\nimport socket, os\n\nif os.path.exists(\"/tmp/CO_command_socket\"):\n    client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n    client.connect(\"/tmp/CO_command_socket\")\n    while True:\n        x = \"[1] \" + input(\"\u003e \") + \"\\r\\n\"\n        if \"\" != x:\n            print(\"SEND:\", x.encode(\"utf-8\"))\n            client.send(x.encode(\"utf-8\"))\n            print(\"RECEIVE:\", client.recv(1024))\n    client.close()\nelse:\n    print(\"Couldn't Connect!\")\n```\n\n\nCreating new project\n--------------------\n`canopend` is a basic CANopen Linux device with optional commander functionalities. However, CANopen device is able to be much more, like (simple) input/output (digital or analog) device according to standard CiA401 or anything else as specified by other CANopen device profiles or own idea.\n\nNew project can be started in new directory simply by adding customized makefile, custom Object Dictionary OD.h/c files and custom application source files in Arduino style, which are called from CO_main_basic.c file.\n\n### Single or multi threaded application\nBy default canopend runs in single thread (CO_SINGLE_THREAD option in Makefile). Different events, such as can reception or timer expiration trigger looping through the stack (all code is non-blocking). It requires less system resources.\n\nIn multi threaded operation a real-time thread is established besides mainline thread. RT thread runs each millisecond and processes PDOs and optional application code with peripheral read/write, control program or similar. With this configuration race conditions must be taken into account, for example application code running from mainline thread must use CO_(UN)LOCK_OD macros when accessing OD variables.\n\nSee also [CANopenDemo](https://github.com/CANopenNode/CANopenDemo) for examples.\n\n\n### Create new project with KDevelop\n- https://www.kdevelop.org/\n- `sudo apt install kdevelop breeze`\n- Run KDevelop, select: Project -\u003e open project\n- Navigate to project directory and click open.\n- KDevelop will recognize `Makefile` and will just use it. Click Finish.\n- Open project settings (right click on project on left panel)\n  - Make: set to 1 thread operation.\n  - Language support, Includes, add paths to directories:\n    - `\u003cpath_to_CANopenLinux_driver_files\u003e`\n    - `\u003cpath_to_CANopenNode\u003e`\n    - `\u003cpath_to_project_files\u003e`\n  - Language support, Defines, add:\n    - `CO_DRIVER_CUSTOM`\n- Run -\u003e Setup launches -\u003e `our_program`:\n  - Add Executable file and name it.\n  - Executable file: `\u003cselect_executable\u003e`\n  - Arguments: `can0 -i 4`\n- Build, then Execute or Debug\n\n\nChange Log\n----------\n- **[v4.0](https://github.com/CANopenNode/CANopenLinux/tree/HEAD) - current**: Git repository started on GitHub.\n  - Linux driver files copied from https://github.com/CANopenNode/CANopenNode/tree/76b43c88ef6d5490cb2f1518e10646e8dcb45c76/socketCAN\n  - cocomm copied from https://github.com/CANopenNode/CANopenSocket/tree/71f21e41fd4527718d8b6161938b479386d2d03b/cocomm\n  - Submodule CANopenNode added.\n  - Few adjustments and documentation written.\n\n\nLicense\n-------\nThis file is part of CANopenNode, an opensource CANopen Stack.\nProject home page is \u003chttps://github.com/CANopenNode/CANopenNode\u003e.\nFor more information on CANopen see \u003chttp://www.can-cia.org/\u003e.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanopennode%2Fcanopenlinux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanopennode%2Fcanopenlinux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanopennode%2Fcanopenlinux/lists"}