/
mt.proto
140 lines (115 loc) · 2.88 KB
/
mt.proto
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
##################################################
#
# Protocol file for Mettler Toledo Balance.
#
# This implements some of the MT-SICS commands
# (level 0 and level 1), which will apply across the
# range of MT balances.
#
# Oak Ridge National Lab, UT-Battelle, 2018.
#
##################################################
##################################################
# General Settings
Terminator = "\r\n";
ReplyTimeout = 2000;
LongTimeout = 60000;
# Note on timeouts:
#
# The 2s timeout for general commands seems necessary. I often didn't get a reply
# within 1s, even though most of the time the response is well below 1s and we can
# poll weight at 10Hz.
#
# The LongTimeout is for the blocking stable weight, tare and zero commands. If
# the scaler isn't stable these commands can take a long time to complete, until
# a timeout is reached in the scale (which seems to be about 30s in the one I tested).
###################################################
# General functions
# Note: for the string commands the device will send
# a string back in quotes like "blah" so it's
# hard to use %s or %c without getting the quotes.
# So I found that a character based format converter
# works fine, where I read all characters except a quote mark.
# /// Send a cancel command
mtCancel {
out "@";
in "I4 A \"%[^\"]\"";
}
# /// Read the device ID
mtI2 {
out "I2";
in "I2 A \"%[^\"]\"";
}
# /// Read the software version
mtI3 {
out "I3";
in "I3 A \"%[^\"]\"";
}
# /// Read the serial number
mtI4 {
out "I4";
in "I4 A \"%[^\"]\"";
}
# /// Read the software ID
mtI5 {
out "I5";
in "I5 A \"%[^\"]\"";
}
###################################################
# Immediate response or fast set/read functions
# /// Read the immediate weight
mtSI {
out "SI";
in "S %(\$1_STAT)c %f %(\$1_EGU)s";
@mismatch {in "S %(\$1_STAT)c";}
}
# /// Perform an immediate tare.
mtTI {
out "TI";
in "TI %(\$1_STAT)c %f %(\$1_EGU)s";
@mismatch {in "TI %(\$1_STAT)c";}
}
# /// Perform an immediate zero.
mtZI {
out "ZI";
in "ZI %(\$1_STAT)c";
}
# /// Read the tare weight
mtTA {
out "TA";
in "TA %(\$1_STAT)c %f %(\$1_EGU)s";
@mismatch {in "TA %(\$1_STAT)c";}
}
# /// Set the tare weight
mtTASet {
out "TA %f %(\$1_EGU)s";
in "TA %(\$1_STAT)c %f %(\$1_EGU)s";
@mismatch {in "TA %(\$1_STAT)c";}
}
# /// Clear the tare weight
mtTAC {
out "TAC";
in "TAC %(\$1_STAT)c";
}
###################################################
# Blocking set/read functions
# /// Stable weight
mtS {
ReplyTimeout = $LongTimeout;
out "S";
in "S %(\$1_STAT)c %f %(\$1_EGU)s";
@mismatch {in "S %(\$1_STAT)c";}
}
# /// Stable tare
mtT {
ReplyTimeout = $LongTimeout;
out "T";
in "T %(\$1_STAT)c %f %(\$1_EGU)s";
@mismatch {in "T %(\$1_STAT)c";}
}
# /// Stable zero
mtZ {
ReplyTimeout = $LongTimeout;
out "Z";
in "Z %(\$1_STAT)c";
}