⚠️ This library is not perfect. Sometimes the returned values do not match with the requests if the communiction is fast.
<script src="mtecConnectModbus.js"></script>
<script>
var pump = new mtecConnectModbus();
async function connect() {
await pump.connect();
}
async function start(){
await (pump.speed = 20);
}
async function stop(){
await pump.stop();
}
</script>
<button onclick="connect()">Connect</button>
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
⚠️ Keep in mind:
.connect()has to be triggered by user gesture (e.g. onclick)- communication takes some time → use async functions and await
Creates the Object to use the library.
var pump = new mtecConnectModbus(inverterNumber);parameters:
- string (length: 2), inverter number (parameter F802), optional (default: "01")
result:
- mtecConnectModbus, conatins everything used to communicate via modbus
Connects to the serial converter.
📝
.connect()has to be triggered by user gesture (e.g. onclick)
var connected = await pump.connect(); // has to be triggered by user gesture (e.g. onclick)result:
- bool, connection to serial interface sucessful?
📝 While the pump is running, a valid command has to be sent at least every second
If activated, the keep alive feature sends a command some time (interval) after the last command.
This feature can be tweaked in the settings:
- bool
pump.settings.keepAlive.active, if keep alive feature is enabled, default: true - int
pump.settings.keepAlive.interval, interval after which the command is sent (in ms), default: 250 - string (or function with return string)
pump.settings.keepAlive.command(length: 10), action number (2) + parameter number (4) + value (4), default: "03FD000001" - function
pump.settings.keepAlive.callback, gets called with return value as parameter, optional
Starts or stops the pump (target frequency has to be set)
// target frequency has to be set
await pump.start(); // starts the pump
await pump.startReverse(); // starts the pump in reverse
await pump.stop(); // stops the pump
Sets the target frequency
await (pump.frequency = frequency);parameters:
- float, positive (resolution: 0.01), target frequency in Hz
Gets the actual frequency
var frequency = await pump.frequency;result:
- float, positive (resolution: 0.01), actual frequency in Hz
Starts (or stops) the pump in the desired direction
⚠️ Do not switch betweenset frequencyandset speed
await (pump.speed = speed);parameters:
- float, negative to reverse (resolution: 0.01), target frequency
Gets the readiness of the machine (on)
var ready = await pump.ready;result:
- bool, machine is ready for operation
Gets the actual output voltage
var voltage = await pump.voltage;result:
- float, positive (resolution: 0.01), actual voltage in % of voltage rating
Gets the actual output current
var current = await pump.current;result:
- float, positive (resolution: 0.01), actual voltage in % of current rating
Gets the actual torque
var torque = await pump.torque;result:
- float, positive (resolution: 0.01), actual voltage in % of torque rating
Sends custom command to inverter
var answer = await pump.sendCommand(parameter, value);parameters:
- string (length: 6), action number (2) + parameter number (4), example: "03FD00"
- int, value
result:
- int, answer value (equals input value if write command)