@iobroker/modbus 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -0
  3. package/build/convert.d.ts +2 -0
  4. package/build/convert.js +102 -0
  5. package/build/convert.js.map +1 -0
  6. package/build/index.d.ts +88 -0
  7. package/build/index.js +1005 -0
  8. package/build/index.js.map +1 -0
  9. package/build/lib/Master.d.ts +27 -0
  10. package/build/lib/Master.js +811 -0
  11. package/build/lib/Master.js.map +1 -0
  12. package/build/lib/Put.d.ts +19 -0
  13. package/build/lib/Put.js +113 -0
  14. package/build/lib/Put.js.map +1 -0
  15. package/build/lib/Slave.d.ts +15 -0
  16. package/build/lib/Slave.js +545 -0
  17. package/build/lib/Slave.js.map +1 -0
  18. package/build/lib/common.d.ts +3 -0
  19. package/build/lib/common.js +371 -0
  20. package/build/lib/common.js.map +1 -0
  21. package/build/lib/crc16modbus.d.ts +1 -0
  22. package/build/lib/crc16modbus.js +33 -0
  23. package/build/lib/crc16modbus.js.map +1 -0
  24. package/build/lib/jsmodbus/modbus-client-core.d.ts +78 -0
  25. package/build/lib/jsmodbus/modbus-client-core.js +528 -0
  26. package/build/lib/jsmodbus/modbus-client-core.js.map +1 -0
  27. package/build/lib/jsmodbus/modbus-server-core.d.ts +33 -0
  28. package/build/lib/jsmodbus/modbus-server-core.js +363 -0
  29. package/build/lib/jsmodbus/modbus-server-core.js.map +1 -0
  30. package/build/lib/jsmodbus/transports/errors.d.ts +7 -0
  31. package/build/lib/jsmodbus/transports/errors.js +40 -0
  32. package/build/lib/jsmodbus/transports/errors.js.map +1 -0
  33. package/build/lib/jsmodbus/transports/modbus-client-serial.d.ts +23 -0
  34. package/build/lib/jsmodbus/transports/modbus-client-serial.js +154 -0
  35. package/build/lib/jsmodbus/transports/modbus-client-serial.js.map +1 -0
  36. package/build/lib/jsmodbus/transports/modbus-client-tcp-rtu.d.ts +24 -0
  37. package/build/lib/jsmodbus/transports/modbus-client-tcp-rtu.js +166 -0
  38. package/build/lib/jsmodbus/transports/modbus-client-tcp-rtu.js.map +1 -0
  39. package/build/lib/jsmodbus/transports/modbus-client-tcp-ssl.d.ts +34 -0
  40. package/build/lib/jsmodbus/transports/modbus-client-tcp-ssl.js +138 -0
  41. package/build/lib/jsmodbus/transports/modbus-client-tcp-ssl.js.map +1 -0
  42. package/build/lib/jsmodbus/transports/modbus-client-tcp.d.ts +27 -0
  43. package/build/lib/jsmodbus/transports/modbus-client-tcp.js +123 -0
  44. package/build/lib/jsmodbus/transports/modbus-client-tcp.js.map +1 -0
  45. package/build/lib/jsmodbus/transports/modbus-server-serial.d.ts +29 -0
  46. package/build/lib/jsmodbus/transports/modbus-server-serial.js +206 -0
  47. package/build/lib/jsmodbus/transports/modbus-server-serial.js.map +1 -0
  48. package/build/lib/jsmodbus/transports/modbus-server-tcp.d.ts +25 -0
  49. package/build/lib/jsmodbus/transports/modbus-server-tcp.js +112 -0
  50. package/build/lib/jsmodbus/transports/modbus-server-tcp.js.map +1 -0
  51. package/build/lib/loggingUtils.d.ts +11 -0
  52. package/build/lib/loggingUtils.js +37 -0
  53. package/build/lib/loggingUtils.js.map +1 -0
  54. package/package.json +68 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2025 Bluefox <dogafox@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @iobroker/modbus
