Skip to content

Commit

Permalink
script for reading bunch of data objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kivel committed Oct 12, 2023
1 parent ce959a1 commit 08e23eb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/python/EL5032.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
0x9008:
- 0x01: { type: uint8, desc: Encoder type }
- 0x03: { type: uint8, desc: Reference system }
- 0x11: { type: string, desc: Encoder designation }
- 0x12: { type: string, desc: Encoder ident number }
- 0x13: { type: string, desc: Encoder serial number }
- 0x14: { type: uint32, desc: Multiturn resolution }
- 0x15: { type: uint32, desc: Singleturn resolution }
- 0x16: { type: uint32, desc: Measuring step }
- 0x21: { type: bool, desc: Light source error supported }
- 0x22: { type: bool, desc: Signal amplitude error supported }
- 0x23: { type: bool, desc: Position error supported }
- 0x24: { type: bool, desc: Overvoltage error supported }
- 0x25: { type: bool, desc: Undervoltage error supported }
- 0x26: { type: bool, desc: Overcurrent error supported }
- 0x27: { type: bool, desc: Battery error supported }
- 0x31: { type: bool, desc: Frequency warning supported }
- 0x32: { type: bool, desc: Temperature warning supported }
- 0x33: { type: bool, desc: Light source warning supported }
- 0x34: { type: bool, desc: Battery warning supported }
- 0x35: { type: bool, desc: Reference Mark warning supported }
- 0x36: { type: bool, desc: Acyclic mode warning supported }
- 0x37: { type: bool, desc: Limit position warning supported }
- 0x38: { type: bool, desc: Not ready warning supported }
- 0x39: { type: bool, desc: Diagnostic warning supported }
- 0x43: { type: bool, desc: Temperature 1 (external) supported }
- 0x44: { type: bool, desc: Temperature 2 (internal) supported }
- 0x51: { type: bool, desc: Clock pulse periods }
60 changes: 60 additions & 0 deletions scripts/python/readElectronicNamePlate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#! /usr/bin/env python

import argparse
import yaml
import json
import toml

import subprocess

def process_index(index, subindeces, master=0, slave=0) -> list:
root_cmd = f'ethercat -m{master} -p{slave} upload {index:#x}'
results = []
for subindexDict in subindeces:
for subindex, value in subindexDict.items():
data_type = value.get('type')
description = f'{subindex:#04x}: {value.get("desc", "")}'
cmd = f'{root_cmd} {subindex:#x} -t{data_type}'
result = subprocess.run(cmd.split(), stdout=subprocess.PIPE, text=True)
results.append(f'{description} = {result.stdout}')
return results

# Create the parser
parser = argparse.ArgumentParser(description='Read a dictionary from a file.')

# Add arguments
parser.add_argument('-y', '--yaml', type=str, help='YAML file to read')
parser.add_argument('-j', '--json', type=str, help='JSON file to read')
parser.add_argument('-t', '--toml', type=str, help='TOML file to read')
parser.add_argument('-m', '--master', type=int, default=0)
parser.add_argument('-p', '--position', type=int, default=1)

# Parse the arguments
args = parser.parse_args()

# Function to read and process the data
def read_and_process(file_path):
with open(file_path, 'r') as file:
if file_path.endswith('.yaml'):
data = yaml.safe_load(file)
elif file_path.endswith('.json'):
data = json.load(file)
elif file_path.endswith('.toml'):
data = toml.load(file)
else:
raise ValueError('Unsupported file type')

for index, subindeces in data.items():
print(f'INDEX ==== {index:#x} ====')
for response in process_index(index, subindeces, args.master, args.position):
print(response.strip())

# Call the function with the respective file path
if args.yaml:
read_and_process(args.yaml)
elif args.json:
read_and_process(args.json)
elif args.toml:
read_and_process(args.toml)
else:
parser.print_help()

0 comments on commit 08e23eb

Please sign in to comment.