Skip to content

Commit

Permalink
# 3.0.4 (2020-06-05)
Browse files Browse the repository at this point in the history
* (bluefox) Added device ID by export/import
* (bluefox) Added the write interval parameter
* (bluefox) Added the disabling of write multiple registers
  • Loading branch information
GermanBluefox committed Jun 5, 2020
1 parent 63ffd91 commit 8f44499
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 468 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ There is a software [**Modbus RTU <-> Modbus RTU over TCP**](http://mbus.sourcef

Both solutions **RTU over TCP** and **TCP** works well.

### Do not use multiple registers
If slave does not support "write multiple registers" command, you can activate it to get warnings, when the multiple registers will be written.

### Write interval
Delay between two write requests in ms. Default 0.

## Data types

- uint16be - Unsigned 16 bit (Big Endian): AABB => AABB
Expand Down Expand Up @@ -186,6 +192,11 @@ There are some programs in folder *test' to test the TCP communication:
- mod_RSsim.exe is slave simulator. It can be that you need [Microsoft Visual C++ 2008 SP1 Redistributable Package](https://www.microsoft.com/en-us/download/details.aspx?id=5582) to start it (because of SideBySide error).

## Changelog
# 3.0.4 (2020-06-05)
* (bluefox) Added device ID by export/import
* (bluefox) Added the write interval parameter
* (bluefox) Added the disabling of write multiple registers

# 3.0.3 (2020-06-05)
* (bluefox) Corrected error after refactoring

Expand Down
Binary file added admin/img/plc_back_opacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 97 additions & 57 deletions admin/index.html

Large diffs are not rendered by default.

74 changes: 73 additions & 1 deletion admin/words.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"common": {
"name": "modbus",
"version": "3.0.3",
"version": "3.0.4",
"news": {
"3.0.4": {
"en": "Added device ID by export/import\nAdded the write interval parameter\nAdded the disabling of write multiple registers",
"de": "Geräte-ID durch Export/Import hinzugefügt\nDer Parameter Schreibintervall wurde hinzugefügt\nDas Deaktivieren des Schreibens mehrerer Register wurde hinzugefügt",
"ru": "Добавлен идентификатор устройства при экспорте/импорте\nДобавлен параметр интервала записи\nДобавлено отключение записи нескольких регистров",
"pt": "ID do dispositivo adicionada por exportação/importação\nAdicionado o parâmetro de intervalo de gravação\nFoi adicionada a desativação de vários registros de gravação",
"nl": "Apparaat-ID toegevoegd door te exporteren/importeren\nDe parameter voor het schrijfinterval toegevoegd\nHet uitschakelen van het schrijven van meerdere registers toegevoegd",
"fr": "ID d'appareil ajouté par export/import\nAjout du paramètre d'intervalle d'écriture\nAjout de la désactivation de l'écriture de plusieurs registres",
"it": "Aggiunto ID dispositivo per esportazione/importazione\nAggiunto il parametro dell'intervallo di scrittura\nAggiunta la disabilitazione della scrittura di più registri",
"es": "ID de dispositivo agregado por exportación/importación\nSe agregó el parámetro de intervalo de escritura\nSe agregó la desactivación de escribir múltiples registros",
"pl": "Dodano identyfikator urządzenia według eksportu/importu\nDodano parametr interwału zapisu\nDodano wyłączenie zapisu wielu rejestrów",
"zh-cn": "通过导出/导入添加了设备ID\n添加了写入间隔参数\n添加了禁用写入多个寄存器的功能"
},
"3.0.3": {
"en": "Corrected error after refactoring",
"de": "Fehler nach dem Refactoring behoben",
Expand Down Expand Up @@ -214,7 +226,9 @@
"doNotIncludeAdrInId": false,
"preserveDotsInId": false,
"round": 2,
"doNotRoundAddressToWord": false
"doNotRoundAddressToWord": false,
"doNotUseWriteMultipleRegisters": false,
"writeInterval": 0
},
"disInputs": [],
"coils": [],
Expand Down
21 changes: 12 additions & 9 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function Master(options, adapter) {

let type = objects[id].native.regType;
let val = sendBuffer[id];
let promise;

if (type === 'coils') {
if (val === 'true' || val === true) {
Expand All @@ -381,7 +382,7 @@ function Master(options, adapter) {
}
val = parseFloat(val);

modbusClient.writeSingleCoil(objects[id].native.deviceId, objects[id].native.address, !!val)
promise = modbusClient.writeSingleCoil(objects[id].native.deviceId, objects[id].native.address, !!val)
.then(response => adapter.log.debug('Write successfully [' + objects[id].native.address + ']: ' + val))
.catch(err => {
adapter.log.error('Cannot write [' + objects[id].native.address + ']: ' + JSON.stringify(err));
Expand All @@ -402,10 +403,10 @@ function Master(options, adapter) {
val = Math.round(val);
}
}
if (objects[id].native.len > 1) {
if (objects[id].native.len > 1 && !options.config.doNotUseWriteMultipleRegisters) {
let hrBuffer = common.writeValue(objects[id].native.type, val, objects[id].native.len);

modbusClient.writeMultipleRegisters(objects[id].native.deviceId, objects[id].native.address, hrBuffer)
promise = modbusClient.writeMultipleRegisters(objects[id].native.deviceId, objects[id].native.address, hrBuffer)
.then(response => adapter.log.debug('Write successfully [' + objects[id].native.address + ']: ' + val))
.catch(err => {
adapter.log.error('Cannot write [' + objects[id].native.address + ']: ' + JSON.stringify(err));
Expand All @@ -416,24 +417,26 @@ function Master(options, adapter) {
if (!modbusClient) {
return adapter.log.error('Client not connected');
}
let buffer = common.writeValue(objects[id].native.type, val, objects[id].native.len);
let buffer = common.writeValue(objects[id].native.type, val, 1);

modbusClient.writeSingleRegister(objects[id].native.deviceId, objects[id].native.address, buffer)
if (objects[id].native.len > 1) {
adapter.log.warn('Trying to write multiple register at once, but option doNotUseWriteMultipleRegisters is enabled! Only first 16 bits are written');
}

promise = modbusClient.writeSingleRegister(objects[id].native.deviceId, objects[id].native.address, buffer)
.then(response => adapter.log.debug('Write successfully [' + objects[id].native.address + ']: ' + val))
.catch(err => {
adapter.log.error('Cannot write [' + objects[id].native.address + ']: ' + JSON.stringify(err));
// still keep on communication
if (!isStop) {
!reconnectTimeout && reconnect(true);
}
!isStop && !reconnectTimeout && reconnect(true);
});
}
}

delete(sendBuffer[id]);

if (Object.keys(sendBuffer).length) {
setTimeout(send, 0);
promise.then(() => setTimeout(send, options.config.writeInterval));
}
}

Expand Down
Loading

0 comments on commit 8f44499

Please sign in to comment.