2
+ This is a library that allows you to implement ioBroker Adapter that communicates via modbus with some device.
3
+
4
+ It could accept TSV file as a configuration.
5
+
6
+ ## Test
7
+ There are some programs in folder `test` to test the TCP communication:
8
+ - Ananas32/64 is a slave simulator (only holding registers and inputs, no coils and digital inputs)
9
+ - RMMS is master simulator
10
+ - mod_RSsim.exe is a 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 Side-By-Side error).
11
+
12
+ <!--
13
+ ### **WORK IN PROGRESS**
14
+ -->
15
+ ## Changelog
16
+ ### 7.0.2 (2025-10-06)
17
+ * (bluefox) initial commit
18
+
19
+ ## License
20
+ The MIT License (MIT)
21
+
22
+ Copyright (c) 2015-2025 Bluefox <dogafox@gmail.com>
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy
25
+ of this software and associated documentation files (the "Software"), to deal
26
+ in the Software without restriction, including without limitation the rights
27
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
+ copies of the Software, and to permit persons to whom the Software is
29
+ furnished to do so, subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in
32
+ all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40
+ THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ import type { Register, RegisterType } from './types';
2
+ export default function tsv2registers(type: RegisterType, fileNameOrText: string): Register[];
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = tsv2registers;
4
+ const tsv_json_1 = require("tsv-json");
5
+ const node_fs_1 = require("node:fs");
6
+ const coils = [
7
+ { name: '_address' },
8
+ { name: 'name' },
9
+ { name: 'description' },
10
+ { name: 'formula' },
11
+ { name: 'role' },
12
+ { name: 'room' },
13
+ { name: 'poll', type: 'checkbox' },
14
+ { name: 'wp', type: 'checkbox' },
15
+ { name: 'cw', type: 'checkbox' },
16
+ { name: 'isScale', type: 'checkbox' },
17
+ ];
18
+ const disInputs = [
19
+ { name: '_address' },
20
+ { name: 'name' },
21
+ { name: 'description' },
22
+ { name: 'formula' },
23
+ { name: 'role' },
24
+ { name: 'room' },
25
+ { name: 'cw', type: 'checkbox' },
26
+ { name: 'isScale', type: 'checkbox' },
27
+ ];
28
+ const holdingRegs = [
29
+ { name: '_address' },
30
+ { name: 'name' },
31
+ { name: 'description' },
32
+ { name: 'unit' },
33
+ { name: 'type' },
34
+ { name: 'len' },
35
+ { name: 'factor' },
36
+ { name: 'offset' },
37
+ { name: 'formula' },
38
+ { name: 'role' },
39
+ { name: 'room' },
40
+ { name: 'poll', type: 'checkbox' },
41
+ { name: 'wp', type: 'checkbox' },
42
+ { name: 'cw', type: 'checkbox' },
43
+ { name: 'isScale', type: 'checkbox' },
44
+ ];
45
+ const inputRegs = [
46
+ { name: '_address' },
47
+ { name: 'name' },
48
+ { name: 'description' },
49
+ { name: 'unit' },
50
+ { name: 'type' },
51
+ { name: 'len' },
52
+ { name: 'factor' },
53
+ { name: 'offset' },
54
+ { name: 'formula' },
55
+ { name: 'role' },
56
+ { name: 'room' },
57
+ { name: 'cw', type: 'checkbox' },
58
+ { name: 'isScale', type: 'checkbox' },
59
+ ];
60
+ function tsv2registers(type, fileNameOrText) {
61
+ if (fileNameOrText.toLowerCase().endsWith('.tsv')) {
62
+ if ((0, node_fs_1.existsSync)(fileNameOrText)) {
63
+ fileNameOrText = (0, node_fs_1.readFileSync)(fileNameOrText).toString();
64
+ }
65
+ }
66
+ let propsFields;
67
+ if (type === 'coils') {
68
+ propsFields = coils;
69
+ }
70
+ else if (type === 'inputRegs') {
71
+ propsFields = inputRegs;
72
+ }
73
+ else if (type === 'holdingRegs') {
74
+ propsFields = holdingRegs;
75
+ }
76
+ else if (type === 'disInputs') {
77
+ propsFields = disInputs;
78
+ }
79
+ if (!propsFields) {
80
+ throw new Error('Unknown register type');
81
+ }
82
+ const data = (0, tsv_json_1.tsv2json)(fileNameOrText.endsWith('\n') ? fileNameOrText : `${fileNameOrText}\n`);
83
+ const fields = data.shift();
84
+ if (fields) {
85
+ for (const index in propsFields) {
86
+ if (propsFields[index].name !== fields[index]) {
87
+ throw new Error(`Unexpected field ${index} for ${fields[index]}`);
88
+ }
89
+ }
90
+ }
91
+ return data.map(itemValues => {
92
+ const item = {};
93
+ for (const index in propsFields) {
94
+ if (propsFields[index].type === 'checkbox') {
95
+ itemValues[index] = itemValues[index] === 'true';
96
+ }
97
+ item[propsFields[index].name] = itemValues[index];
98
+ }
99
+ return item;
100
+ });
101
+ }
102
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":";;AAmEA,gCA4CC;AA9GD,uCAAoC;AACpC,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AC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QAChH,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { Adapter } from '@iobroker/adapter-core';
2
+ import type { DeviceMasterOption, DeviceSlaveOption, ModbusAdapterConfig, ModbusParameters, Options, Register, RegisterInternal, RegisterType } from './types';
3
+ import type { PortInfo } from '@serialport/bindings-interface';
4
+ import tsv2registers from './convert';
5
+ import { Master } from './lib/Master';
6
+ import Slave from './lib/Slave';
7
+ export { tsv2registers };
8
+ export default class ModbusAdapter extends Adapter {
9
+ config: ModbusAdapterConfig;
10
+ private infoRegExp;
11
+ static readonly _rmap: {
12
+ [bit: number]: number;
13
+ };
14
+ static readonly _dmap: {
15
+ [bit: number]: number;
16
+ };
17
+ private objects;
18
+ private enumObjs;
19
+ static readonly typeItemsLen: {
20
+ [type: string]: number;
21
+ };
22
+ modbus: Master | Slave | null;
23
+ constructor(adapterName: string, params: ModbusParameters, registers: {
24
+ disInputs?: Register[];
25
+ coils?: Register[];
26
+ inputRegs?: Register[];
27
+ holdingRegs?: Register[];
28
+ });
29
+ processMessage(obj: ioBroker.Message): void;
30
+ stopAdapter(callback?: () => void): void;
31
+ static filterSerialPorts(path: string): boolean;
32
+ listSerial(ports: PortInfo[]): {
33
+ path: string;
34
+ }[] | undefined;
35
+ addToEnum(enumName: string, id: string): Promise<void>;
36
+ removeFromEnum(enumName: string, id: string): Promise<void>;
37
+ syncEnums(enumGroup: 'rooms', id: string, newEnumName: string): Promise<void>;
38
+ static address2alias(id: RegisterType, address: number | string, isDirect: boolean, offset: number): number;
39
+ createExtendObject(id: string, objData: ioBroker.StateObject | ioBroker.ChannelObject): Promise<void>;
40
+ processTasks(tasks: ({
41
+ name: 'add';
42
+ id: string;
43
+ obj: ioBroker.StateObject | ioBroker.ChannelObject;
44
+ } | {
45
+ name: 'del';
46
+ id: string;
47
+ } | {
48
+ name: 'syncEnums';
49
+ id: string;
50
+ newName: string;
51
+ })[]): Promise<void>;
52
+ prepareConfig(): Promise<Options>;
53
+ checkDeviceIds(options: Options, config: Register[], deviceIds: number[]): void;
54
+ checkObjects(regType: RegisterType, regName: string, regFullName: string, tasks: ({
55
+ name: 'add';
56
+ id: string;
57
+ obj: ioBroker.StateObject | ioBroker.ChannelObject;
58
+ } | {
59
+ name: 'del';
60
+ id: string;
61
+ } | {
62
+ name: 'syncEnums';
63
+ id: string;
64
+ newName: string;
65
+ })[], newObjects: string[], deviceId: number): void;
66
+ assignIds(deviceId: number, config: RegisterInternal[], result: DeviceSlaveOption | DeviceMasterOption, regName: string, regType: RegisterType, localOptions: {
67
+ multiDeviceId?: boolean;
68
+ showAliases: boolean;
69
+ doNotRoundAddressToWord: boolean;
70
+ directAddresses: boolean;
71
+ maxBlock?: number;
72
+ maxBoolBlock?: number;
73
+ doNotIncludeAdrInId: boolean;
74
+ preserveDotsInId: boolean;
75
+ }): void;
76
+ iterateAddresses(isBools: boolean, deviceId: number, result: DeviceSlaveOption | DeviceMasterOption, regName: string, regType: RegisterType, localOptions: {
77
+ multiDeviceId?: boolean;
78
+ showAliases: boolean;
79
+ doNotRoundAddressToWord: boolean;
80
+ directAddresses: boolean;
81
+ maxBlock?: number;
82
+ maxBoolBlock?: number;
83
+ doNotIncludeAdrInId: boolean;
84
+ preserveDotsInId: boolean;
85
+ }): void;
86
+ parseConfig(): Promise<Options>;
87
+ main(): Promise<void>;
88
+ }