CK-InoDrive-API 0.2.8b0__tar.gz → 0.2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CK-InoDrive-API-0.2.9/CK_InoDrive_API.egg-info/PKG-INFO +129 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/SOURCES.txt +4 -0
- CK-InoDrive-API-0.2.9/CK_InoDrive_API.egg-info/requires.txt +3 -0
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/IO.py +333 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/defines.py +65 -1
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/discoverLan.py +13 -25
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/discoverWs.py +17 -29
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/file.py +37 -31
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/inoDrive.py +56 -0
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/sysControl.py +101 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/userApp.py +238 -223
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/utils.py +97 -121
- CK-InoDrive-API-0.2.9/CkInoDriveAPI/wsHandle.py +498 -0
- CK-InoDrive-API-0.2.9/LICENSE.txt +7 -0
- CK-InoDrive-API-0.2.9/PKG-INFO +129 -0
- CK-InoDrive-API-0.2.9/README.txt +1978 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/setup.py +13 -9
- CK-InoDrive-API-0.2.8b0/CK_InoDrive_API.egg-info/PKG-INFO +0 -99
- CK-InoDrive-API-0.2.8b0/CK_InoDrive_API.egg-info/requires.txt +0 -3
- CK-InoDrive-API-0.2.8b0/CkInoDriveAPI/inoDrive.py +0 -309
- CK-InoDrive-API-0.2.8b0/CkInoDriveAPI/wsHandle.py +0 -359
- CK-InoDrive-API-0.2.8b0/PKG-INFO +0 -99
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/dependency_links.txt +0 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CK_InoDrive_API.egg-info/top_level.txt +0 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/CkInoDriveAPI/__init__.py +0 -0
- {CK-InoDrive-API-0.2.8b0 → CK-InoDrive-API-0.2.9}/setup.cfg +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: CK-InoDrive-API
|
|
3
|
+
Version: 0.2.9
|
|
4
|
+
Summary: InoDrive API Library
|
|
5
|
+
Home-page: https://cardinalkinetic.com
|
|
6
|
+
Author: Cardinal Kinetic
|
|
7
|
+
Author-email: support@cardinalkinetic.com
|
|
8
|
+
License: https://www.cardinalkinetic.com/user-manual/api/inodrive-py
|
|
9
|
+
Project-URL: Documentation, https://www.cardinalkinetic.com/user-manual/api/inodrive-py
|
|
10
|
+
Keywords: InoWorx InoDrive InoSync MotionControl ServoControl
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.txt
|
|
20
|
+
License-File: README.txt
|
|
21
|
+
Requires-Dist: websocket-client==1.6.4
|
|
22
|
+
Requires-Dist: ifaddr==0.2.0
|
|
23
|
+
Requires-Dist: msgpack==1.0.7
|
|
24
|
+
|
|
25
|
+
#### **Installation**
|
|
26
|
+
|
|
27
|
+
Install and Update package via [pip](https://pip.pypa.io/en/stable/getting-started/)
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
pip install CK-InoDrive-API
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### **Usage**
|
|
34
|
+
|
|
35
|
+
Importing Library
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
# Import InoDrive API library
|
|
39
|
+
import CkInoDriveAPI
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Create InoDrive Object using WebSocket
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
# Create instance to InoDrive module object
|
|
46
|
+
# Connect by Name
|
|
47
|
+
Drive = CkInoDriveAPI.InoDrive(target='Name')
|
|
48
|
+
|
|
49
|
+
# Connect by Serial Number
|
|
50
|
+
Drive = CkInoDriveAPI.InoDrive(target='SN')
|
|
51
|
+
|
|
52
|
+
# Connect by IP Address
|
|
53
|
+
Drive = CkInoDriveAPI.InoDrive(target='IPv4 Address')
|
|
54
|
+
|
|
55
|
+
# Auto connect
|
|
56
|
+
Drive = CkInoDriveAPI.InoDrive(target='IPv4 Address', autoConnect=True)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Read and Write Variable's
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
# Connect to the drive
|
|
63
|
+
Drive.connect()
|
|
64
|
+
|
|
65
|
+
# Read variable with name 'VariableName'
|
|
66
|
+
Drive.UserApp.read_var('VariableName')
|
|
67
|
+
|
|
68
|
+
# Write variable with name 'VariableName' and value equal to 1
|
|
69
|
+
Drive.UserApp.write_var('VariableName', 1)
|
|
70
|
+
|
|
71
|
+
# Disconnect from the drive
|
|
72
|
+
Drive.disconnect()
|
|
73
|
+
|
|
74
|
+
# Drive object cleanup
|
|
75
|
+
Drive.dispose()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Get and Set Output's
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# Connect to the drive
|
|
82
|
+
Drive.connect()
|
|
83
|
+
|
|
84
|
+
# Read Output 2
|
|
85
|
+
state = Drive.IO.get_output(2)
|
|
86
|
+
|
|
87
|
+
# Take control of InoDrive module to override output state
|
|
88
|
+
Drive.SysControl.take_control(True)
|
|
89
|
+
|
|
90
|
+
# Set Output 2 to On state
|
|
91
|
+
Drive.IO.set_output(2, True)
|
|
92
|
+
state = Drive.IO.get_output(2)
|
|
93
|
+
|
|
94
|
+
# Disable module override
|
|
95
|
+
Drive.SysControl.take_control(False)
|
|
96
|
+
|
|
97
|
+
# Disconnect from the drive
|
|
98
|
+
Drive.disconnect()
|
|
99
|
+
|
|
100
|
+
# Drive object cleanup
|
|
101
|
+
Drive.dispose()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Change Module Name (Power cycle InoDrive for changes to take effect)
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# Connect to the drive
|
|
108
|
+
Drive.connect()
|
|
109
|
+
|
|
110
|
+
# Read module configuration file
|
|
111
|
+
config_file = Drive.File.read_module_config()
|
|
112
|
+
|
|
113
|
+
# Set new module name
|
|
114
|
+
config_file['name'] = "NewName"
|
|
115
|
+
|
|
116
|
+
# Write configuration changes out
|
|
117
|
+
Drive.File.write_module_config(config_file)
|
|
118
|
+
|
|
119
|
+
# Disconnect from the drive
|
|
120
|
+
Drive.disconnect()
|
|
121
|
+
|
|
122
|
+
# Drive object cleanup
|
|
123
|
+
Drive.dispose()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### **Links**
|
|
127
|
+
|
|
128
|
+
- [API Documentation](https://www.cardinalkinetic.com/user-manual/api/inodrive-py)
|
|
129
|
+
- [Company Website](https://www.cardinalkinetic.com)
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.txt
|
|
1
3
|
setup.py
|
|
2
4
|
CK_InoDrive_API.egg-info/PKG-INFO
|
|
3
5
|
CK_InoDrive_API.egg-info/SOURCES.txt
|
|
4
6
|
CK_InoDrive_API.egg-info/dependency_links.txt
|
|
5
7
|
CK_InoDrive_API.egg-info/requires.txt
|
|
6
8
|
CK_InoDrive_API.egg-info/top_level.txt
|
|
9
|
+
CkInoDriveAPI/IO.py
|
|
7
10
|
CkInoDriveAPI/__init__.py
|
|
8
11
|
CkInoDriveAPI/defines.py
|
|
9
12
|
CkInoDriveAPI/discoverLan.py
|
|
10
13
|
CkInoDriveAPI/discoverWs.py
|
|
11
14
|
CkInoDriveAPI/file.py
|
|
12
15
|
CkInoDriveAPI/inoDrive.py
|
|
16
|
+
CkInoDriveAPI/sysControl.py
|
|
13
17
|
CkInoDriveAPI/userApp.py
|
|
14
18
|
CkInoDriveAPI/utils.py
|
|
15
19
|
CkInoDriveAPI/wsHandle.py
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from .wsHandle import InoDriveWS
|
|
4
|
+
from .defines import CK
|
|
5
|
+
from .defines import OP_STATE
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class IO(object):
|
|
9
|
+
def __init__(self, **kwargs):
|
|
10
|
+
self._connection_handle: InoDriveWS = kwargs.get('connection_handle')
|
|
11
|
+
|
|
12
|
+
def dispose(self):
|
|
13
|
+
return
|
|
14
|
+
|
|
15
|
+
def get_metrics(self):
|
|
16
|
+
try:
|
|
17
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_METRICS])
|
|
18
|
+
|
|
19
|
+
if response.get('error'):
|
|
20
|
+
return {'success': False, 'Error': f'InoDrive GetMetrics Error: {str(response.get("error"))}'}
|
|
21
|
+
|
|
22
|
+
data = response['data'][0]
|
|
23
|
+
|
|
24
|
+
# Operational State
|
|
25
|
+
if data.get('state'):
|
|
26
|
+
for key, value in data['state'].items():
|
|
27
|
+
data['state'][key] = OP_STATE.get_state_by_value(value)
|
|
28
|
+
|
|
29
|
+
# Ethernet Ports
|
|
30
|
+
ports = {}
|
|
31
|
+
for port in data['eth_ports']:
|
|
32
|
+
ports.update({
|
|
33
|
+
port['name']: {
|
|
34
|
+
'link': port['link'],
|
|
35
|
+
'errors': port['errors'],
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
data['eth_ports'] = ports
|
|
39
|
+
|
|
40
|
+
data.update({'success': True})
|
|
41
|
+
|
|
42
|
+
return data
|
|
43
|
+
except Exception as ex:
|
|
44
|
+
return {'success': False, 'error': str(ex)}
|
|
45
|
+
|
|
46
|
+
def get_temperatures(self):
|
|
47
|
+
try:
|
|
48
|
+
data = self.get_metrics()
|
|
49
|
+
if data.get('error'):
|
|
50
|
+
logging.error(data['error'])
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
'case': data['temperatures']['case'],
|
|
55
|
+
'cpu': data['temperatures']['cpu'],
|
|
56
|
+
'fets': data['temperatures']['fets'],
|
|
57
|
+
'outputs': data['temperatures']['outputs'],
|
|
58
|
+
'regen': data['temperatures']['regen']
|
|
59
|
+
}
|
|
60
|
+
except Exception as ex:
|
|
61
|
+
logging.exception(ex)
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def get_input_voltage(self):
|
|
65
|
+
try:
|
|
66
|
+
data = self.get_metrics()
|
|
67
|
+
if data.get('error'):
|
|
68
|
+
logging.error(data['error'])
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
return data['v_in']
|
|
72
|
+
except Exception as ex:
|
|
73
|
+
logging.exception(ex)
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
def get_operational_state(self):
|
|
77
|
+
try:
|
|
78
|
+
data = self.get_metrics()
|
|
79
|
+
if data.get('error'):
|
|
80
|
+
logging.error(data['error'])
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
return data['state']
|
|
84
|
+
except Exception as ex:
|
|
85
|
+
logging.exception(ex)
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
def get_ethernet_ports(self):
|
|
89
|
+
try:
|
|
90
|
+
data = self.get_metrics()
|
|
91
|
+
if data.get('error'):
|
|
92
|
+
logging.error(data['error'])
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
return data['eth_ports']
|
|
96
|
+
except Exception as ex:
|
|
97
|
+
logging.exception(ex)
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
def get_inputs_data(self):
|
|
101
|
+
try:
|
|
102
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_INPUTS])
|
|
103
|
+
|
|
104
|
+
if response.get('error'):
|
|
105
|
+
return {'success': False, 'Error': f'InoDrive GetInputData Error: {str(response.get("error"))}'}
|
|
106
|
+
|
|
107
|
+
data = response['data'][0]
|
|
108
|
+
data.update({'success': True})
|
|
109
|
+
|
|
110
|
+
return data
|
|
111
|
+
except Exception as ex:
|
|
112
|
+
return {'success': False, 'error': str(ex)}
|
|
113
|
+
|
|
114
|
+
def get_accelerometer(self):
|
|
115
|
+
try:
|
|
116
|
+
data = self.get_inputs_data()
|
|
117
|
+
if data.get('error'):
|
|
118
|
+
logging.error(data['error'])
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
return {'x': data['g_forces'][0], 'y': data['g_forces'][1], 'z': data['g_forces'][2]}
|
|
122
|
+
except Exception as ex:
|
|
123
|
+
logging.exception(ex)
|
|
124
|
+
return None
|
|
125
|
+
|
|
126
|
+
def get_input(self, input=None):
|
|
127
|
+
try:
|
|
128
|
+
data = self.get_inputs_data()
|
|
129
|
+
if data.get('error'):
|
|
130
|
+
logging.error(data['error'])
|
|
131
|
+
return None
|
|
132
|
+
|
|
133
|
+
if type(input) == int and input >= 0 and input <= 3:
|
|
134
|
+
return 1 if (data['digital'] >> input) & 0x1 else 0
|
|
135
|
+
else:
|
|
136
|
+
return data['digital']
|
|
137
|
+
except Exception as ex:
|
|
138
|
+
logging.exception(ex)
|
|
139
|
+
|
|
140
|
+
return None
|
|
141
|
+
|
|
142
|
+
def get_safety_input(self, input=None):
|
|
143
|
+
try:
|
|
144
|
+
data = self.get_inputs_data()
|
|
145
|
+
if data.get('error'):
|
|
146
|
+
logging.error(data['error'])
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
if type(input) == int and input >= 0 and input <= 1:
|
|
150
|
+
return 1 if (data['safety'] >> input) & 0x1 else 0
|
|
151
|
+
else:
|
|
152
|
+
return data['safety']
|
|
153
|
+
except Exception as ex:
|
|
154
|
+
logging.exception(ex)
|
|
155
|
+
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
def get_analog_input(self):
|
|
159
|
+
try:
|
|
160
|
+
data = self.get_inputs_data()
|
|
161
|
+
if data.get('error'):
|
|
162
|
+
logging.error(data['error'])
|
|
163
|
+
return None
|
|
164
|
+
|
|
165
|
+
return data['analog']
|
|
166
|
+
except Exception as ex:
|
|
167
|
+
logging.exception(ex)
|
|
168
|
+
|
|
169
|
+
return None
|
|
170
|
+
|
|
171
|
+
def set_input_polarity(self, target=None, state=None):
|
|
172
|
+
try:
|
|
173
|
+
|
|
174
|
+
if target == 'all' and state is not None:
|
|
175
|
+
target = -1
|
|
176
|
+
if type(state) == str:
|
|
177
|
+
state = 0xf if state.upper() == 'NPN' else 0x0
|
|
178
|
+
else:
|
|
179
|
+
state = 0xf if state else 0x0
|
|
180
|
+
elif target == 'val' and type(state) == int:
|
|
181
|
+
target = -1
|
|
182
|
+
elif type(target) == int and target >= 0 and target <= 3 and state is not None:
|
|
183
|
+
if type(state) == str:
|
|
184
|
+
state = 0x1 if state.upper() == 'NPN' else 0x0
|
|
185
|
+
else:
|
|
186
|
+
state = 0x1 if state else 0x0
|
|
187
|
+
else:
|
|
188
|
+
logging.error(f'InoDrive SetInputPolarity Error: target or state not supported...')
|
|
189
|
+
return None
|
|
190
|
+
|
|
191
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_INPUT_POLARITY, target, state])
|
|
192
|
+
|
|
193
|
+
if response.get('error'):
|
|
194
|
+
logging.error(f'InoDrive SetInputPolarity Error: {str(response)}')
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
return True
|
|
198
|
+
except Exception as ex:
|
|
199
|
+
logging.exception(ex)
|
|
200
|
+
|
|
201
|
+
return None
|
|
202
|
+
|
|
203
|
+
def get_input_polarity(self, input=None):
|
|
204
|
+
try:
|
|
205
|
+
data = self.get_inputs_data()
|
|
206
|
+
if data.get('error'):
|
|
207
|
+
logging.error(data['error'])
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
if type(input) == int and input >= 0 and input <= 3:
|
|
211
|
+
return 'NPN' if (data['polarity'] >> input) & 0x1 else 'PNP'
|
|
212
|
+
else:
|
|
213
|
+
return data['polarity']
|
|
214
|
+
except Exception as ex:
|
|
215
|
+
logging.exception(ex)
|
|
216
|
+
|
|
217
|
+
return None
|
|
218
|
+
|
|
219
|
+
def get_outputs_data(self):
|
|
220
|
+
try:
|
|
221
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.GET_OUTPUTS])
|
|
222
|
+
|
|
223
|
+
if response.get('error'):
|
|
224
|
+
return {'success': False, 'Error': f'InoDrive GetOutputData Error: {str(response.get("error"))}'}
|
|
225
|
+
|
|
226
|
+
data = response['data'][0]
|
|
227
|
+
data.update({'success': True})
|
|
228
|
+
|
|
229
|
+
return data
|
|
230
|
+
except Exception as ex:
|
|
231
|
+
return {'success': False, 'error': str(ex)}
|
|
232
|
+
|
|
233
|
+
def set_output(self, target=None, state=None):
|
|
234
|
+
try:
|
|
235
|
+
if target == 'all' and state is not None:
|
|
236
|
+
target = -1
|
|
237
|
+
state = 0x7 if state else 0x0
|
|
238
|
+
elif target == 'val' and type(state) == int:
|
|
239
|
+
target = -1
|
|
240
|
+
elif type(target) == int and target >= 0 and target <= 2 and state is not None:
|
|
241
|
+
state = 0x1 if state else 0x0
|
|
242
|
+
else:
|
|
243
|
+
logging.error(f'InoDrive SetOutput Error: target os state not supported...')
|
|
244
|
+
return None
|
|
245
|
+
|
|
246
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_OUTPUTS, target, state])
|
|
247
|
+
|
|
248
|
+
if response.get('error'):
|
|
249
|
+
logging.error(f'InoDrive SetOutput Error: {str(response)}')
|
|
250
|
+
return None
|
|
251
|
+
|
|
252
|
+
return True
|
|
253
|
+
except Exception as ex:
|
|
254
|
+
logging.exception(ex)
|
|
255
|
+
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
def get_output(self, output=None):
|
|
259
|
+
try:
|
|
260
|
+
|
|
261
|
+
data = self.get_outputs_data()
|
|
262
|
+
if data.get('error'):
|
|
263
|
+
logging.error(data['error'])
|
|
264
|
+
return None
|
|
265
|
+
|
|
266
|
+
if type(output) == int and output >= 0 and output <= 2:
|
|
267
|
+
return 1 if (data['digital'] >> output) & 0x1 else 0
|
|
268
|
+
else:
|
|
269
|
+
return data['digital']
|
|
270
|
+
|
|
271
|
+
except Exception as ex:
|
|
272
|
+
logging.exception(ex)
|
|
273
|
+
|
|
274
|
+
return None
|
|
275
|
+
|
|
276
|
+
def get_output_fault(self, output=None):
|
|
277
|
+
try:
|
|
278
|
+
|
|
279
|
+
data = self.get_outputs_data()
|
|
280
|
+
if data.get('error'):
|
|
281
|
+
logging.error(data['error'])
|
|
282
|
+
return None
|
|
283
|
+
|
|
284
|
+
if type(output) == int and output >= 0 and output <= 2:
|
|
285
|
+
return 1 if (data['digital_faults'] >> output) & 0x1 else 0
|
|
286
|
+
else:
|
|
287
|
+
return data['digital_faults']
|
|
288
|
+
|
|
289
|
+
except Exception as ex:
|
|
290
|
+
logging.exception(ex)
|
|
291
|
+
|
|
292
|
+
return None
|
|
293
|
+
|
|
294
|
+
def set_holding_brake(self, state=False):
|
|
295
|
+
try:
|
|
296
|
+
|
|
297
|
+
response = self._connection_handle.msg_pack_request([CK.MSG_PACK.SET_HOLDING_BRAKE, True if state else False])
|
|
298
|
+
|
|
299
|
+
if response.get('error'):
|
|
300
|
+
logging.error(f'InoDrive GetOutputFault Error: {str(response)}')
|
|
301
|
+
return None
|
|
302
|
+
|
|
303
|
+
return True
|
|
304
|
+
except Exception as ex:
|
|
305
|
+
logging.exception(ex)
|
|
306
|
+
|
|
307
|
+
return None
|
|
308
|
+
|
|
309
|
+
def get_holding_brake(self):
|
|
310
|
+
try:
|
|
311
|
+
data = self.get_outputs_data()
|
|
312
|
+
if data.get('error'):
|
|
313
|
+
logging.error(data['error'])
|
|
314
|
+
return None
|
|
315
|
+
|
|
316
|
+
return 0x1 if data['brake'] else 0x0
|
|
317
|
+
except Exception as ex:
|
|
318
|
+
logging.exception(ex)
|
|
319
|
+
|
|
320
|
+
return None
|
|
321
|
+
|
|
322
|
+
def get_holding_brake_fault(self):
|
|
323
|
+
try:
|
|
324
|
+
data = self.get_outputs_data()
|
|
325
|
+
if data.get('error'):
|
|
326
|
+
logging.error(data['error'])
|
|
327
|
+
return None
|
|
328
|
+
|
|
329
|
+
return 0x1 if data['brake_fault'] else 0x0
|
|
330
|
+
except Exception as ex:
|
|
331
|
+
logging.exception(ex)
|
|
332
|
+
|
|
333
|
+
return None
|
|
@@ -8,7 +8,6 @@ class _MsgTypes(object):
|
|
|
8
8
|
IPv6 = 0x17
|
|
9
9
|
IPv6_CIDR = 0x18
|
|
10
10
|
NTP_TIME = 0x19
|
|
11
|
-
NTP_TIME = 0x19
|
|
12
11
|
PTP_TIME = 0x2a
|
|
13
12
|
RESERVED_TIME = 0x2b
|
|
14
13
|
MSG_PACK = 0x2c
|
|
@@ -33,6 +32,7 @@ class _MsgFile(object):
|
|
|
33
32
|
BACKUP_FW_TRANSFER = 0x203
|
|
34
33
|
TRANSFER = 0x204
|
|
35
34
|
LIST = 0x205
|
|
35
|
+
WEBPAGE_TRANSFER = 0x208
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class _MsgSpecial(object):
|
|
@@ -56,6 +56,7 @@ class _MsgResult(object):
|
|
|
56
56
|
MULTIPLE_COMMANDS = 0x7
|
|
57
57
|
FILE_ERROR = 0x8
|
|
58
58
|
UPGRADE_ERROR = 0x9
|
|
59
|
+
MSG_PACK_NOT_SUPPORTED = 0xB
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
class _MsgCommand(object):
|
|
@@ -70,6 +71,66 @@ class _MsgJsonApi(object):
|
|
|
70
71
|
DISCONNECT = 255
|
|
71
72
|
|
|
72
73
|
|
|
74
|
+
class _MsgPack(object):
|
|
75
|
+
INVALID = 0x0
|
|
76
|
+
BEACON = 0x1
|
|
77
|
+
CONSOLE_ENABLE = 0x2
|
|
78
|
+
TAKE_CONTROL = 0x3
|
|
79
|
+
MODULE_INFO = 0x4
|
|
80
|
+
|
|
81
|
+
GET_INPUTS = 0x10
|
|
82
|
+
GET_OUTPUTS = 0x11
|
|
83
|
+
GET_METRICS = 0x12
|
|
84
|
+
LIST_VARIABLES = 0x16
|
|
85
|
+
ACCESS_VARIABLES = 0x17
|
|
86
|
+
|
|
87
|
+
SET_INPUT_POLARITY = 0x20
|
|
88
|
+
SET_OUTPUTS = 0x21
|
|
89
|
+
SET_HOLDING_BRAKE = 0x22
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class _MsgPackErrors(object):
|
|
93
|
+
NONE = 0x0
|
|
94
|
+
OUT_OF_MEMORY = 0x1
|
|
95
|
+
INTERNAL_ERROR = 0x2
|
|
96
|
+
BAD_INPUT = 0x3
|
|
97
|
+
BAD_VALUES = 0x4
|
|
98
|
+
NOT_IMPLEMENTED = 0x5
|
|
99
|
+
NOT_ALLOWED = 0x6
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class _OPState(object):
|
|
103
|
+
STATES = {
|
|
104
|
+
"invalid": 0,
|
|
105
|
+
"initializing": 1,
|
|
106
|
+
"initFailed": 2,
|
|
107
|
+
"faulted": 3,
|
|
108
|
+
"operational": 4,
|
|
109
|
+
|
|
110
|
+
"inFailSafeMode": 10,
|
|
111
|
+
"connectingToPeers": 11,
|
|
112
|
+
|
|
113
|
+
"motorNotConfigured": 20,
|
|
114
|
+
"motorDisabled": 21,
|
|
115
|
+
"motorI2tLimited": 22,
|
|
116
|
+
"motorInSto": 23,
|
|
117
|
+
"motorLimitSwitchActive": 24,
|
|
118
|
+
"motorHoldingBrakeFault": 25,
|
|
119
|
+
"motorStopped": 26,
|
|
120
|
+
"motorRunning": 27,
|
|
121
|
+
|
|
122
|
+
"externalControl": 40,
|
|
123
|
+
"uAppNotPresent": 41,
|
|
124
|
+
"uAppStartDelay": 42,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
def get_state_by_value(self, state):
|
|
128
|
+
for key, value in self.STATES.items():
|
|
129
|
+
if state == value:
|
|
130
|
+
return key
|
|
131
|
+
return "invalid"
|
|
132
|
+
|
|
133
|
+
|
|
73
134
|
class _CkDefines(object):
|
|
74
135
|
NOP = 0x0
|
|
75
136
|
RESPONSE = 0x1
|
|
@@ -82,6 +143,8 @@ class _CkDefines(object):
|
|
|
82
143
|
RESULT = _MsgResult()
|
|
83
144
|
COMMAND = _MsgCommand()
|
|
84
145
|
JSON_API = _MsgJsonApi()
|
|
146
|
+
MSG_PACK = _MsgPack()
|
|
147
|
+
MSG_PACK_ERRORS = _MsgPackErrors()
|
|
85
148
|
|
|
86
149
|
API_VAR_ACCESS = {
|
|
87
150
|
'none': 0,
|
|
@@ -382,3 +445,4 @@ class _CkDefines(object):
|
|
|
382
445
|
|
|
383
446
|
|
|
384
447
|
CK = _CkDefines()
|
|
448
|
+
OP_STATE = _OPState()
|
|
@@ -12,7 +12,6 @@ SMEEX_UDP_WELL_KNOWN_PORT = 17737
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def _get_network_interfaces_using_ifaddr(one_ip_per_adapter=False):
|
|
15
|
-
"""Return Client Network Interfaces with IP Addresses."""
|
|
16
15
|
logging.info("List interfaces with ifaddr...")
|
|
17
16
|
netif_ip_list = []
|
|
18
17
|
try:
|
|
@@ -44,7 +43,7 @@ def _get_network_interfaces_using_ifaddr(one_ip_per_adapter=False):
|
|
|
44
43
|
|
|
45
44
|
|
|
46
45
|
def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeout=0.5, ma_sleep_min=0.2, ma_sleep_max=0.5):
|
|
47
|
-
"""Discover
|
|
46
|
+
""" Discover modules on the network interface with the specified IP address."""
|
|
48
47
|
modules_found = {}
|
|
49
48
|
|
|
50
49
|
# Apply a sensible minimum to the timeout
|
|
@@ -221,10 +220,7 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
221
220
|
fw_type = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
222
221
|
data = data[item_size:]
|
|
223
222
|
|
|
224
|
-
firmware_flags =
|
|
225
|
-
'production': True if fw_type & (1 << 6) else False,
|
|
226
|
-
'failSafe': True if fw_type & (1 << 7) else False,
|
|
227
|
-
}
|
|
223
|
+
firmware_flags = Utils.get_firmware_flags(fw_type)
|
|
228
224
|
# =======================================================================
|
|
229
225
|
|
|
230
226
|
# Networking
|
|
@@ -252,31 +248,30 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
252
248
|
|
|
253
249
|
# PCB Version
|
|
254
250
|
# =======================================================================
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
'type': 0,
|
|
260
|
-
}
|
|
251
|
+
pcb_major = 1
|
|
252
|
+
pcb_minor = 1
|
|
253
|
+
pcb_build = 1
|
|
254
|
+
pcb_type = 0
|
|
261
255
|
|
|
262
256
|
if discover_version >= 2:
|
|
263
257
|
item_size = 1
|
|
264
|
-
|
|
258
|
+
pcb_major = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
265
259
|
data = data[item_size:]
|
|
266
260
|
|
|
267
261
|
item_size = 1
|
|
268
|
-
|
|
262
|
+
pcb_minor = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
269
263
|
data = data[item_size:]
|
|
270
264
|
|
|
271
265
|
item_size = 1
|
|
272
|
-
|
|
266
|
+
pcb_build = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
273
267
|
data = data[item_size:]
|
|
274
268
|
|
|
275
269
|
if discover_version >= 3:
|
|
276
270
|
item_size = 1
|
|
277
|
-
|
|
271
|
+
pcb_type = Utils.get_typed_value(data[0:item_size], 'uint8')
|
|
278
272
|
data = data[item_size:]
|
|
279
273
|
|
|
274
|
+
pcb_flags = Utils.get_pcb_flags(pcb_type)
|
|
280
275
|
# =======================================================================
|
|
281
276
|
|
|
282
277
|
except struct.error:
|
|
@@ -300,7 +295,8 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
300
295
|
'dns': dns,
|
|
301
296
|
'mac': mac_address,
|
|
302
297
|
},
|
|
303
|
-
'
|
|
298
|
+
'pcb': '.'.join([str(pcb_major), str(pcb_minor), str(pcb_build)]),
|
|
299
|
+
'pcbFlags': pcb_flags,
|
|
304
300
|
"netif": netif_ip_tuple[0]
|
|
305
301
|
}
|
|
306
302
|
modules_found[sn] = new_module_d
|
|
@@ -316,14 +312,6 @@ def _discover_modules_on_netif(netif_ip_tuple, num_attempts=1, per_attempt_timeo
|
|
|
316
312
|
|
|
317
313
|
|
|
318
314
|
def id_discover_lan(net_adapter_ip=None, num_attempts=2):
|
|
319
|
-
"""
|
|
320
|
-
Discover InoDrive module(s) and gather their information by parsing through Client Network Adapter(s).
|
|
321
|
-
|
|
322
|
-
:Arguments:
|
|
323
|
-
* **net_adapter_ip** *(String)*: (Optional) IP Address of Client Network Adapter the Module is connected to.
|
|
324
|
-
* **num_attempts** *(Integer)*: (Optional) Number of attempts to retrieve Module Information. Defaults to 2 attempts.
|
|
325
|
-
:Returns: **List** - A List of Dictionaries containing the InoDrive's Module and Network Information.
|
|
326
|
-
"""
|
|
327
315
|
# Apply limits to the num_attempts
|
|
328
316
|
if num_attempts < 0:
|
|
329
317
|
num_attempts = 1
|