-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improved Serial documentation. * Adding Enron function documentation. * Formatting of MD file * not ignoring node_modules when linting? * removing older LTS --------- Co-authored-by: 1038642892 <[email protected]>
- Loading branch information
1 parent
f62b36d
commit 5caff30
Showing
4 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const ModbusRTU = require(".."); | ||
|
||
const holdingRegisters = {}; | ||
const coils = {}; | ||
const inputRegisters = {}; | ||
const discreteInputs = {}; | ||
|
||
const vector = { | ||
getInputRegister: function(addr) { | ||
return inputRegisters[addr]; | ||
}, | ||
getMultipleInputRegisters: function(startAddr, length) { | ||
const values = []; | ||
for (let i = 0; i < length; i++) { | ||
values[i] = inputRegisters[startAddr + i]; | ||
} | ||
return values; | ||
}, | ||
getDiscreteInput: function(addr) { | ||
return discreteInputs[addr]; | ||
}, | ||
getHoldingRegister: function(addr) { | ||
return holdingRegisters[addr]; | ||
}, | ||
setRegister: function(addr, value) { | ||
holdingRegisters[addr] = value; | ||
return; | ||
}, | ||
getMultipleHoldingRegisters: function(startAddr, length) { | ||
const values = []; | ||
for (let i = 0; i < length; i++) { | ||
values[i] = holdingRegisters[startAddr + i]; | ||
} | ||
return values; | ||
}, | ||
getCoil: function(addr) { | ||
return coils[addr]; | ||
}, | ||
setCoil: function(addr, value) { | ||
coils[addr] = value; | ||
return coils[addr]; | ||
}, | ||
readDeviceIdentification: function() { | ||
return { | ||
0x00: "MyVendorName", | ||
0x01: "MyProductCode", | ||
0x02: "MyMajorMinorRevision", | ||
0x05: "MyModelName", | ||
0x97: "MyExtendedObject1", | ||
0xab: "MyExtendedObject2" | ||
}; | ||
} | ||
}; | ||
|
||
// set the server to answer for modbus requests | ||
const serverSerial = new ModbusRTU.ServerSerial( | ||
vector, | ||
{ | ||
port: "/tmp/ttyp0", | ||
debug: true, | ||
unitID: 1 | ||
// enron: true, | ||
// enronTables: { | ||
// booleanRange: [1001, 1999], | ||
// shortRange: [3001, 3999], | ||
// longRange: [5001, 5999], | ||
// floatRange: [7001, 7999] | ||
// } | ||
}, | ||
{ | ||
baudRate: 9600, | ||
dataBits: 8, | ||
stopBits: 1, | ||
parity: "even" | ||
} | ||
); | ||
|
||
serverSerial.on("error", function(err) { | ||
// Handle socket error if needed, can be ignored | ||
console.error(err); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters