From a4a0172b31bf4b4ba05fcbd951dd515ec4d0cb3f Mon Sep 17 00:00:00 2001 From: Janez Date: Sat, 18 Mar 2023 17:59:34 +0100 Subject: [PATCH] Add Python example for cocomm --- .github/FUNDING.yml | 4 ++-- README.md | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 4661580..437d8e6 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -6,7 +6,7 @@ open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: CANopenNode +liberapay: # CANopenNode issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] +custom: ['paypal.me/jnz022'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/README.md b/README.md index ae15c23..94dc990 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,26 @@ To create CANopen Linux commander device on local socket run: #### cocomm CANopenLinux/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. +#### Accessing ASCII command interface with Python +Here 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. + +```python +import socket, os + +if os.path.exists("/tmp/CO_command_socket"): + client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + client.connect("/tmp/CO_command_socket") + while True: + x = "[1] " + input("> ") + "\r\n" + if "" != x: + print("SEND:", x.encode("utf-8")) + client.send(x.encode("utf-8")) + print("RECEIVE:", client.recv(1024)) + client.close() +else: + print("Couldn't Connect!") +``` + Creating new project --------------------