1
0
Fork 0

Add Python example for cocomm

This commit is contained in:
Janez 2023-03-18 17:59:34 +01:00
parent bf94f78ce2
commit a4a0172b31
2 changed files with 22 additions and 2 deletions

4
.github/FUNDING.yml vendored
View file

@ -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']

View file

@ -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
--------------------