Repository navigation
Expand file tree
/
Copy pathPythonTamApi.py
More file actions
59 lines (48 loc) · 2.29 KB
/
Copy pathPythonTamApi.py
File metadata and controls
59 lines (48 loc) · 2.29 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
import clr
from os import environ, path
from System import Exception, Enum, Func, TimeSpan
from System.Linq import Enumerable
TAM_SOFTWARE_PATH = path.join(environ['ProgramFiles'], 'Triamec', 'Tam', '8.0.0', 'SDK')
clr.AddReference(path.join(TAM_SOFTWARE_PATH, 'Triamec.Common.dll'))
clr.AddReference(path.join(TAM_SOFTWARE_PATH, 'Tam.dll'))
# These references need to be added in order to circumvent binding failures
clr.AddReference(path.join(TAM_SOFTWARE_PATH, 'System.Memory'))
clr.AddReference(path.join(TAM_SOFTWARE_PATH, 'System.Runtime.CompilerServices.Unsafe.dll'))
from Triamec.Tam import TamEnumerable, TamAxis, TamTopology
from Triamec import CommonExtensions
from Triamec.TriaLink import DeviceState
from Triamec.TriaLink.Adapter import DataLinkLayers
from Triamec.Tam.Acquisitions import TamAcquisitionExtensions
# Create the root object representing the topology of the TAM hardware.
# Note that we must dispose this object at the end in order to clean up resources.
topo = TamTopology(None)
try:
topo.AddLocalTamSystem(None)
except Exception as e:
CommonExtensions.FullMessage(e)
# Connect the drive / get system
tamSystem = topo.Systems[0]
try:
# Boot the Tria-Link so that it learns about connected stations.
tamSystem.Identify()
except Exception as e:
CommonExtensions.FullMessage(e)
# Set the axis name the example works with.
axis_name = 'Axis 0'
# This code looks weird since we need to specify all extension methods and generic arguments explicitly.
# In C#, we could express this as
# var axis = topology.AsDepthFirstLeaves<TamAxis>().FirstOrDefault(a => a.Name == name);
# Get the axis with the predefined name
axis = Enumerable.FirstOrDefault[TamAxis](TamEnumerable.AsDepthFirstLeaves[TamAxis](topo), Func[TamAxis, bool](lambda a : a.Name == axis_name))
# Read arbitrary registers (e.g. Axis state)
state = axis.Register.Signals.General.AxisState.Read()
print(axis_name + ': ' + state.ToString())
# Create acquisition variable for master position, configure and acquire data
posReg = axis.Register.Signals.PositionController.MasterPosition
posVar = TamAcquisitionExtensions.CreateVariable(posReg)
duration = TimeSpan.FromSeconds(1)
TamAcquisitionExtensions.Acquire(posVar,duration)
result = list(posVar)
print('acquired ' + str(len(result)) + ' samples')
# Clean up resources
topo.Dispose()