nodbus-plus 0.8.2 → 1.0.0
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.
- package/.readthedocs.yaml +35 -0
- package/LICENSE.md +21 -21
- package/README.md +163 -48
- package/docs/Makefile +20 -0
- package/docs/client/channel.rst +209 -0
- package/docs/client/nodbus_master_serial.rst +559 -0
- package/docs/client/nodbus_master_tcp.rst +573 -0
- package/docs/conf.py +41 -0
- package/docs/images/01-readcoils.png +0 -0
- package/docs/images/02-readinputs.png +0 -0
- package/docs/images/03-readholding.png +0 -0
- package/docs/images/04-readinputsreg.png +0 -0
- package/docs/images/05-writecoil.png +0 -0
- package/docs/images/06-writeregister.png +0 -0
- package/docs/images/15-writecoil.png +0 -0
- package/docs/images/16.png +0 -0
- package/docs/images/22-mask.png +0 -0
- package/docs/images/23.png +0 -0
- package/docs/images/7.png +0 -0
- package/docs/images/modbus_pdu.png +0 -0
- package/docs/images/serial_adu.png +0 -0
- package/docs/images/tcp_adu.png +0 -0
- package/docs/index.rst +30 -0
- package/docs/make.bat +35 -0
- package/docs/protocol/modbus_master.rst +276 -0
- package/docs/protocol/modbus_master_serial.rst +290 -0
- package/docs/protocol/modbus_master_tcp.rst +296 -0
- package/docs/protocol/modbus_server.rst +469 -0
- package/docs/protocol/modbus_server_serial.rst +543 -0
- package/docs/protocol/modbus_server_tcp.rst +365 -0
- package/docs/requirements.txt +4 -0
- package/docs/server/net_server.rst +242 -0
- package/docs/server/nodbus_serial_server.rst +652 -0
- package/docs/server/nodbus_tcp_server.rst +505 -0
- package/docs/starting.rst +192 -0
- package/docs/static/simple logo.jpg +0 -0
- package/package.json +39 -30
- package/samples/mb_serial_server.js +77 -0
- package/samples/mb_tcp_client.js +114 -0
- package/samples/mb_tcp_server.js +58 -0
- package/src/client/net/serialchannel.js +195 -0
- package/src/client/net/tcpchannel.js +233 -0
- package/src/client/net/udpchannel.js +243 -0
- package/src/client/nodbus_serial_client.js +577 -0
- package/src/client/nodbus_tcp_client.js +542 -0
- package/src/nodbus-plus.js +157 -110
- package/src/protocol/modbus_master.js +298 -961
- package/src/protocol/modbus_master_serial.js +247 -0
- package/src/protocol/modbus_master_tcp.js +219 -0
- package/src/protocol/modbus_server.js +936 -0
- package/src/protocol/modbus_server_serial.js +368 -0
- package/src/protocol/modbus_server_tcp.js +129 -0
- package/src/protocol/utils.js +296 -0
- package/src/server/net/serialserver.js +184 -0
- package/src/server/net/tcpserver.js +290 -0
- package/src/server/net/udpserver.js +242 -0
- package/src/server/nodbus_serial_server.js +238 -0
- package/src/server/nodbus_tcp_server.js +249 -0
- package/test/modbus_master.test.js +279 -0
- package/test/modbus_master_serial.test.js +124 -0
- package/test/modbus_master_tcp.test.js +178 -0
- package/test/modbus_server.test.js +506 -0
- package/test/modbus_server_serial.test.js +328 -0
- package/test/modbus_server_tcp.test.js +91 -0
- package/test/nodbus_client_serial.test.js +307 -0
- package/test/nodbus_client_tcp.test.js +334 -0
- package/test/nodbus_server_serial.test.js +255 -0
- package/test/nodbus_server_tcp.test.js +216 -0
- package/CHANGELOG.md +0 -27
- package/src/client/m_stcp_client.js +0 -214
- package/src/client/m_tcp_client.js +0 -234
- package/src/net/tcpclient.js +0 -173
- package/src/net/tcpserver.js +0 -329
- package/src/protocol/adu.js +0 -40
- package/src/protocol/ascii_adu.js +0 -139
- package/src/protocol/boolean_register.js +0 -78
- package/src/protocol/functions/Force_Multiple_Coils.js +0 -76
- package/src/protocol/functions/Force_Single_Coil.js +0 -54
- package/src/protocol/functions/Mask_Holding_Register.js +0 -47
- package/src/protocol/functions/Preset_Multiple_Registers.js +0 -53
- package/src/protocol/functions/Preset_Single_Register.js +0 -39
- package/src/protocol/functions/Read_Coil_Status.js +0 -59
- package/src/protocol/functions/Read_Holding_Registers.js +0 -52
- package/src/protocol/functions/Read_Input_Registers.js +0 -52
- package/src/protocol/functions/Read_Input_Status.js +0 -58
- package/src/protocol/mbap.js +0 -60
- package/src/protocol/modbus_device.js +0 -35
- package/src/protocol/modbus_slave.js +0 -522
- package/src/protocol/pdu.js +0 -70
- package/src/protocol/rtu_adu.js +0 -122
- package/src/protocol/serial_adu.js +0 -29
- package/src/protocol/tcp_adu.js +0 -84
- package/src/protocol/word_register.js +0 -122
- package/src/server/m_stcp_server.js +0 -310
- package/src/server/m_tcp_server.js +0 -295
- package/test/modbus-stcp-server-test.js +0 -72
- package/test/modbus-stcp-server-test1.js +0 -72
- package/test/modbus-tcp-client-test.js +0 -159
- package/test/modbus-tcp-server-test.js +0 -75
- package/test/modbus-tcp-server-test2.js +0 -75
- package/test/modbus_stcp_client.js +0 -149
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var nodbus = require('../src/nodbus-plus');
|
|
2
|
-
|
|
3
|
-
var modbusTCPServer = new nodbus.ModbusTcpServer(500);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
modbusTCPServer.on('listening', function(port){
|
|
7
|
-
console.log('Server listening on: ' + port);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
modbusTCPServer.on('values', function(reference, address){
|
|
11
|
-
console.log('data write on: ' + (reference == '0x' ? 'coils' : 'holding registers'))
|
|
12
|
-
address.forEach(function(value, key){
|
|
13
|
-
console.log(key + ': ' + value);
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
modbusTCPServer.on('connection', function(socket){
|
|
18
|
-
console.log('New connection form: ' + socket.remoteAddress);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
modbusTCPServer.on('error', function(err){
|
|
22
|
-
console.log(err)
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
modbusTCPServer.on('closed', function(){
|
|
26
|
-
console.log('server closed');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
modbusTCPServer.on('client-disconnect', function(socket){
|
|
30
|
-
console.log('Client ' + socket.remoteAddress + ' disconnected');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
modbusTCPServer.on('indication', function(adubuffer){
|
|
34
|
-
console.log('Indication Recieved');
|
|
35
|
-
console.log(adubuffer);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
modbusTCPServer.on('response', function(resp){
|
|
39
|
-
console.log('Response:');
|
|
40
|
-
console.log(resp);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
modbusTCPServer.SetData(1, 'inputs', 2);
|
|
45
|
-
modbusTCPServer.SetData(1, 'inputs', 3);
|
|
46
|
-
modbusTCPServer.SetData(1, 'inputs', 7);
|
|
47
|
-
modbusTCPServer.SetData(1, 'inputs', 11);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
modbusTCPServer.SetData(1, 'coils', 1);
|
|
51
|
-
modbusTCPServer.SetData(1, 'coils', 6);
|
|
52
|
-
modbusTCPServer.SetData(1, 'coils', 9);
|
|
53
|
-
modbusTCPServer.SetData(1, 'coils', 15);
|
|
54
|
-
|
|
55
|
-
modbusTCPServer.SetData(59, 'holding', 0, 'uint');
|
|
56
|
-
modbusTCPServer.SetData(-358, 'holding', 2, 'int');
|
|
57
|
-
modbusTCPServer.SetData(3.14, 'holding', 3, 'float');
|
|
58
|
-
modbusTCPServer.SetData(0x12, 'holding', 5);
|
|
59
|
-
modbusTCPServer.SetData(0x9E36, 'holding', 6);
|
|
60
|
-
modbusTCPServer.SetData(3598.59, 'holding', 9, 'double');
|
|
61
|
-
|
|
62
|
-
modbusTCPServer.SetData(-27, 'inputs-registers', 1, 'int');
|
|
63
|
-
modbusTCPServer.SetData(-34752648, 'inputs-registers', 2, 'int32');
|
|
64
|
-
modbusTCPServer.SetData(123456789, 'inputs-registers', 5, 'uint32');
|
|
65
|
-
|
|
66
|
-
console.log(modbusTCPServer.GetData('holding',0,'uint'));
|
|
67
|
-
console.log(modbusTCPServer.GetData('holding',2,'int'));
|
|
68
|
-
console.log(modbusTCPServer.GetData('holding',3,'float'));
|
|
69
|
-
console.log(modbusTCPServer.GetData('holding',9,'double'));
|
|
70
|
-
console.log(modbusTCPServer.GetData(3,2,'int32'));
|
|
71
|
-
console.log(modbusTCPServer.GetData(3,5,'uint32'));
|
|
72
|
-
console.log(modbusTCPServer.GetData(1,7));
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
modbusTCPServer.Start();
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
var nodbus = require('..');
|
|
2
|
-
|
|
3
|
-
var modbusSTCPClient = nodbus.CreateMaster('eth', 'rtu');
|
|
4
|
-
|
|
5
|
-
var value;
|
|
6
|
-
|
|
7
|
-
modbusSTCPClient.AddSlave ('plc1', {port:502, timeout:50, modbusAddress:2});
|
|
8
|
-
modbusSTCPClient.AddSlave ('plc2', {port:501, timeout:100, modbusAddress:1, serialMode:'ascii'});
|
|
9
|
-
|
|
10
|
-
modbusSTCPClient.on('data', function(id, data){
|
|
11
|
-
console.log('Data from' + id + ': \n');
|
|
12
|
-
console.log(data);
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
modbusSTCPClient.on('timeout', function(id){
|
|
16
|
-
console.log(id+':timeout');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
modbusSTCPClient.on('error', function(id, err){
|
|
20
|
-
console.log(id + ':error')
|
|
21
|
-
console.log(err)
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
modbusSTCPClient.on('modbus_exception', function(id, modbusError){
|
|
25
|
-
console.log(id + ': '+ modbusError);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
modbusSTCPClient.on('connect', function(id){
|
|
29
|
-
console.log('connection stablished whit ' + id);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
modbusSTCPClient.on('indication', function(id, data){
|
|
33
|
-
console.log('indication send to ' + id);
|
|
34
|
-
console.log(data)
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
modbusSTCPClient.on('disconnect', function(id, err){
|
|
38
|
-
console.log(id+' disconnected');
|
|
39
|
-
console.log(err)
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
modbusSTCPClient.on('raw_data', function(id, data){
|
|
43
|
-
console.log('buffer from ' + id)
|
|
44
|
-
console.log(data);
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
modbusSTCPClient.on('idle', function(id){
|
|
48
|
-
console.log(id +' is waiting');
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
function Test(){
|
|
52
|
-
console.log('starting test')
|
|
53
|
-
//provando evento modbus exeption
|
|
54
|
-
//modbusSTCPClient.ReadHoldingRegisters(15265, 1);
|
|
55
|
-
|
|
56
|
-
//provando funcion 1
|
|
57
|
-
setTimeout(function(){
|
|
58
|
-
console.log('leyendo coils de la 0 a la 7');
|
|
59
|
-
modbusSTCPClient.ReadCoilStatus('plc1', 0, 8);
|
|
60
|
-
modbusSTCPClient.ReadCoilStatus('plc2', 0, 8);
|
|
61
|
-
modbusSTCPClient.ReadCoilStatus('plc5', 0, 8);
|
|
62
|
-
}, 100);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
//provando funcion 2
|
|
66
|
-
setTimeout(function(){
|
|
67
|
-
console.log('leyendo inputs de la 3 a la 8');
|
|
68
|
-
modbusSTCPClient.ReadInputStatus('plc1', 3, 6);
|
|
69
|
-
modbusSTCPClient.ReadInputStatus('plc2', 3, 6);
|
|
70
|
-
}, 150);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
//provando funcion 3
|
|
74
|
-
setTimeout(function(){
|
|
75
|
-
console.log('leyendo holdingRegisters del 0 al 3');
|
|
76
|
-
modbusSTCPClient.ReadHoldingRegisters('plc1', 0, 4);
|
|
77
|
-
modbusSTCPClient.ReadHoldingRegisters('plc2', 0, 4);
|
|
78
|
-
}, 200);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//provando funcion 4
|
|
82
|
-
setTimeout(function(){
|
|
83
|
-
console.log('leyendo inputsRegisters del 1 al 5');
|
|
84
|
-
modbusSTCPClient.ReadInputRegisters('plc1', 1, 5);
|
|
85
|
-
modbusSTCPClient.ReadInputRegisters('plc2', 1, 5);
|
|
86
|
-
}, 250);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
//provando funcion 5
|
|
90
|
-
setTimeout(function(){
|
|
91
|
-
console.log('forzando la coil 5 a 1');
|
|
92
|
-
modbusSTCPClient.ForceSingleCoil('plc1', true, 5);
|
|
93
|
-
modbusSTCPClient.ForceSingleCoil('plc2', true, 5);
|
|
94
|
-
}, 300)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//provando funcion 6
|
|
99
|
-
setTimeout(function(){
|
|
100
|
-
console.log('forzando el registro 14 a 12536');
|
|
101
|
-
modbusSTCPClient.PresetSingleRegister('plc1', 12536, 14);
|
|
102
|
-
modbusSTCPClient.PresetSingleRegister('plc2', 12536, 14);
|
|
103
|
-
}, 350)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//provando funcion 15
|
|
107
|
-
setTimeout(function(){
|
|
108
|
-
console.log('forzando las coils 3 al 12 a 1011001010');
|
|
109
|
-
values = [1, 0, 1, 1, 0, 0, 1, 0, 1, 0];
|
|
110
|
-
modbusSTCPClient.ForceMultipleCoils('plc1', values, 3);
|
|
111
|
-
modbusSTCPClient.ForceMultipleCoils('plc2', values, 3);
|
|
112
|
-
}, 400)
|
|
113
|
-
|
|
114
|
-
//provando funcion 16
|
|
115
|
-
setTimeout(function(){
|
|
116
|
-
console.log('forzando los registros 16 al 21 a [3.14, -54, 0, 7852689]');
|
|
117
|
-
values = [3.14, -54, 0, 7852689];
|
|
118
|
-
modbusSTCPClient.PresetMultipleRegisters('plc1', values , 16);
|
|
119
|
-
modbusSTCPClient.PresetMultipleRegisters('plc2', values , 16);
|
|
120
|
-
}, 450)
|
|
121
|
-
|
|
122
|
-
//provando funcion 22
|
|
123
|
-
setTimeout(function(){
|
|
124
|
-
console.log('mask registro 5');
|
|
125
|
-
values = [1, 0, 0, 1, -1, 0, 1, -1, -1, -1, 0, 0, 1, 1, -1, 0];
|
|
126
|
-
modbusSTCPClient.MaskHoldingRegister('plc1', values , 5);
|
|
127
|
-
modbusSTCPClient.MaskHoldingRegister('plc2', values , 5);
|
|
128
|
-
}, 500)
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
setTimeout(function(){
|
|
133
|
-
console.log('check connection');
|
|
134
|
-
console.log(modbusSTCPClient.isReady('plc1'));
|
|
135
|
-
},1400);
|
|
136
|
-
|
|
137
|
-
//modbusSTCPClient.once('ready', Test);
|
|
138
|
-
|
|
139
|
-
let promise = modbusSTCPClient.Start();
|
|
140
|
-
|
|
141
|
-
promise.then(function(value){
|
|
142
|
-
console.log('conected to:');
|
|
143
|
-
console.log(value);
|
|
144
|
-
Test();
|
|
145
|
-
}, function(value){
|
|
146
|
-
console.log('fail to conect to');
|
|
147
|
-
console.log(value);
|
|
148
|
-
Test();
|
|
149
|
-
});
|