-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpump.js
186 lines (160 loc) · 4.12 KB
/
pump.js
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const i2c = require('i2c-bus');
const EZODevice = require('./ezo_device.js').default;
/**
* Wrapper class for Peristaltic Pump
*/
class Pump extends EZODevice {
/**
* This will begin continuously dispensing liquid until Pause or Stop is given.
* @param {boolean} reverse
*/
async StartDispensing(reverse){
if(reverse){
await this.SendCommand("D,-*");
}else{
await this.SendCommand("D,*");
}
}
/**
* Stops dispensing. Returns the volume of liquid that has been dispensed.
* @returns String
*/
async StopDispensing(){
//_*DONE,v
return (await this.SendCommand("X")).toString().split(',')[1];
}
/**
* Dispenses the given amount. Negative amounts will run the pump in reverse
* @param {String} ml
*/
async Dispense(ml){
await this.SendCommand("D,"+ml);
}
/**
* Dispenses the given volume over the given minutes.
* @param {Number} ml Amount
* @param {Number} min Minutes
*/
async Dose(ml,min){
await this.SendCommand(`D,${ml},${min}`);
}
/**
* Maintain a constant flow rate.
* @param {Number} rate (ml/min)
* @param {String} min Minutes to maintain this rate. Use '*' for indefinite time.
*/
async DispenseConstantRate(rate,min){
await this.SendCommand(`DC,${rate},${min}`);
}
/**
* Pauses Dispensing.
*/
async PauseDispensing(){
await this.SendCommand('P');
}
/**
* Checks if the unit is currently paused
* @returns boolean
*/
async IsPaused(){
const cmd = 'P,?';
//returns _?P,n
return ((await this.SendCommand(cmd))[cmd.length+1]==1);
}
/**
* Gets the current voltage across the Pump's terminals.
* @returns String
*/
async GetPumpVoltage(){
const cmd='PV,?';
return (await this.SendCommand(cmd)).toString('ascii',cmd.length+1);
}
/**
* Gets a single value showing dispensed volume.
* @returns {Promise<Number>}
*/
async GetReading(){
return Number.parseFloat((await this.SendCommand('R')).toString('ascii',1));
}
/**
* Shows the total volume (ml) dispensed by the pump.
*
* This data is erased if the pump loses power.
* @param {boolean} absolute Get the absolute total volume instead.
* @returns ml
*/
async GetTotalDispensedVolume(absolute){
let cmd='TV,?';
if(absolute){
cmd = 'ATV,?';
}
return (await this.SendCommand(cmd)).toString('ascii',cmd.length+1);
}
/**
* Clears the total dispensed volume.
*/
async ClearTotalDispensedVolume(){
await this.SendCommand('clear');
}
/**
* Returns a single number indicating calibration status.
*
* 0 - uncalibrated
*
* 1 - fixed volume
*
* 2 - volume over time
*
* 3 - both
* @returns String
*/
async isCalibrated(){
//returns _?Cal,n
const cmd ='Cal,?';
return (await this.SendCommand(cmd))[cmd.length+1];
}
async Calibrate(volume){
await this.SendCommand('Cal,'+volume);
}
async ClearCalibration(){
await this.SendCommand('Cal,clear');
}
/**
* Enables/Disables the specified parameter.
*
* 'V' - volume being pumped.
*
* 'TV' - total volume being pumped.
*
* 'ATV' - absolute total volume being pumped
* @param {String} parameter
* @param {Boolean} isEnabled
*/
async SetParameters(parameter,isEnabled){
await this.SendCommand(`O,${parameter},${(isEnabled?1:0)}`);
}
/**
* Returns a comma seperated string of the currently enabled parameters
* @returns Promise<String>
*/
async GetParametersEnabled(){
const cmd = 'O,?';
return (await this.SendCommand(cmd)).toString('ascii',cmd.length+1);
}
/**
* This is not supported on the Atlas Scientific Peristaltic Pumps
* @param name
*/
SetName(name){
//Pumps do not support
}
/**
* This is not supported on the Atlas Scientific Peristaltic Pumps
* @returns {null}
*/
GetName(){
return 0;
}
}
module.exports = Pump;
module.exports.default=Pump;