-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
77 lines (57 loc) · 1.79 KB
/
example.py
File metadata and controls
77 lines (57 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import swtools
import yos_device
import sys
from swtools import swtools_connection_options as conn
DEVICE_ADDRESS = 0
MSGCONF_STRING = "3:4" # CAN speed 500 kbps
swt = swtools.swtools(
conn=conn(
interface="usb",
addr=DEVICE_ADDRESS,
msgconf_str=MSGCONF_STRING,
credentials="",
)
)
device = yos_device.yos_device(swt)
def example():
print("SN: " + device.get_sn())
print("HWID: " + device.get_hwid())
print("SWID: " + device.get_swid())
print("CAN settings: " + device.get_msgconf(3))
print("Controller temperature: " + str(device.get_var("/driver/temp")))
print("Execute YOS command:")
ret = swt.yosctl_cmd_exec(["echo", "Hello", "world!"])
print(ret.stdout)
print("Result of command: " + str(ret.returncode))
print("Restore default config:")
device.restore()
print("Push config:")
swt.yosctl_push(file="config.yc")
print("Run YOS script:")
ret = swt.script_std("esc3-selftest.ys")
print()
print("Script return code: " + str(ret))
print("Example started")
# Check if device is connected and do interface clain
if device.is_NOT_on(fast=True):
print("Device is not connected")
sys.exit(1)
# Login to device
print("Logging in")
# swt.conn.set_if("usb") # USB interface is already set from the beginning
if device.login():
print("Logging in failed")
sys.exit(1)
example()
print()
print("Changing interface to kvaser and do the same over again")
print("=======================================================")
swt.conn.set_if("kvaser")
# # After you change interface, it is necesary run "yosctl id claim".
# This is done inside function "is_NOT_on"
if device.is_NOT_on(fast=True):
print("Unable to connect using kvaser")
sys.exit(1)
example()
print("Example finished")
sys.exit(0)