From c1a59c935ab9025362a203a2fa8e7fa00ee1a8b1 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Thu, 24 Aug 2017 09:08:19 -0700 Subject: [PATCH 01/26] fixed typos --- Modbus485Master/README.md | 2 +- ModbusTCPMaster/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modbus485Master/README.md b/Modbus485Master/README.md index 707dfb7..0d491b5 100644 --- a/Modbus485Master/README.md +++ b/Modbus485Master/README.md @@ -253,7 +253,7 @@ modbus.maskWriteRegister(0x01, 0x10, 0xFFFF, 0x0000, function(error, result) { Function Code : 23 -This method performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read ^. It takes the following parameters: +This method performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read. It takes the following parameters: | Parameter | Data Type | Required | Default Value | Description | | --- | --- | --- | --- | --- | diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index 93ed972..e9a5207 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -289,7 +289,7 @@ modbus.maskWriteRegister(0x10, 0xFFFF, 0x0000, function(error, result) { Function Code : 23 -This method performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read ^. It takes the following parameters: +This method performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read. It takes the following parameters: | Parameter | Data Type | Required | Default Value | Description | | --- | --- | --- | --- | --- | From cac24105745c31f8511bc4dd41ddb5c133ef8935 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Thu, 24 Aug 2017 09:19:54 -0700 Subject: [PATCH 02/26] updated file names and require statements --- ...us485Master.class.nut => Modbus485Master.device.lib.nut} | 0 Modbus485Master/README.md | 6 +++--- Modbus485Master/example/example.device.nut | 6 +++--- ...dbus485Slave.class.nut => Modbus485Slave.device.lib.nut} | 0 Modbus485Slave/README.md | 4 ++-- Modbus485Slave/example/device.example.nut | 4 ++-- .../{ModbusMaster.class.nut => ModbusMaster.device.lib.nut} | 0 ModbusRTU/{ModbusRTU.class.nut => ModbusRTU.device.lib.nut} | 0 ModbusRTU/README.md | 2 +- .../{ModbusSlave.class.nut => ModbusSlave.device.lib.nut} | 0 ...usTCPMaster.class.nut => ModbusTCPMaster.device.lib.nut} | 0 ModbusTCPMaster/README.md | 6 +++--- ModbusTCPMaster/example/device.example.nut | 6 +++--- 13 files changed, 17 insertions(+), 17 deletions(-) rename Modbus485Master/{Modbus485Master.class.nut => Modbus485Master.device.lib.nut} (100%) rename Modbus485Slave/{Modbus485Slave.class.nut => Modbus485Slave.device.lib.nut} (100%) rename ModbusMaster/{ModbusMaster.class.nut => ModbusMaster.device.lib.nut} (100%) rename ModbusRTU/{ModbusRTU.class.nut => ModbusRTU.device.lib.nut} (100%) rename ModbusSlave/{ModbusSlave.class.nut => ModbusSlave.device.lib.nut} (100%) rename ModbusTCPMaster/{ModbusTCPMaster.class.nut => ModbusTCPMaster.device.lib.nut} (100%) diff --git a/Modbus485Master/Modbus485Master.class.nut b/Modbus485Master/Modbus485Master.device.lib.nut similarity index 100% rename from Modbus485Master/Modbus485Master.class.nut rename to Modbus485Master/Modbus485Master.device.lib.nut diff --git a/Modbus485Master/README.md b/Modbus485Master/README.md index 0d491b5..fa02543 100644 --- a/Modbus485Master/README.md +++ b/Modbus485Master/README.md @@ -6,9 +6,9 @@ This library allows an imp to communicate with other devices via the Modbus-RS48 ``` #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.class.nut:1.0.0" -#require "ModbusMaster.class.nut:1.0.0" -#require "Modbus485Master.class.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.0" +#require "ModbusMaster.device.lib.nut:1.0.0" +#require "Modbus485Master.device.lib.nut:1.0.0" ``` ## Hardware Setup diff --git a/Modbus485Master/example/example.device.nut b/Modbus485Master/example/example.device.nut index 8a53fbf..04d66ad 100644 --- a/Modbus485Master/example/example.device.nut +++ b/Modbus485Master/example/example.device.nut @@ -1,7 +1,7 @@ #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.class.nut:1.0.0" -#require "ModbusMaster.class.nut:1.0.0" -#require "Modbus485Master.class.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.0" +#require "ModbusMaster.device.lib.nut:1.0.0" +#require "Modbus485Master.device.lib.nut:1.0.0" // this example demonstrates how to write and read values into/from holding registers const DEVICE_ADDRESS = 0x01; diff --git a/Modbus485Slave/Modbus485Slave.class.nut b/Modbus485Slave/Modbus485Slave.device.lib.nut similarity index 100% rename from Modbus485Slave/Modbus485Slave.class.nut rename to Modbus485Slave/Modbus485Slave.device.lib.nut diff --git a/Modbus485Slave/README.md b/Modbus485Slave/README.md index 2674b66..9e2ac47 100644 --- a/Modbus485Slave/README.md +++ b/Modbus485Slave/README.md @@ -6,8 +6,8 @@ This library empowers an imp to communicate with the Modbus Master via the RS485 ```squirrel #require "CRC16.class.nut:1.0.0" -#require "ModbusSlave.class.nut:1.0.0" -#require "Modbus485Slave.class.nut:1.0.0" +#require "ModbusSlave.device.lib.nut:1.0.0" +#require "Modbus485Slave.device.lib.nut:1.0.0" ``` ## Hardware Setup diff --git a/Modbus485Slave/example/device.example.nut b/Modbus485Slave/example/device.example.nut index bcbdd63..89ed1fd 100644 --- a/Modbus485Slave/example/device.example.nut +++ b/Modbus485Slave/example/device.example.nut @@ -1,6 +1,6 @@ #require "CRC16.class.nut:1.0.0" -#require "ModbusSlave.class.nut:1.0.0" -#require "Modbus485Slave.class.nut:1.0.0" +#require "ModbusSlave.device.lib.nut:1.0.0" +#require "Modbus485Slave.device.lib.nut:1.0.0" modbus <- Modbus485Slave(hardware.uart2, hardware.pinL, 1, { debug = true }); diff --git a/ModbusMaster/ModbusMaster.class.nut b/ModbusMaster/ModbusMaster.device.lib.nut similarity index 100% rename from ModbusMaster/ModbusMaster.class.nut rename to ModbusMaster/ModbusMaster.device.lib.nut diff --git a/ModbusRTU/ModbusRTU.class.nut b/ModbusRTU/ModbusRTU.device.lib.nut similarity index 100% rename from ModbusRTU/ModbusRTU.class.nut rename to ModbusRTU/ModbusRTU.device.lib.nut diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 790219a..67df886 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -6,7 +6,7 @@ This library creates and parses Modbus Protocol Data Units (PDU). It depends on ``` #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.class.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.0" ``` ## ModbusRTU Class Usage diff --git a/ModbusSlave/ModbusSlave.class.nut b/ModbusSlave/ModbusSlave.device.lib.nut similarity index 100% rename from ModbusSlave/ModbusSlave.class.nut rename to ModbusSlave/ModbusSlave.device.lib.nut diff --git a/ModbusTCPMaster/ModbusTCPMaster.class.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut similarity index 100% rename from ModbusTCPMaster/ModbusTCPMaster.class.nut rename to ModbusTCPMaster/ModbusTCPMaster.device.lib.nut diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index e9a5207..b58f82c 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -5,9 +5,9 @@ This library allows an imp to communicate with other devices via TCP/IP. It requ **To use this library, add the following statements to the top of your device code:** ``` -#require "ModbusRTU.class.nut:1.0.0" -#require "ModbusMaster.class.nut:1.0.0" -#require "ModbusTCPMaster.class.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.0" +#require "ModbusMaster.device.lib.nut:1.0.0" +#require "ModbusTCPMaster.device.lib.nut:1.0.0" #require "W5500.device.nut:1.0.0" ``` diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index 7d7ac09..a28c4d8 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -1,7 +1,7 @@ #require "W5500.device.nut:1.0.0" -#require "ModbusRTU.class.nut:1.0.0" -#require "ModbusMaster.class.nut:1.0.0" -#require "ModbusTCPMaster.class.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.0" +#require "ModbusMaster.device.lib.nut:1.0.0" +#require "ModbusTCPMaster.device.lib.nut:1.0.0" // this example shows how to use readWriteMultipleRegisters From a6f4d7f2526535b2caeb1764a9835b62edc7bd17 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Thu, 24 Aug 2017 09:28:23 -0700 Subject: [PATCH 03/26] added license and updated license links --- LICENSE | 23 ++++++++++++++++ .../Modbus485Master.device.lib.nut | 26 ++++++++++++++++--- Modbus485Master/README.md | 2 +- Modbus485Master/example/example.device.nut | 24 +++++++++++++++++ Modbus485Master/tests/device.test.nut | 24 +++++++++++++++++ Modbus485Slave/Modbus485Slave.device.lib.nut | 26 ++++++++++++++++--- Modbus485Slave/README.md | 2 +- Modbus485Slave/example/device.example.nut | 24 +++++++++++++++++ Modbus485Slave/tests/device.test.nut | 25 ++++++++++++++++++ ModbusMaster/ModbusMaster.device.lib.nut | 26 ++++++++++++++++--- ModbusMaster/README.md | 2 +- ModbusRTU/ModbusRTU.device.lib.nut | 26 ++++++++++++++++--- ModbusRTU/README.md | 2 +- ModbusRTU/lib/CRC16.class.nut | 24 +++++++++++++++++ ModbusRTU/tests/device.test.nut | 24 +++++++++++++++++ ModbusSlave/ModbusSlave.device.lib.nut | 26 ++++++++++++++++--- ModbusSlave/README.md | 2 +- .../ModbusTCPMaster.device.lib.nut | 26 ++++++++++++++++--- ModbusTCPMaster/README.md | 2 +- ModbusTCPMaster/example/device.example.nut | 24 +++++++++++++++++ ModbusTCPMaster/tests/device.test.nut | 25 ++++++++++++++++++ README.md | 2 +- 22 files changed, 362 insertions(+), 25 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b59b0fd --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +MIT License + +Copyright 2017 Electric Imp + +SPDX-License-Identifier: MIT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Modbus485Master/Modbus485Master.device.lib.nut b/Modbus485Master/Modbus485Master.device.lib.nut index 9fd59b5..91c70a1 100644 --- a/Modbus485Master/Modbus485Master.device.lib.nut +++ b/Modbus485Master/Modbus485Master.device.lib.nut @@ -1,6 +1,26 @@ -// Copyright (c) 2017 Electric Imp -// This file is licensed under the MIT License -// http://opensource.org/licenses/MIT +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. class Modbus485Master extends ModbusMaster { static MINIMUM_RESPONSE_LENGTH = 5; diff --git a/Modbus485Master/README.md b/Modbus485Master/README.md index fa02543..e1efc76 100644 --- a/Modbus485Master/README.md +++ b/Modbus485Master/README.md @@ -343,4 +343,4 @@ The table below enumerates all the exception codes that can be possibly encounte ## License -The Modbus485Master library is licensed under the [MIT License](https://github.com/electricimp/Modbus/tree/master/LICENSE). +The Modbus485Master library is licensed under the [MIT License](../LICENSE). diff --git a/Modbus485Master/example/example.device.nut b/Modbus485Master/example/example.device.nut index 04d66ad..94d16aa 100644 --- a/Modbus485Master/example/example.device.nut +++ b/Modbus485Master/example/example.device.nut @@ -1,3 +1,27 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #require "CRC16.class.nut:1.0.0" #require "ModbusRTU.device.lib.nut:1.0.0" #require "ModbusMaster.device.lib.nut:1.0.0" diff --git a/Modbus485Master/tests/device.test.nut b/Modbus485Master/tests/device.test.nut index 2f511df..553ba01 100644 --- a/Modbus485Master/tests/device.test.nut +++ b/Modbus485Master/tests/device.test.nut @@ -1,3 +1,27 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + const DEVICE_ADDRESS = 1; function errorMessage(error, resolve, reject) { diff --git a/Modbus485Slave/Modbus485Slave.device.lib.nut b/Modbus485Slave/Modbus485Slave.device.lib.nut index 2e5af05..b78c309 100644 --- a/Modbus485Slave/Modbus485Slave.device.lib.nut +++ b/Modbus485Slave/Modbus485Slave.device.lib.nut @@ -1,6 +1,26 @@ -// Copyright (c) 2017 Electric Imp -// This file is licensed under the MIT License -// http://opensource.org/licenses/MIT +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. class Modbus485Slave extends ModbusSlave { static MIN_REQUEST_LENGTH = 4; diff --git a/Modbus485Slave/README.md b/Modbus485Slave/README.md index 9e2ac47..f8faf4e 100644 --- a/Modbus485Slave/README.md +++ b/Modbus485Slave/README.md @@ -195,4 +195,4 @@ The table below enumerates all the exception codes that can be possibly encounte # License -The Modbus485Slave library is licensed under the [MIT License](https://github.com/electricimp/Mdobus/tree/master/LICENSE). +The Modbus485Slave library is licensed under the [MIT License](../LICENSE). diff --git a/Modbus485Slave/example/device.example.nut b/Modbus485Slave/example/device.example.nut index 89ed1fd..813775a 100644 --- a/Modbus485Slave/example/device.example.nut +++ b/Modbus485Slave/example/device.example.nut @@ -1,3 +1,27 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #require "CRC16.class.nut:1.0.0" #require "ModbusSlave.device.lib.nut:1.0.0" #require "Modbus485Slave.device.lib.nut:1.0.0" diff --git a/Modbus485Slave/tests/device.test.nut b/Modbus485Slave/tests/device.test.nut index 6cd6cba..34a3d9c 100644 --- a/Modbus485Slave/tests/device.test.nut +++ b/Modbus485Slave/tests/device.test.nut @@ -1,3 +1,28 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + + // it is a bit hard to write test cases if the hardware is involved, // so the idea is to create a fake buffer and simulate the parsing requests and creating responses diff --git a/ModbusMaster/ModbusMaster.device.lib.nut b/ModbusMaster/ModbusMaster.device.lib.nut index 1e333db..c08ccc7 100644 --- a/ModbusMaster/ModbusMaster.device.lib.nut +++ b/ModbusMaster/ModbusMaster.device.lib.nut @@ -1,6 +1,26 @@ -// Copyright (c) 2017 Electric Imp -// This file is licensed under the MIT License -// http://opensource.org/licenses/MIT +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. class ModbusMaster { static VERSION = "1.0.0"; diff --git a/ModbusMaster/README.md b/ModbusMaster/README.md index 3997dad..e5f275f 100644 --- a/ModbusMaster/README.md +++ b/ModbusMaster/README.md @@ -15,4 +15,4 @@ This library enables an imp to communicate with other devices via TCP/IP . # License -The ModbusRTUMaster library is licensed under the [MIT License](https://github.com/electricimp/thethingsapi/tree/master/LICENSE). +The ModbusRTUMaster library is licensed under the [MIT License](../LICENSE). diff --git a/ModbusRTU/ModbusRTU.device.lib.nut b/ModbusRTU/ModbusRTU.device.lib.nut index 9d135d0..b2abcdf 100644 --- a/ModbusRTU/ModbusRTU.device.lib.nut +++ b/ModbusRTU/ModbusRTU.device.lib.nut @@ -1,6 +1,26 @@ -// Copyright (c) 2017 Electric Imp -// This file is licensed under the MIT License -// http://opensource.org/licenses/MIT +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. enum MODBUSRTU_SUB_FUNCTION_CODE { RETURN_QUERY_DATA = 0x0000, diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 67df886..986f3e4 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -230,4 +230,4 @@ local result = parse({ ## License -The ModbusRTU library is licensed under the [MIT License](https://github.com/electricimp/Modbus/tree/master/LICENSE). +The ModbusRTU library is licensed under the [MIT License](../LICENSE). diff --git a/ModbusRTU/lib/CRC16.class.nut b/ModbusRTU/lib/CRC16.class.nut index 18aedff..a3e6b92 100644 --- a/ModbusRTU/lib/CRC16.class.nut +++ b/ModbusRTU/lib/CRC16.class.nut @@ -1,3 +1,27 @@ +// MIT License +// +// Copyright 2015 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + const CRC16_LOOKUP_LOW = "\x00\xC0\xC1\x01\xC3\x03\x02\xC2\xC6\x06\x07\xC7\x05\xC5\xC4\x04\xCC\x0C\x0D\xCD\x0F\xCF\xCE\x0E\x0A\xCA\xCB\x0B\xC9\x09\x08\xC8\xD8\x18\x19\xD9\x1B\xDB\xDA\x1A\x1E\xDE\xDF\x1F\xDD\x1D\x1C\xDC\x14\xD4\xD5\x15\xD7\x17\x16\xD6\xD2\x12\x13\xD3\x11\xD1\xD0\x10\xF0\x30\x31\xF1\x33\xF3\xF2\x32\x36\xF6\xF7\x37\xF5\x35\x34\xF4\x3C\xFC\xFD\x3D\xFF\x3F\x3E\xFE\xFA\x3A\x3B\xFB\x39\xF9\xF8\x38\x28\xE8\xE9\x29\xEB\x2B\x2A\xEA\xEE\x2E\x2F\xEF\x2D\xED\xEC\x2C\xE4\x24\x25\xE5\x27\xE7\xE6\x26\x22\xE2\xE3\x23\xE1\x21\x20\xE0\xA0\x60\x61\xA1\x63\xA3\xA2\x62\x66\xA6\xA7\x67\xA5\x65\x64\xA4\x6C\xAC\xAD\x6D\xAF\x6F\x6E\xAE\xAA\x6A\x6B\xAB\x69\xA9\xA8\x68\x78\xB8\xB9\x79\xBB\x7B\x7A\xBA\xBE\x7E\x7F\xBF\x7D\xBD\xBC\x7C\xB4\x74\x75\xB5\x77\xB7\xB6\x76\x72\xB2\xB3\x73\xB1\x71\x70\xB0\x50\x90\x91\x51\x93\x53\x52\x92\x96\x56\x57\x97\x55\x95\x94\x54\x9C\x5C\x5D\x9D\x5F\x9F\x9E\x5E\x5A\x9A\x9B\x5B\x99\x59\x58\x98\x88\x48\x49\x89\x4B\x8B\x8A\x4A\x4E\x8E\x8F\x4F\x8D\x4D\x4C\x8C\x44\x84\x85\x45\x87\x47\x46\x86\x82\x42\x43\x83\x41\x81\x80\x40"; const CRC16_LOOKUP_HIGH = "\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40"; diff --git a/ModbusRTU/tests/device.test.nut b/ModbusRTU/tests/device.test.nut index b4e17e0..8eb3cc0 100644 --- a/ModbusRTU/tests/device.test.nut +++ b/ModbusRTU/tests/device.test.nut @@ -1,3 +1,27 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + const MINIMUM_RESPONSE_LENGTH = 5; const DEVICE_ADDRESS = 0x01; diff --git a/ModbusSlave/ModbusSlave.device.lib.nut b/ModbusSlave/ModbusSlave.device.lib.nut index 0de705e..b5da047 100644 --- a/ModbusSlave/ModbusSlave.device.lib.nut +++ b/ModbusSlave/ModbusSlave.device.lib.nut @@ -1,6 +1,26 @@ -// Copyright (c) 2017 Electric Imp -// This file is licensed under the MIT License -// http://opensource.org/licenses/MIT +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. enum MODBUSSLAVE_TARGET_TYPE { COIL, diff --git a/ModbusSlave/README.md b/ModbusSlave/README.md index 8d6689a..6219203 100644 --- a/ModbusSlave/README.md +++ b/ModbusSlave/README.md @@ -11,4 +11,4 @@ This library empowers an imp to communicate the Modbus Master via the RS485 prot # License -The ModbusRTUMaster library is licensed under the [MIT License](https://github.com/electricimp/thethingsapi/tree/master/LICENSE). +The ModbusRTUMaster library is licensed under the [MIT License](../LICENSE). diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index 09ad6f2..9497c13 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -1,6 +1,26 @@ -// Copyright (c) 2017 Electric Imp -// This file is licensed under the MIT License -// http://opensource.org/licenses/MIT +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. class ModbusTCPMaster extends ModbusMaster { static MAX_TRANSACTION_COUNT = 65535; diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index b58f82c..95faa9b 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -386,4 +386,4 @@ The table below enumerates all the exception codes that can be possibly encounte ## License -The ModbusTCPMaster library is licensed under the [MIT License](https://github.com/electricimp/Modbus/tree/master/LICENSE). +The ModbusTCPMaster library is licensed under the [MIT License](../LICENSE). diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index a28c4d8..3fcdb3a 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -1,3 +1,27 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + #require "W5500.device.nut:1.0.0" #require "ModbusRTU.device.lib.nut:1.0.0" #require "ModbusMaster.device.lib.nut:1.0.0" diff --git a/ModbusTCPMaster/tests/device.test.nut b/ModbusTCPMaster/tests/device.test.nut index b1231c9..2b04b0d 100644 --- a/ModbusTCPMaster/tests/device.test.nut +++ b/ModbusTCPMaster/tests/device.test.nut @@ -1,3 +1,28 @@ +// MIT License +// +// Copyright 2017 Electric Imp +// +// SPDX-License-Identifier: MIT +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + + const PASS_MESSAGE = "Pass"; function errorMessage(error, resolve, reject) { diff --git a/README.md b/README.md index 530705b..2e9b27b 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ This library enables an imp to communicate with other Modbus devices via TCP/IP. ## License -The Modbus libraries are licensed under the [MIT License](https://github.com/electricimp/Modbus/tree/master/LICENSE). +The Modbus libraries are licensed under the [MIT License](./LICENSE). From b875229cb917556c50f777153754eb5a6810d613 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Thu, 24 Aug 2017 10:07:58 -0700 Subject: [PATCH 04/26] updated version number --- Modbus485Master/README.md | 6 +++--- Modbus485Master/example/example.device.nut | 6 +++--- Modbus485Slave/README.md | 4 ++-- Modbus485Slave/example/device.example.nut | 4 ++-- ModbusMaster/ModbusMaster.device.lib.nut | 2 +- ModbusRTU/ModbusRTU.device.lib.nut | 2 +- ModbusRTU/README.md | 2 +- ModbusSlave/ModbusSlave.device.lib.nut | 2 +- ModbusTCPMaster/README.md | 6 +++--- ModbusTCPMaster/example/device.example.nut | 6 +++--- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Modbus485Master/README.md b/Modbus485Master/README.md index e1efc76..5016e35 100644 --- a/Modbus485Master/README.md +++ b/Modbus485Master/README.md @@ -6,9 +6,9 @@ This library allows an imp to communicate with other devices via the Modbus-RS48 ``` #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.device.lib.nut:1.0.0" -#require "ModbusMaster.device.lib.nut:1.0.0" -#require "Modbus485Master.device.lib.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.1" +#require "ModbusMaster.device.lib.nut:1.0.1" +#require "Modbus485Master.device.lib.nut:1.0.1" ``` ## Hardware Setup diff --git a/Modbus485Master/example/example.device.nut b/Modbus485Master/example/example.device.nut index 94d16aa..d6a6a99 100644 --- a/Modbus485Master/example/example.device.nut +++ b/Modbus485Master/example/example.device.nut @@ -23,9 +23,9 @@ // OTHER DEALINGS IN THE SOFTWARE. #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.device.lib.nut:1.0.0" -#require "ModbusMaster.device.lib.nut:1.0.0" -#require "Modbus485Master.device.lib.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.1" +#require "ModbusMaster.device.lib.nut:1.0.1" +#require "Modbus485Master.device.lib.nut:1.0.1" // this example demonstrates how to write and read values into/from holding registers const DEVICE_ADDRESS = 0x01; diff --git a/Modbus485Slave/README.md b/Modbus485Slave/README.md index f8faf4e..cf7c101 100644 --- a/Modbus485Slave/README.md +++ b/Modbus485Slave/README.md @@ -6,8 +6,8 @@ This library empowers an imp to communicate with the Modbus Master via the RS485 ```squirrel #require "CRC16.class.nut:1.0.0" -#require "ModbusSlave.device.lib.nut:1.0.0" -#require "Modbus485Slave.device.lib.nut:1.0.0" +#require "ModbusSlave.device.lib.nut:1.0.1" +#require "Modbus485Slave.device.lib.nut:1.0.1" ``` ## Hardware Setup diff --git a/Modbus485Slave/example/device.example.nut b/Modbus485Slave/example/device.example.nut index 813775a..f1884f5 100644 --- a/Modbus485Slave/example/device.example.nut +++ b/Modbus485Slave/example/device.example.nut @@ -23,8 +23,8 @@ // OTHER DEALINGS IN THE SOFTWARE. #require "CRC16.class.nut:1.0.0" -#require "ModbusSlave.device.lib.nut:1.0.0" -#require "Modbus485Slave.device.lib.nut:1.0.0" +#require "ModbusSlave.device.lib.nut:1.0.1" +#require "Modbus485Slave.device.lib.nut:1.0.1" modbus <- Modbus485Slave(hardware.uart2, hardware.pinL, 1, { debug = true }); diff --git a/ModbusMaster/ModbusMaster.device.lib.nut b/ModbusMaster/ModbusMaster.device.lib.nut index c08ccc7..5b2c04a 100644 --- a/ModbusMaster/ModbusMaster.device.lib.nut +++ b/ModbusMaster/ModbusMaster.device.lib.nut @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusMaster { - static VERSION = "1.0.0"; + static VERSION = "1.0.1"; _debug = null; // diff --git a/ModbusRTU/ModbusRTU.device.lib.nut b/ModbusRTU/ModbusRTU.device.lib.nut index b2abcdf..26e03a5 100644 --- a/ModbusRTU/ModbusRTU.device.lib.nut +++ b/ModbusRTU/ModbusRTU.device.lib.nut @@ -84,7 +84,7 @@ enum MODBUSRTU_OBJECT_ID { } class ModbusRTU { - static VERSION = "1.0.0"; + static VERSION = "1.0.1"; // resLen and reqLen are the length of the PDU static FUNCTION_CODES = { readCoils = { diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 986f3e4..6ad0243 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -6,7 +6,7 @@ This library creates and parses Modbus Protocol Data Units (PDU). It depends on ``` #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.device.lib.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.1" ``` ## ModbusRTU Class Usage diff --git a/ModbusSlave/ModbusSlave.device.lib.nut b/ModbusSlave/ModbusSlave.device.lib.nut index b5da047..fcbe00f 100644 --- a/ModbusSlave/ModbusSlave.device.lib.nut +++ b/ModbusSlave/ModbusSlave.device.lib.nut @@ -41,7 +41,7 @@ enum MODBUSSLAVE_EXCEPTION { } class ModbusSlave { - static VERSION = "1.0.0"; + static VERSION = "1.0.1"; static FUNCTION_CODES = { readCoil = { fcode = 0x01, diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index 95faa9b..ec23f5c 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -5,9 +5,9 @@ This library allows an imp to communicate with other devices via TCP/IP. It requ **To use this library, add the following statements to the top of your device code:** ``` -#require "ModbusRTU.device.lib.nut:1.0.0" -#require "ModbusMaster.device.lib.nut:1.0.0" -#require "ModbusTCPMaster.device.lib.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.1" +#require "ModbusMaster.device.lib.nut:1.0.1" +#require "ModbusTCPMaster.device.lib.nut:1.0.1" #require "W5500.device.nut:1.0.0" ``` diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index 3fcdb3a..6651e72 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -23,9 +23,9 @@ // OTHER DEALINGS IN THE SOFTWARE. #require "W5500.device.nut:1.0.0" -#require "ModbusRTU.device.lib.nut:1.0.0" -#require "ModbusMaster.device.lib.nut:1.0.0" -#require "ModbusTCPMaster.device.lib.nut:1.0.0" +#require "ModbusRTU.device.lib.nut:1.0.1" +#require "ModbusMaster.device.lib.nut:1.0.1" +#require "ModbusTCPMaster.device.lib.nut:1.0.1" // this example shows how to use readWriteMultipleRegisters From f63cd1800fa225356f640dd75148ae2674001a08 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Thu, 24 Aug 2017 10:43:30 -0700 Subject: [PATCH 05/26] added version to extender classes --- Modbus485Master/Modbus485Master.device.lib.nut | 1 + Modbus485Slave/Modbus485Slave.device.lib.nut | 1 + ModbusTCPMaster/ModbusTCPMaster.device.lib.nut | 1 + 3 files changed, 3 insertions(+) diff --git a/Modbus485Master/Modbus485Master.device.lib.nut b/Modbus485Master/Modbus485Master.device.lib.nut index 91c70a1..fe2d590 100644 --- a/Modbus485Master/Modbus485Master.device.lib.nut +++ b/Modbus485Master/Modbus485Master.device.lib.nut @@ -23,6 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class Modbus485Master extends ModbusMaster { + static VERSION = "1.0.1"; static MINIMUM_RESPONSE_LENGTH = 5; _uart = null; _rts = null; diff --git a/Modbus485Slave/Modbus485Slave.device.lib.nut b/Modbus485Slave/Modbus485Slave.device.lib.nut index b78c309..0ea3a66 100644 --- a/Modbus485Slave/Modbus485Slave.device.lib.nut +++ b/Modbus485Slave/Modbus485Slave.device.lib.nut @@ -23,6 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class Modbus485Slave extends ModbusSlave { + static VERSION = "1.0.1"; static MIN_REQUEST_LENGTH = 4; _slaveID = null; _uart = null; diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index 9497c13..05d3720 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -23,6 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusTCPMaster extends ModbusMaster { + static VERSION = "1.0.1"; static MAX_TRANSACTION_COUNT = 65535; _transactions = null; _wiz = null; From 0265984eba9c1d70085caa5945892e8d954d4e83 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Fri, 25 Aug 2017 14:08:12 +1000 Subject: [PATCH 06/26] Fix minor typo --- ModbusTCPMaster/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index ec23f5c..d7f9830 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -27,7 +27,7 @@ This is the main library class. It implements most of the functions listed in th ### Constructor: ModbusTCPMaster(*wiz[, debug]*) -Instantiate a new ModbusTCPMaster object. It takes one required parameter: *wiz*, the [Wiznet W5500](https://github.com/electricimp/Wiznet_5500) object that is driving the Ethernet link, and one optional boolean parameter: *debug* which, if enabled, prints the outgoing and incoming ADU for debugging purposes. The defualt value of *debug* is `false`. +Instantiate a new ModbusTCPMaster object. It takes one required parameter: *wiz*, the [Wiznet W5500](https://github.com/electricimp/Wiznet_5500) object that is driving the Ethernet link, and one optional boolean parameter: *debug* which, if enabled, prints the outgoing and incoming ADU for debugging purposes. The default value of *debug* is `false`. #### Example From 10628f5e7c38d51d62704559471ff00f47c64cb0 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Wed, 13 Sep 2017 12:54:28 -0700 Subject: [PATCH 07/26] updated Modbus485 to ModbusSerial --- .gitignore | 2 - Modbus485Master/.gitignore | 8 --- ModbusMaster/README.md | 4 +- ModbusRTU/.gitignore | 7 --- ModbusRTU/.imptest | 14 +++++ ModbusRTU/lib/CRC16.class.nut | 57 ------------------- ModbusRTU/tests/device.test.nut | 8 ++- ModbusSerialMaster/.imptest | 14 +++++ .../ModbusSerialMaster.device.lib.nut | 33 +++++++---- .../README.md | 39 +++++++------ .../example/example.device.nut | 12 +++- .../tests/device.test.nut | 23 +++++++- ModbusSerialSlave/.imptest | 14 +++++ .../ModbusSerialSlave.device.lib.nut | 24 +++++--- .../README.md | 16 +++--- .../example/device.example.nut | 13 ++++- .../tests/device.test.nut | 16 ++++-- ModbusSlave/README.md | 4 +- ModbusTCPMaster/.imptest | 14 +++++ ModbusTCPMaster/tests/device.test.nut | 7 +++ README.md | 10 ++-- 21 files changed, 197 insertions(+), 142 deletions(-) delete mode 100644 .gitignore delete mode 100644 Modbus485Master/.gitignore delete mode 100644 ModbusRTU/.gitignore create mode 100644 ModbusRTU/.imptest delete mode 100644 ModbusRTU/lib/CRC16.class.nut create mode 100644 ModbusSerialMaster/.imptest rename Modbus485Master/Modbus485Master.device.lib.nut => ModbusSerialMaster/ModbusSerialMaster.device.lib.nut (95%) rename {Modbus485Master => ModbusSerialMaster}/README.md (91%) rename {Modbus485Master => ModbusSerialMaster}/example/example.device.nut (84%) rename {Modbus485Master => ModbusSerialMaster}/tests/device.test.nut (95%) create mode 100644 ModbusSerialSlave/.imptest rename Modbus485Slave/Modbus485Slave.device.lib.nut => ModbusSerialSlave/ModbusSerialSlave.device.lib.nut (93%) rename {Modbus485Slave => ModbusSerialSlave}/README.md (90%) rename {Modbus485Slave => ModbusSerialSlave}/example/device.example.nut (84%) rename {Modbus485Slave => ModbusSerialSlave}/tests/device.test.nut (98%) create mode 100644 ModbusTCPMaster/.imptest diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d62ddbb..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.pdf -*.txt diff --git a/Modbus485Master/.gitignore b/Modbus485Master/.gitignore deleted file mode 100644 index 6a0eacc..0000000 --- a/Modbus485Master/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -**/.build_api_key.json -build/* -builds/* -**/.imptest -agent.nut -device.nut -settings.wrench -lib/* diff --git a/ModbusMaster/README.md b/ModbusMaster/README.md index e5f275f..e53bd67 100644 --- a/ModbusMaster/README.md +++ b/ModbusMaster/README.md @@ -5,9 +5,9 @@ This class is the abstract class for the following classes, it should NOT be ins **Please proceed to one of the following libraries** -# [Modbus485Master](../Modbus485Master/) +# [ModbusSerialMaster](../ModbusSerialMaster/) -This library allows an imp to communicate with other devices via the Modbus-RS485 protocol. +This library allows an imp to communicate with other devices via Modbus-RS485 or Modbus-RS232 protocol. # [ModbusTCPMaster](../ModbusTCPMaster/) diff --git a/ModbusRTU/.gitignore b/ModbusRTU/.gitignore deleted file mode 100644 index 2b513e8..0000000 --- a/ModbusRTU/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -**/.build_api_key.json -build/* -builds/* -**/.imptest -agent.nut -device.nut -settings.wrench diff --git a/ModbusRTU/.imptest b/ModbusRTU/.imptest new file mode 100644 index 0000000..30f3a03 --- /dev/null +++ b/ModbusRTU/.imptest @@ -0,0 +1,14 @@ +{ + "modelId": "KB2yibqKCKCh" /* I */, + "devices": [ + "5000d8c46a56cdae" /* I */ + ], + "agentFile": false, + "deviceFile": "ModbusRTU.device.lib.nut", + "stopOnFailure": false, + "timeout": 10, + "tests": [ + "*.test.nut", + "tests/**/*.test.nut" + ] +} \ No newline at end of file diff --git a/ModbusRTU/lib/CRC16.class.nut b/ModbusRTU/lib/CRC16.class.nut deleted file mode 100644 index a3e6b92..0000000 --- a/ModbusRTU/lib/CRC16.class.nut +++ /dev/null @@ -1,57 +0,0 @@ -// MIT License -// -// Copyright 2015 Electric Imp -// -// SPDX-License-Identifier: MIT -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO -// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES -// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. - -const CRC16_LOOKUP_LOW = "\x00\xC0\xC1\x01\xC3\x03\x02\xC2\xC6\x06\x07\xC7\x05\xC5\xC4\x04\xCC\x0C\x0D\xCD\x0F\xCF\xCE\x0E\x0A\xCA\xCB\x0B\xC9\x09\x08\xC8\xD8\x18\x19\xD9\x1B\xDB\xDA\x1A\x1E\xDE\xDF\x1F\xDD\x1D\x1C\xDC\x14\xD4\xD5\x15\xD7\x17\x16\xD6\xD2\x12\x13\xD3\x11\xD1\xD0\x10\xF0\x30\x31\xF1\x33\xF3\xF2\x32\x36\xF6\xF7\x37\xF5\x35\x34\xF4\x3C\xFC\xFD\x3D\xFF\x3F\x3E\xFE\xFA\x3A\x3B\xFB\x39\xF9\xF8\x38\x28\xE8\xE9\x29\xEB\x2B\x2A\xEA\xEE\x2E\x2F\xEF\x2D\xED\xEC\x2C\xE4\x24\x25\xE5\x27\xE7\xE6\x26\x22\xE2\xE3\x23\xE1\x21\x20\xE0\xA0\x60\x61\xA1\x63\xA3\xA2\x62\x66\xA6\xA7\x67\xA5\x65\x64\xA4\x6C\xAC\xAD\x6D\xAF\x6F\x6E\xAE\xAA\x6A\x6B\xAB\x69\xA9\xA8\x68\x78\xB8\xB9\x79\xBB\x7B\x7A\xBA\xBE\x7E\x7F\xBF\x7D\xBD\xBC\x7C\xB4\x74\x75\xB5\x77\xB7\xB6\x76\x72\xB2\xB3\x73\xB1\x71\x70\xB0\x50\x90\x91\x51\x93\x53\x52\x92\x96\x56\x57\x97\x55\x95\x94\x54\x9C\x5C\x5D\x9D\x5F\x9F\x9E\x5E\x5A\x9A\x9B\x5B\x99\x59\x58\x98\x88\x48\x49\x89\x4B\x8B\x8A\x4A\x4E\x8E\x8F\x4F\x8D\x4D\x4C\x8C\x44\x84\x85\x45\x87\x47\x46\x86\x82\x42\x43\x83\x41\x81\x80\x40"; -const CRC16_LOOKUP_HIGH = "\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40\x00\xC1\x81\x40\x01\xC0\x80\x41\x00\xC1\x81\x40\x01\xC0\x80\x41\x01\xC0\x80\x41\x00\xC1\x81\x40"; - -class CRC16 { - static version = [1,0,0]; - static defaultInitValue = 0xFFFF; - - // Calculate the CRC16 of data [string or blob] for a given range - static function calculate(data, start = null, end = null, initValue = null) { - //Start is inclusive - if(start == null) start = 0; - - // End is exclusive - if(end == null) end = data.len(); - - // Check if we should use a non-default value - if(initValue == null) initValue = defaultInitValue; - - // index is a convenience varaiable - local index; - local lo = initValue & 0xFF; - local hi = (initValue >> 8 ) & 0xFF; - - // Loop through the data - for(local i = start; i < end; i++) { - index = lo ^ data[i]; - lo = hi ^ CRC16_LOOKUP_HIGH[index]; - hi = CRC16_LOOKUP_LOW[index]; - } - - return (hi << 8) | lo; - } -} diff --git a/ModbusRTU/tests/device.test.nut b/ModbusRTU/tests/device.test.nut index 8eb3cc0..1f6bc2d 100644 --- a/ModbusRTU/tests/device.test.nut +++ b/ModbusRTU/tests/device.test.nut @@ -22,10 +22,15 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +// ----------------------------------------------------------------------------- + +// This test can run on any Imp. + +@include "github:electricimp/CRC16/CRC16.class.nut"; + const MINIMUM_RESPONSE_LENGTH = 5; const DEVICE_ADDRESS = 0x01; - function parse (fakeBuffer, params){ local length = fakeBuffer.len(); if (length < MINIMUM_RESPONSE_LENGTH){ @@ -40,7 +45,6 @@ function parse (fakeBuffer, params){ return result; } - class DeviceTestCase extends ImpTestCase { function setUp() { diff --git a/ModbusSerialMaster/.imptest b/ModbusSerialMaster/.imptest new file mode 100644 index 0000000..4ec53c2 --- /dev/null +++ b/ModbusSerialMaster/.imptest @@ -0,0 +1,14 @@ +{ + "modelId": "KB2yibqKCKCh" /* I */, + "devices": [ + "5000d8c46a56cdae" /* I */ + ], + "agentFile": false, + "deviceFile": false, + "stopOnFailure": false, + "timeout": 10, + "tests": [ + "*.test.nut", + "tests/**/*.test.nut" + ] +} \ No newline at end of file diff --git a/Modbus485Master/Modbus485Master.device.lib.nut b/ModbusSerialMaster/ModbusSerialMaster.device.lib.nut similarity index 95% rename from Modbus485Master/Modbus485Master.device.lib.nut rename to ModbusSerialMaster/ModbusSerialMaster.device.lib.nut index fe2d590..7a7a4fc 100644 --- a/Modbus485Master/Modbus485Master.device.lib.nut +++ b/ModbusSerialMaster/ModbusSerialMaster.device.lib.nut @@ -22,9 +22,11 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -class Modbus485Master extends ModbusMaster { - static VERSION = "1.0.1"; +class ModbusSerialMaster extends ModbusMaster { + + static VERSION = "2.0.0"; static MINIMUM_RESPONSE_LENGTH = 5; + _uart = null; _rts = null; _timeout = null; @@ -50,7 +52,7 @@ class Modbus485Master extends ModbusMaster { // @item {float} timeout - 1.0 second by default // @item {bool} debug - false by default. If enabled, the outgoing and incoming ADU will be printed for debugging purpose // - constructor(uart, rts, params = {}) { + constructor(uart, rts = null, params = {}) { base.constructor(("debug" in params) ? params.debug : false); if (!("CRC16" in getroottable())) { throw "Must include CRC16 library v1.0.0+"; @@ -65,10 +67,14 @@ class Modbus485Master extends ModbusMaster { _timeout = ("timeout" in params) ? params.timeout : 1.0; _receiveBuffer = blob(); _uart = uart; - _rts = rts; _queue = []; - _uart.configure(baudRate, dataBits, parity, stopBits, NO_CTSRTS, _uartCallback.bindenv(this)); - _rts.configure(DIGITAL_OUT, 0); + if (rts != null) { + _rts = rts; + _uart.configure(baudRate, dataBits, parity, stopBits, NO_CTSRTS, _uartCallback.bindenv(this)); + _rts.configure(DIGITAL_OUT, 0); + } else { + _uart.configure(baudRate, dataBits, parity, stopBits, 0x00, _uartCallback.bindenv(this)); + } } // @@ -335,13 +341,18 @@ class Modbus485Master extends ModbusMaster { } _callback = properties.callback; local frame = _createADU(PDU); - local rw = _rts.write.bindenv(_rts); local uw = _uart.write.bindenv(_uart); local uf = _uart.flush.bindenv(_uart); - rw(1); - uw(frame); - uf(); - rw(0); + if (_rts != null) { + local rw = _rts.write.bindenv(_rts); + rw(1); + uw(frame); + uf(); + rw(0); + } else { + uw(frame); + uf(); + } _log(frame, "Outgoing ADU : "); _responseTimer = _responseTimeoutFactory(_timeout); } diff --git a/Modbus485Master/README.md b/ModbusSerialMaster/README.md similarity index 91% rename from Modbus485Master/README.md rename to ModbusSerialMaster/README.md index 5016e35..f0beb04 100644 --- a/Modbus485Master/README.md +++ b/ModbusSerialMaster/README.md @@ -1,6 +1,6 @@ -# Modbus485Master +# ModbusSerialMaster -This library allows an imp to communicate with other devices via the Modbus-RS485 protocol. +This library allows an imp to communicate with other devices via the Modbus-RS485 or Modbus-RS232 protocol. **To use this library, add the following statements to the top of your device code:** @@ -8,7 +8,7 @@ This library allows an imp to communicate with other devices via the Modbus-RS48 #require "CRC16.class.nut:1.0.0" #require "ModbusRTU.device.lib.nut:1.0.1" #require "ModbusMaster.device.lib.nut:1.0.1" -#require "Modbus485Master.device.lib.nut:1.0.1" +#require "ModbusSerialMaster.device.lib.nut:2.0.0" ``` ## Hardware Setup @@ -23,13 +23,13 @@ The following instructions are applicable to Electric Imp’s [impAccelerator&tr 6. Power up the Fieldbus Gateway 7. Configure the Fieldbus Gateway for Internet access using BlinkUp™ -## Modbus485Master Class Usage +## ModbusSerialMaster Class Usage This is the main library class. It implements most of the functions listed in the [Modbus specification](http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf). -### Constructor: Modbus485Master(*uart, rts[, params]*) +### Constructor: ModbusSerialMaster(*uart[, rts][, params]*) -Instantiate a new Modbus485Master object and set the configuration of the UART bus over which it operates. The parameters *uart* and *rts* are, respectively, the imp UART in use and an imp GPIO pin which will be used to control flow. The *params* parameter is optional and takes a table containing the following keys: +Instantiate a new ModbusSerialMaster object and set the configuration of the UART bus over which it operates. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 coms when using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: | Key | Default | Notes | | ------ | ----------- | ------------------------------------------------------------------------------- | @@ -43,10 +43,10 @@ Instantiate a new Modbus485Master object and set the configuration of the UART b #### Example ```squirrel -modbus <- Modbus485Master(hardware.uart2, hardware.pinL); +modbus <- ModbusSerialMaster(hardware.uart2, hardware.pinL); ``` -## Modbus485Master Class Methods +## ModbusSerialMaster Class Methods ### read(*deviceAddress, targetType, startingAddress, quantity[, callback]*) @@ -73,7 +73,7 @@ This is a generic method used to read values from a single coil, register, or mu ```squirrel // Read from a single coil -modbus.read(0x01, MODBUSRTU_TARGET_TYPE.DISCRETE_INPUT, 0x01, 1, function(error, result) { +modbus.read(0x01, MODBUSRTU_TARGET_TYPE.COIL, 0x0001, 1, function(error, result) { if (error) { server.error(error); } else { @@ -82,7 +82,7 @@ modbus.read(0x01, MODBUSRTU_TARGET_TYPE.DISCRETE_INPUT, 0x01, 1, function(error, }.bindenv(this)); // Read from multiple registers -modbus.read(0x01, MODBUSRTU_TARGET_TYPE.INPUT_REGISTER, 0x01 , 5, function(error, results) { +modbus.read(0x01, MODBUSRTU_TARGET_TYPE.INPUT_REGISTER, 0x7000 , 2, function(error, results) { if (error) { server.error(error); } else { @@ -119,7 +119,7 @@ This is a generic method used to write values to multiple coils and registers. I ```squirrel // Write to a single coil -modbus.write(0x01, MODBUSRTU_TARGET_TYPE.COIL, 0x01, 1, true, function(error, result) { +modbus.write(0x01, MODBUSRTU_TARGET_TYPE.COIL, 8192, 1, true, function(error, result) { if (error) { server.error(error); } else { @@ -128,13 +128,11 @@ modbus.write(0x01, MODBUSRTU_TARGET_TYPE.COIL, 0x01, 1, true, function(error, re }.bindenv(this)); // Write to multiple registers -modbus.write(0x01, MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER, 0x01, 5, [false, true, false, true, true], function(error, results) { +modbus.write(0x01, MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER, 9, 3, [188, 80, 18], function(error, result) { if (error) { server.error(error); } else { - foreach(key, value in results) { - server.log(key + " : " + value); - } + server.log(result); } }.bindenv(this)); ``` @@ -271,6 +269,15 @@ This method performs a combination of one read operation and one write operation #### Example ```squirrel +modbus.readWriteMultipleRegisters(0x01, 9, 3, 9, 3, [188, 80, 18], function(error, result) { + if (error) { + errorMessage(error, resolve, reject); + } else { + foreach(key, value in results) { + server.log(key + " : " + value); + } + } +}.bindenv(this)); ``` ### readDeviceIdentification(*deviceAddress, readDeviceIdCode, objectId[, callback]*) @@ -343,4 +350,4 @@ The table below enumerates all the exception codes that can be possibly encounte ## License -The Modbus485Master library is licensed under the [MIT License](../LICENSE). +The ModbusSerialMaster library is licensed under the [MIT License](../LICENSE). diff --git a/Modbus485Master/example/example.device.nut b/ModbusSerialMaster/example/example.device.nut similarity index 84% rename from Modbus485Master/example/example.device.nut rename to ModbusSerialMaster/example/example.device.nut index d6a6a99..4017e3f 100644 --- a/Modbus485Master/example/example.device.nut +++ b/ModbusSerialMaster/example/example.device.nut @@ -25,12 +25,18 @@ #require "CRC16.class.nut:1.0.0" #require "ModbusRTU.device.lib.nut:1.0.1" #require "ModbusMaster.device.lib.nut:1.0.1" -#require "Modbus485Master.device.lib.nut:1.0.1" +#require "ModbusSerialMaster.device.lib.nut:2.0.0" + +// Hardware used: Fieldbus Gateway and Kojo +// Click PLC C0-02DR-D connectied via RS485 ports + +// This example demonstrates how to write and read values +// into/from holding registers. -// this example demonstrates how to write and read values into/from holding registers const DEVICE_ADDRESS = 0x01; // instantiate the the Modbus485Master object -modbus <- Modbus485Master(hardware.uart2, hardware.pinL); +local params = {"baudRate" : 38400, "parity" : PARITY_ODD}; +modbus <- ModbusSerialMaster(hardware.uart2, hardware.pinL, params); // write values into 3 holding registers starting at address 9 modbus.write(DEVICE_ADDRESS, MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER, 9, 3, [188, 80, 18], function(error, res) { diff --git a/Modbus485Master/tests/device.test.nut b/ModbusSerialMaster/tests/device.test.nut similarity index 95% rename from Modbus485Master/tests/device.test.nut rename to ModbusSerialMaster/tests/device.test.nut index 553ba01..c6a9abc 100644 --- a/Modbus485Master/tests/device.test.nut +++ b/ModbusSerialMaster/tests/device.test.nut @@ -22,8 +22,21 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -const DEVICE_ADDRESS = 1; +// ----------------------------------------------------------------------------- +// Hardware setup: +// * Fieldbus Gateway +// * Koyo Click PLC C0-02DR-D +// * Connected via RS485 ports + +@include "github:electricimp/CRC16/CRC16.class.nut"; +@include __PATH__ + "/../../ModbusRTU/ModbusRTU.device.lib.nut"; +@include __PATH__ + "/../../ModbusMaster/ModbusMaster.device.lib.nut"; +@include __PATH__ + "/../ModbusSerialMaster.device.lib.nut"; + +// Function to allow tests with expected error messages to pass +// With the hardware setup above it is expected that only **testReportSlaveID** +// will need this helper to pass testing function errorMessage(error, resolve, reject) { switch (error) { case MODBUSRTU_EXCEPTION.ILLEGAL_FUNCTION: @@ -37,13 +50,17 @@ function errorMessage(error, resolve, reject) { } } +const DEVICE_ADDRESS = 0x01; + class DeviceTestCase extends ImpTestCase { _PASS_MESSAGE = "Pass"; _modbus = null; function setUp() { - _modbus = Modbus485Master(hardware.uart2, hardware.pinL); - return "Modbus485Master"; + // These are the default settings for the Koyo Click PLC C0-02DR-D + local params = {"baudRate" : 38400, "parity" : PARITY_ODD}; + _modbus = ModbusSerialMaster(hardware.uart2, hardware.pinL, params); + return "ModbusSerialMaster"; } function testReadCoils() { diff --git a/ModbusSerialSlave/.imptest b/ModbusSerialSlave/.imptest new file mode 100644 index 0000000..4ec53c2 --- /dev/null +++ b/ModbusSerialSlave/.imptest @@ -0,0 +1,14 @@ +{ + "modelId": "KB2yibqKCKCh" /* I */, + "devices": [ + "5000d8c46a56cdae" /* I */ + ], + "agentFile": false, + "deviceFile": false, + "stopOnFailure": false, + "timeout": 10, + "tests": [ + "*.test.nut", + "tests/**/*.test.nut" + ] +} \ No newline at end of file diff --git a/Modbus485Slave/Modbus485Slave.device.lib.nut b/ModbusSerialSlave/ModbusSerialSlave.device.lib.nut similarity index 93% rename from Modbus485Slave/Modbus485Slave.device.lib.nut rename to ModbusSerialSlave/ModbusSerialSlave.device.lib.nut index 0ea3a66..ee729b1 100644 --- a/Modbus485Slave/Modbus485Slave.device.lib.nut +++ b/ModbusSerialSlave/ModbusSerialSlave.device.lib.nut @@ -22,8 +22,8 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -class Modbus485Slave extends ModbusSlave { - static VERSION = "1.0.1"; +class ModbusSerialSlave extends ModbusSlave { + static VERSION = "2.0.0"; static MIN_REQUEST_LENGTH = 4; _slaveID = null; _uart = null; @@ -35,6 +35,7 @@ class Modbus485Slave extends ModbusSlave { // // Constructor for Modbus485Slave // + // @param {integer} slaveID - The slave id // @param {object} uart - The UART object // @param {object} rts - The pin used as RTS // @param {table} params - The table contains all the arugments the constructor expects @@ -44,7 +45,7 @@ class Modbus485Slave extends ModbusSlave { // @item {integer} stopBits - 1 bit by default // @item {bool} debug - false by default. If enabled, the outgoing and incoming ADU will be printed for debugging purpose // - constructor(uart, rts, slaveID, params = {}) { + constructor(slaveID, uart, rts = null, params = {}) { if (!("CRC16" in getroottable())) { throw "Must include CRC16 library v1.0.0+"; } @@ -64,7 +65,7 @@ class Modbus485Slave extends ModbusSlave { // 4.5 characters time in microseconds _minInterval = 45000000.0 / baudRate; _uart.configure(baudRate, dataBits, parity, stopBits, TIMING_ENABLED, _onReceive.bindenv(this)); - _rts.configure(DIGITAL_OUT, 0); + if (_rts != null) _rts.configure(DIGITAL_OUT, 0); } // @@ -165,13 +166,18 @@ class Modbus485Slave extends ModbusSlave { // the concrete function to send a packet via RS485 // function _send(ADU) { - local rw = _rts.write.bindenv(_rts); local uw = _uart.write.bindenv(_uart); local uf = _uart.flush.bindenv(_uart); - rw(1); - uw(ADU); - uf(); - rw(0); + if (_rts != null) { + local rw = _rts.write.bindenv(_rts); + rw(1); + uw(ADU); + uf(); + rw(0); + } else { + uw(ADU); + uf(); + } _log(ADU, "Outgoing ADU : "); // return ADU to help with testing return ADU; diff --git a/Modbus485Slave/README.md b/ModbusSerialSlave/README.md similarity index 90% rename from Modbus485Slave/README.md rename to ModbusSerialSlave/README.md index cf7c101..647f2c8 100644 --- a/Modbus485Slave/README.md +++ b/ModbusSerialSlave/README.md @@ -1,13 +1,13 @@ -# Modbus485Slave +# ModbusSerialSlave -This library empowers an imp to communicate with the Modbus Master via the RS485 protocol. +This library empowers an imp to communicate with the Modbus Master via the RS485 or RS232 protocol. **To use this library, add the following statements to the top of your device code:** ```squirrel #require "CRC16.class.nut:1.0.0" #require "ModbusSlave.device.lib.nut:1.0.1" -#require "Modbus485Slave.device.lib.nut:1.0.1" +#require "ModbusSerialSlave.device.lib.nut:2.0.0" ``` ## Hardware Setup @@ -22,13 +22,13 @@ The following instructions are applicable to Electric Imp’s [impAccelerator&tr 6. Power up the Fieldbus Gateway 7. Configure the Fieldbus Gateway for Internet access using BlinkUp™ -## Modbus485Slave Class Usage +## ModbusSerialSlave Class Usage This is the main library class. -### Constructor: Modbus485Slave(*uart, rts, slaveID[, params]*) +### Constructor: ModbusSerialSlave(*slaveID, uart[, rts][, params]*) -Instantiate a new Modbus485Slave object and set the configuration of the UART bus over which it operates. The parameters *uart* and *rts* are, respectively, the imp UART in use and an imp GPIO pin which will be used to control flow. The *slaveID* parameter takes an ID by which the master identifies this slave. The *params* parameter is optional and takes a table containing the following keys: +Instantiate a new ModbusSerialSlave object and set the configuration of the UART bus over which it operates. The *slaveID* parameter takes an ID by which the master identifies this slave. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 coms when using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: | Key | Default | Notes | | --- | --- | --- | @@ -41,7 +41,7 @@ Instantiate a new Modbus485Slave object and set the configuration of the UART bu #### Example ```squirrel -modbus <- Modbus485Slave(hardware.uart2, hardware.pinL, 1); +modbus <- Modbus485Slave(1, hardware.uart2, hardware.pinL); ``` ### setSlaveID(*slaveID*) @@ -195,4 +195,4 @@ The table below enumerates all the exception codes that can be possibly encounte # License -The Modbus485Slave library is licensed under the [MIT License](../LICENSE). +The ModbusSerialSlave library is licensed under the [MIT License](../LICENSE). diff --git a/Modbus485Slave/example/device.example.nut b/ModbusSerialSlave/example/device.example.nut similarity index 84% rename from Modbus485Slave/example/device.example.nut rename to ModbusSerialSlave/example/device.example.nut index f1884f5..e91573a 100644 --- a/Modbus485Slave/example/device.example.nut +++ b/ModbusSerialSlave/example/device.example.nut @@ -24,15 +24,22 @@ #require "CRC16.class.nut:1.0.0" #require "ModbusSlave.device.lib.nut:1.0.1" -#require "Modbus485Slave.device.lib.nut:1.0.1" +#require "ModbusSerialSlave.device.lib.nut:2.0.0" -modbus <- Modbus485Slave(hardware.uart2, hardware.pinL, 1, { debug = true }); +// Hardware used: Fieldbus Gateway and Kojo +// Click PLC C0-02DR-D connectied via RS485 ports + +// This example demonstrates a holding register read. + +const SLAVE_ID = 0x01; + +local params = {"baudRate" : 38400, "parity" : PARITY_ODD, "debug" : true}; +modbus <- ModbusSerialSlave(SLAVE_ID, hardware.uart2, hardware.pinL, params); modbus.onError(function(error) { server.error(error); }); -// a holding register read example modbus.onRead(function(slaveID, functionCode, startingAddress, quantity) { server.log("slaveID : " + slaveID); server.log("functionCode : " + functionCode); diff --git a/Modbus485Slave/tests/device.test.nut b/ModbusSerialSlave/tests/device.test.nut similarity index 98% rename from Modbus485Slave/tests/device.test.nut rename to ModbusSerialSlave/tests/device.test.nut index 34a3d9c..f6cc30b 100644 --- a/Modbus485Slave/tests/device.test.nut +++ b/ModbusSerialSlave/tests/device.test.nut @@ -22,9 +22,17 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +// ---------------------------------------------------------------------------------- -// it is a bit hard to write test cases if the hardware is involved, -// so the idea is to create a fake buffer and simulate the parsing requests and creating responses +// It is a bit hard to write test cases if the hardware is involved, +// so the idea is to create a fake buffer and simulate the parsing +// requests and creating responses. + +// Hardware used: Fieldbus Gateway + +@include "github:electricimp/CRC16/CRC16.class.nut"; +@include __PATH__ + "/../../ModbusSlave/ModbusSlave.device.lib.nut"; +@include __PATH__ + "/../ModbusSerialSlave.device.lib.nut"; const SLAVE_ID = 1; const MIN_REQUEST_LENGTH = 4; @@ -45,8 +53,8 @@ class DeviceTestCase extends ImpTestCase { _modbus = null; function setUp() { - _modbus = Modbus485Slave(hardware.uart2, hardware.pinL, SLAVE_ID); - return "Modbus485Slave"; + _modbus = ModbusSerialSlave(SLAVE_ID, hardware.uart2, hardware.pinL); + return "ModbusSerialSlave"; } function testSetSlaveID() { diff --git a/ModbusSlave/README.md b/ModbusSlave/README.md index 6219203..f308d77 100644 --- a/ModbusSlave/README.md +++ b/ModbusSlave/README.md @@ -5,9 +5,9 @@ This is the base class for the following classes, and it should NOT be instantia **Please proceed to one of the following libraries** -# [Modbus485Slave](../Modbus485Slave/) +# [ModbusSerialSlave](../ModbusSerialSlave/) -This library empowers an imp to communicate the Modbus Master via the RS485 protocol. +This library empowers an imp to communicate the Modbus Master via the RS485 or RS232 protocol. # License diff --git a/ModbusTCPMaster/.imptest b/ModbusTCPMaster/.imptest new file mode 100644 index 0000000..4ec53c2 --- /dev/null +++ b/ModbusTCPMaster/.imptest @@ -0,0 +1,14 @@ +{ + "modelId": "KB2yibqKCKCh" /* I */, + "devices": [ + "5000d8c46a56cdae" /* I */ + ], + "agentFile": false, + "deviceFile": false, + "stopOnFailure": false, + "timeout": 10, + "tests": [ + "*.test.nut", + "tests/**/*.test.nut" + ] +} \ No newline at end of file diff --git a/ModbusTCPMaster/tests/device.test.nut b/ModbusTCPMaster/tests/device.test.nut index 2b04b0d..f561345 100644 --- a/ModbusTCPMaster/tests/device.test.nut +++ b/ModbusTCPMaster/tests/device.test.nut @@ -25,6 +25,11 @@ const PASS_MESSAGE = "Pass"; +@include "https://raw.githubusercontent.com/electricimp/Wiznet_5500/master/W5500.device.lib.nut"; +@include __PATH__ + "/../../ModbusRTU/ModbusRTU.device.lib.nut"; +@include __PATH__ + "/../../ModbusMaster/ModbusMaster.device.lib.nut"; +@include __PATH__ + "/../ModbusTCPMaster.device.lib.nut"; + function errorMessage(error, resolve, reject) { switch(error) { case MODBUSRTU_EXCEPTION.ILLEGAL_FUNCTION: @@ -47,8 +52,10 @@ class DeviceTestCase extends ImpTestCase { function setUp() { local spi = hardware.spi0; spi.configure(CLOCK_IDLE_LOW | MSB_FIRST | USE_CS_L, 1000); + local wiz = W5500(hardware.pinXC, spi, null, hardware.pinXA); wiz.configureNetworkSettings("192.168.1.30", "255.255.255.0", "192.168.1.1"); + _modbus = ModbusTCPMaster(wiz); _connection = Promise(function(resolve, reject) { _modbus.connect({ diff --git a/README.md b/README.md index 2e9b27b..61f00ae 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ Electric Imp’s Modbus support is delivered through the following four librarie ### [ModbusRTU](./ModbusRTU/) -This library creates and parses Modbus Protocol Data Unit (PDU). This library is a prerequisite for the Modbus485Master and ModbusTCPMaster libraries. +This library creates and parses Modbus Protocol Data Unit (PDU). This library is a prerequisite for the ModbusSerialMaster and ModbusTCPMaster libraries. -### [Modbus485Master](./Modbus485Master/) +### [ModbusSerialMaster](./ModbusSerialMaster/) -This library allows an imp to communicate with other Modbus devices via the Modbus-RS485 protocol. +This library allows an imp to communicate with other devices via Modbus-RS485 or Modbus-RS232 protocol. -### [Modbus485Slave](./Modbus485Slave/) +### [ModbusSerialSlave](./ModbusSerialSlave/) -This library empowers an imp to communicate with a Modbus Master via the RS485 protocol. +This library empowers an imp to communicate with a Modbus Master via the RS485 or RS232 protocol. ### [ModbusTCPMaster](./ModbusTCPMaster/) From 01526d7a60cea40d6426ccbf00fd75153b3c1271 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Fri, 15 Sep 2017 15:06:33 +0100 Subject: [PATCH 08/26] Minor edits --- ModbusSerialMaster/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ModbusSerialMaster/README.md b/ModbusSerialMaster/README.md index f0beb04..8370dab 100644 --- a/ModbusSerialMaster/README.md +++ b/ModbusSerialMaster/README.md @@ -29,13 +29,13 @@ This is the main library class. It implements most of the functions listed in th ### Constructor: ModbusSerialMaster(*uart[, rts][, params]*) -Instantiate a new ModbusSerialMaster object and set the configuration of the UART bus over which it operates. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 coms when using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: +Instantiates a new ModbusSerialMaster object and configures the UART bus over which it operates. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 communications when you are using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: | Key | Default | Notes | | ------ | ----------- | ------------------------------------------------------------------------------- | | baudRate | 19200 | The baud rate of the UART connection | | dataBits | 8 | The word size on the UART connection in bits (7 or 8 bits) | -| parity | *PARITY_NONE* | Parity configuration of the UART connection | +| parity | *PARITY_NONE* | Parity configuration of the UART connection | | stopBits | 1 | Number of stop bits (1 or 2) on the UART connection | | timeout | 1.0 | The maximum time allowed for one request | | debug | `false` | If enabled, the outgoing and incoming ADU will be printed for debugging purpose | @@ -50,7 +50,7 @@ modbus <- ModbusSerialMaster(hardware.uart2, hardware.pinL); ### read(*deviceAddress, targetType, startingAddress, quantity[, callback]*) -Function Code : 01, 02, 03, 04 +Function Codes: 01, 02, 03, 04 This is a generic method used to read values from a single coil, register, or multiple coils and registers. It takes the following parameters: @@ -95,7 +95,7 @@ modbus.read(0x01, MODBUSRTU_TARGET_TYPE.INPUT_REGISTER, 0x7000 , 2, function(err ### write(*deviceAddress, targetType, startingAddress, quantity, values[, callback]*) -Function Code : 05, 06, 15, 16 +Function Codes: 05, 06, 15, 16 This is a generic method used to write values to multiple coils and registers. It takes the following parameters: @@ -139,7 +139,7 @@ modbus.write(0x01, MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER, 9, 3, [188, 80, 18], ### readExceptionStatus(*deviceAddress[, callback]*) -Function Code : 07 +Function Code: 07 This method reads the contents of eight Exception Status outputs in a remote device (address passed into the first parameter. If a callback is supplied, it will be triggered when a response regarding this request is received. The callback takes two parameters: *error* and *result*. @@ -157,7 +157,7 @@ modbus.readExceptionStatus(0x01, function(error, result) { ### diagnostics(*deviceAddress, subFunctionCode, data[, callback]*) -Function Code : 08 +Function Code: 08 This method provides a series of tests for checking the communication system between a client (Master) device and a server (Slave), or for checking various internal error conditions within a server. It takes the following parameters: @@ -204,7 +204,7 @@ modbus.diagnostics(0x01, MODBUSRTU_SUB_FUNCTION_CODE.RESTART_COMMUNICATION_OPTIO ### reportSlaveID(*deviceAddress[, callback]*) -Function Code : 17 +Function Code: 17 This method reads the description of the type, the current status and other information specific to a remote device whose address is specified in the method’s first parameter. The second, optional parameter is a function that will be fired when a response regarding this request is received. It takes two parameters, *error* and *result*. @@ -223,7 +223,7 @@ modbus.reportSlaveID(0x01, function(error, result) { ### maskWriteRegister(*deviceAddress, referenceAddress, AND_Mask, OR_Mask[, callback]*) -Function Code : 22 +Function Code: 22 This method modifies the contents of a specified holding register using a combination of an AND mask, an OR mask and the register’s current contents. The function can be used to set or clear individual bits in the register. It takes the following parameters: @@ -249,7 +249,7 @@ modbus.maskWriteRegister(0x01, 0x10, 0xFFFF, 0x0000, function(error, result) { ### readWriteMultipleRegisters(*deviceAddress, readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue[, callback]*) -Function Code : 23 +Function Code: 23 This method performs a combination of one read operation and one write operation in a single Modbus transaction. The write operation is performed before the read. It takes the following parameters: @@ -282,7 +282,7 @@ modbus.readWriteMultipleRegisters(0x01, 9, 3, 9, 3, [188, 80, 18], function(erro ### readDeviceIdentification(*deviceAddress, readDeviceIdCode, objectId[, callback]*) -Function Code : 43/14 +Function Code: 43/14 This method lets you read the identification and additional information relative to the physical and functional description of a remote device. It takes the following parameters: From 377d8d95c3d56517925de9f1fa85dfa9a3a3a2dd Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Fri, 15 Sep 2017 15:08:55 +0100 Subject: [PATCH 09/26] Minor edits --- ModbusSerialSlave/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModbusSerialSlave/README.md b/ModbusSerialSlave/README.md index 647f2c8..fad825e 100644 --- a/ModbusSerialSlave/README.md +++ b/ModbusSerialSlave/README.md @@ -28,7 +28,7 @@ This is the main library class. ### Constructor: ModbusSerialSlave(*slaveID, uart[, rts][, params]*) -Instantiate a new ModbusSerialSlave object and set the configuration of the UART bus over which it operates. The *slaveID* parameter takes an ID by which the master identifies this slave. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 coms when using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: +Instantiates a new ModbusSerialSlave object and configures the UART bus over which it operates. The *slaveID* parameter takes an ID by which the master identifies this slave. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 communications when you are using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: | Key | Default | Notes | | --- | --- | --- | From e8113ff26f1739f0daf686fc152a6c196581553f Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Wed, 21 Mar 2018 14:21:44 +0000 Subject: [PATCH 10/26] Update README.md - Change links to new Dev Center URLs - Minor tweaks --- ModbusSerialMaster/README.md | 233 +++++++++++++++++------------------ 1 file changed, 116 insertions(+), 117 deletions(-) diff --git a/ModbusSerialMaster/README.md b/ModbusSerialMaster/README.md index 8370dab..9a09436 100644 --- a/ModbusSerialMaster/README.md +++ b/ModbusSerialMaster/README.md @@ -11,44 +11,44 @@ This library allows an imp to communicate with other devices via the Modbus-RS48 #require "ModbusSerialMaster.device.lib.nut:2.0.0" ``` -## Hardware Setup +## Hardware Setup ## -The following instructions are applicable to Electric Imp’s [impAccelerator™ Fieldbus Gateway](https://electricimp.com/docs/hardware/resources/reference-designs/fieldbusgateway/). +The following instructions are applicable to Electric Imp’s [impAccelerator™ Fieldbus Gateway](https://developer.electricimp.com/hardware/resources/reference-designs/fieldbusgateway). 1. Connect the antenna to the Fieldbus Gateway 2. Wire RS485 A on the Fieldbus Gateway to port A / positive(+) on the other device 3. Wire RS485 B on the Fieldbus Gateway to port B / negative(-) on the other device 4. Wire both devices’ ground ports together -5. Fit [jumper J2](https://electricimp.com/docs/hardware/resources/reference-designs/fieldbusgateway/#rs-485) on the Fieldbus Gateway motherboard to enable RS485 +5. Fit [jumper J2](https://developer.electricimp.com/hardware/resources/reference-designs/fieldbusgateway#rs-485) on the Fieldbus Gateway motherboard to enable RS485 6. Power up the Fieldbus Gateway 7. Configure the Fieldbus Gateway for Internet access using BlinkUp™ -## ModbusSerialMaster Class Usage +## ModbusSerialMaster Class Usage ## This is the main library class. It implements most of the functions listed in the [Modbus specification](http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf). -### Constructor: ModbusSerialMaster(*uart[, rts][, params]*) +### Constructor: ModbusSerialMaster(*uart[, rts][, params]*) ### Instantiates a new ModbusSerialMaster object and configures the UART bus over which it operates. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 communications when you are using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: -| Key | Default | Notes | -| ------ | ----------- | ------------------------------------------------------------------------------- | -| baudRate | 19200 | The baud rate of the UART connection | -| dataBits | 8 | The word size on the UART connection in bits (7 or 8 bits) | -| parity | *PARITY_NONE* | Parity configuration of the UART connection | -| stopBits | 1 | Number of stop bits (1 or 2) on the UART connection | -| timeout | 1.0 | The maximum time allowed for one request | -| debug | `false` | If enabled, the outgoing and incoming ADU will be printed for debugging purpose | +| Key | Default | Notes | +| --- | --- | --- | +| *baudRate* | 19200 | The baud rate of the UART connection | +| *dataBits* | 8 | The word size on the UART connection in bits (7 or 8 bits) | +| *parity* | *PARITY_NONE* | Parity configuration of the UART connection | +| *stopBits* | 1 | Number of stop bits (1 or 2) on the UART connection | +| *timeout* | 1.0 | The maximum time allowed for one request | +| *debug* | `false` | If enabled, the outgoing and incoming ADU will be printed for debugging purpose | -#### Example +#### Example #### ```squirrel modbus <- ModbusSerialMaster(hardware.uart2, hardware.pinL); ``` -## ModbusSerialMaster Class Methods +## ModbusSerialMaster Class Methods ## -### read(*deviceAddress, targetType, startingAddress, quantity[, callback]*) +### read(*deviceAddress, targetType, startingAddress, quantity[, callback]*) ### Function Codes: 01, 02, 03, 04 @@ -60,7 +60,7 @@ This is a generic method used to read values from a single coil, register, or mu | *targetType* | Constant | Yes | N/A | Refer to the ‘Target Type’ table, below | | *startingAddress* | Integer | Yes | N/A | The address from which it begins reading values | | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are read from | -| *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *callback* | Function | No | `null` | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | | Target Type | Value | Access | | --- | --- | --- | @@ -69,37 +69,37 @@ This is a generic method used to read values from a single coil, register, or mu | Input Register | *MODBUSRTU_TARGET_TYPE.INPUT_REGISTER* | Read-Only | | Holding Register | *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER* | Read-Write | -#### Example +#### Example #### ```squirrel // Read from a single coil modbus.read(0x01, MODBUSRTU_TARGET_TYPE.COIL, 0x0001, 1, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } + if (error) { + server.error(error); + } else { + server.log(result); + } }.bindenv(this)); // Read from multiple registers modbus.read(0x01, MODBUSRTU_TARGET_TYPE.INPUT_REGISTER, 0x7000 , 2, function(error, results) { - if (error) { - server.error(error); - } else { - foreach(key, value in results) { - server.log(key + " : " + value); - } + if (error) { + server.error(error); + } else { + foreach(key, value in results) { + server.log(key + " : " + value); } + } }.bindenv(this)); ``` -### write(*deviceAddress, targetType, startingAddress, quantity, values[, callback]*) +### write(*deviceAddress, targetType, startingAddress, quantity, values[, callback]*) ### Function Codes: 05, 06, 15, 16 This is a generic method used to write values to multiple coils and registers. It takes the following parameters: -#### Parameters +#### Parameters #### | Parameter | Data Type | Required | Default Value | Description | | --- | --- | --- | --- | --- | @@ -107,55 +107,55 @@ This is a generic method used to write values to multiple coils and registers. I | *targetType* | Constant | Yes | N/A | Refer to the ‘Target Type’ table, above | | *startingAddress* | Integer | Yes | N/A | The address from which it begins writing values | | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are written into | -| *values* | Integer, array of integers, bool, Blob | Yes | N/A | The values written into Coils or Registers. Please view Notes below | -| *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *values* | Integer, array of integers, bool, blob | Yes | N/A | The values written into Coils or Registers. Please view Notes below | +| *callback* | Function | No | `null` | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | -#### Notes +#### Notes #### 1. Integer, blob and array[integer] are applicable to *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER*. Use an array[integer] only applicable when *quantity* is greater than one. 2. Integer, bool, blob and array[integer, bool] are applicable to *MODBUSRTU_TARGET_TYPE.COIL*. Use array[integer, bool] only applicable when *quantity* is greater than one. The integer value set to coils can be either 0x0000 or 0xFF00. Other values are ignored. -#### Example +#### Example #### ```squirrel // Write to a single coil modbus.write(0x01, MODBUSRTU_TARGET_TYPE.COIL, 8192, 1, true, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } + if (error) { + server.error(error); + } else { + server.log(result); + } }.bindenv(this)); // Write to multiple registers modbus.write(0x01, MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER, 9, 3, [188, 80, 18], function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } + if (error) { + server.error(error); + } else { + server.log(result); + } }.bindenv(this)); ``` -### readExceptionStatus(*deviceAddress[, callback]*) +### readExceptionStatus(*deviceAddress[, callback]*) ### Function Code: 07 This method reads the contents of eight Exception Status outputs in a remote device (address passed into the first parameter. If a callback is supplied, it will be triggered when a response regarding this request is received. The callback takes two parameters: *error* and *result*. -#### Example +#### Example #### ```squirrel modbus.readExceptionStatus(0x01, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } + if (error) { + server.error(error); + } else { + server.log(result); + } }.bindenv(this)); ``` -### diagnostics(*deviceAddress, subFunctionCode, data[, callback]*) +### diagnostics(*deviceAddress, subFunctionCode, data[, callback]*) ### Function Code: 08 @@ -166,7 +166,7 @@ This method provides a series of tests for checking the communication system bet | *deviceAddress* | Integer| Yes | N/A | The unique address that identifies a device | | *subFunctionCode* | Constant | Yes | N/A | Refer to the ‘Sub-function Code’ table, below | | *data* | Blob | Yes | N/A | The data field required by Modbus request | -| *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *callback* | Function | No | `null` | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | | Sub-function Code | Value (Hex) | | --- | --- | @@ -186,7 +186,7 @@ This method provides a series of tests for checking the communication system bet | *MODBUSRTU_SUB_FUNCTION_CODE.RETURN_BUS_CHARACTER_OVERRUN_COUNT* | 0x0012 | | *MODBUSRTU_SUB_FUNCTION_CODE.CLEAR_OVERRUN_COUNTER_AND_FLAG* | 0x0014 | -#### Example +#### Example #### ```squirrel local data = blob(2); @@ -194,34 +194,34 @@ data.writen(0xFF00, 'w'); data.swap2(); modbus.diagnostics(0x01, MODBUSRTU_SUB_FUNCTION_CODE.RESTART_COMMUNICATION_OPTION, data, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } + if (error) { + server.error(error); + } else { + server.log(result); + } }.bindenv(this)); ``` -### reportSlaveID(*deviceAddress[, callback]*) +### reportSlaveID(*deviceAddress[, callback]*) ### Function Code: 17 This method reads the description of the type, the current status and other information specific to a remote device whose address is specified in the method’s first parameter. The second, optional parameter is a function that will be fired when a response regarding this request is received. It takes two parameters, *error* and *result*. -#### Example +#### Example #### ```squirrel modbus.reportSlaveID(0x01, function(error, result) { - if (error) { - server.error(error); - } else { - server.log("Run indicator : " + result.runIndicator); - server.log(result.slaveId); - } + if (error) { + server.error(error); + } else { + server.log("Run indicator : " + result.runIndicator); + server.log(result.slaveId); + } }.bindenv(this)); ``` -### maskWriteRegister(*deviceAddress, referenceAddress, AND_Mask, OR_Mask[, callback]*) +### maskWriteRegister(*deviceAddress, referenceAddress, AND_Mask, OR_Mask[, callback]*) ### Function Code: 22 @@ -233,21 +233,21 @@ This method modifies the contents of a specified holding register using a combin | *referenceAddress* | Integer | Yes | N/A | The address of the holding register the value is written into | | *AND_mask* | Integer | Yes | N/A | The AND mask | | *OR_mask* | Integer | Yes | N/A | The OR mask | -| *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *callback* | Function | No | `null` | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | -#### Example +#### Example #### ```squirrel modbus.maskWriteRegister(0x01, 0x10, 0xFFFF, 0x0000, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } + if (error) { + server.error(error); + } else { + server.log(result); + } }.bindenv(this)); ``` -### readWriteMultipleRegisters(*deviceAddress, readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue[, callback]*) +### readWriteMultipleRegisters(*deviceAddress, readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue[, callback]*) ### Function Code: 23 @@ -261,26 +261,25 @@ This method performs a combination of one read operation and one write operation | *writeStartAddress* | Integer | Yes | N/A | The address from which it begins writing values | | *writeQuantity* | Integer | Yes | N/A | The number of consecutive addresses values are written into | | *writeValue* | Blob | Yes | N/A | The value written into the holding register | -| *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *callback* | Function | No | `null` | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | **Note** The actual order of operation is determined by the implementation of user's device. - -#### Example +#### Example #### ```squirrel modbus.readWriteMultipleRegisters(0x01, 9, 3, 9, 3, [188, 80, 18], function(error, result) { - if (error) { - errorMessage(error, resolve, reject); - } else { - foreach(key, value in results) { - server.log(key + " : " + value); - } + if (error) { + errorMessage(error, resolve, reject); + } else { + foreach(key, value in results) { + server.log(key + " : " + value); } + } }.bindenv(this)); ``` -### readDeviceIdentification(*deviceAddress, readDeviceIdCode, objectId[, callback]*) +### readDeviceIdentification(*deviceAddress, readDeviceIdCode, objectId[, callback]*) ### Function Code: 43/14 @@ -291,7 +290,7 @@ This method lets you read the identification and additional information relative | *deviceAddress* | Integer | Yes | N/A | The unique address that identifies a device | | *readDeviceIdCode* | Constant| Yes | N/A | Refer to the ‘Read Device ID Code’ table, below | | *objectId* | Constant | Yes | N/A | Refer to the ‘Object ID’ table, below | -| *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *callback* | Function | No | `null` | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | | Read Device ID Code | Description | | --- | --- | @@ -310,44 +309,44 @@ This method lets you read the identification and additional information relative | *MODBUSRTU_OBJECT_ID.MODEL_NAME* | Regular | | *MODBUSRTU_OBJECT_ID.USER_APPLICATION_NAME* | Regular | -#### Example +#### Example #### ```squirrel modbus.readDeviceIdentification(0x01, MODBUSRTU_READ_DEVICE_CODE.BASIC, MODBUSRTU_OBJECT_ID.VENDOR_NAME, function(error, objects) { - if (error) { - server.error("Error: " + error + ", Objects: " + objects); - } else { - local info = "DeviceId: "; - foreach (id, val in objects) { - info += format("[%d] %s, ", id, val.tostring()); - } - server.log(info); + if (error) { + server.error("Error: " + error + ", Objects: " + objects); + } else { + local info = "DeviceId: "; + foreach (id, val in objects) { + info += format("[%d] %s, ", id, val.tostring()); } + server.log(info); + } }.bindenv(this)); ``` -## Exception Codes +## Exception Codes ## The table below enumerates all the exception codes that can be possibly encountered. Refer to [Modbus specification](http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf) for more detailed description on Modbus-specific exceptions. -| Value (Dec) | Description | -| ------------- | ----------------------- | -| 1 | Illegal Function | -| 2 | Illegal Data Address | -| 3 | Illegal Data Value | -| 4 | Slave Device Fail | -| 5 | Acknowledge | -| 6 | Slave Device Busy | -| 7 | Negative Acknowledge | -| 8 | Memory Parity Error | -| 80 | Response Timeout | -| 81 | Invalid CRC | -| 82 | Invalid Argument Length | -| 83 | Invalid Device Address | -| 87 | Invalid Target Type | -| 88 | Invalid Values | -| 89 | Invalid Quantity | - -## License +| Value (Dec) | Description | +| --- | --- | +| 1 | Illegal Function | +| 2 | Illegal Data Address | +| 3 | Illegal Data Value | +| 4 | Slave Device Fail | +| 5 | Acknowledge | +| 6 | Slave Device Busy | +| 7 | Negative Acknowledge | +| 8 | Memory Parity Error | +| 80 | Response Timeout | +| 81 | Invalid CRC | +| 82 | Invalid Argument Length | +| 83 | Invalid Device Address | +| 87 | Invalid Target Type | +| 88 | Invalid Values | +| 89 | Invalid Quantity | + +## License ## The ModbusSerialMaster library is licensed under the [MIT License](../LICENSE). From 81242c01f106128a8d22dbc736f414104e7c2148 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Wed, 21 Mar 2018 14:23:57 +0000 Subject: [PATCH 11/26] Update README.md - Change links to new Dev Center URLs - Minor tweaks --- ModbusSerialSlave/README.md | 100 ++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/ModbusSerialSlave/README.md b/ModbusSerialSlave/README.md index fad825e..7058136 100644 --- a/ModbusSerialSlave/README.md +++ b/ModbusSerialSlave/README.md @@ -1,6 +1,6 @@ -# ModbusSerialSlave +# ModbusSerialSlave # -This library empowers an imp to communicate with the Modbus Master via the RS485 or RS232 protocol. +This library empowers an imp to communicate with the Modbus Master via the Modbus-RS485 or Modbus-RS232 protocol. **To use this library, add the following statements to the top of your device code:** @@ -10,23 +10,23 @@ This library empowers an imp to communicate with the Modbus Master via the RS485 #require "ModbusSerialSlave.device.lib.nut:2.0.0" ``` -## Hardware Setup +## Hardware Setup ## -The following instructions are applicable to Electric Imp’s [impAccelerator™ Fieldbus Gateway](https://electricimp.com/docs/hardware/resources/reference-designs/fieldbusgateway/). +The following instructions are applicable to Electric Imp’s [impAccelerator™ Fieldbus Gateway](https://developer.electricimp.com/hardware/resources/reference-designs/fieldbusgateway). 1. Connect the antenna to the Fieldbus Gateway 2. Wire RS485 A on the Fieldbus Gateway to port A / positive(+) on the other device 3. Wire RS485 B on the Fieldbus Gateway to port B / negative(-) on the other device 4. Wire both devices’ ground ports together -5. Fit [jumper J2](https://electricimp.com/docs/hardware/resources/reference-designs/fieldbusgateway/#rs-485) on the Fieldbus Gateway motherboard to enable RS485 +5. Fit [jumper J2](https://developer.electricimp.com/hardware/resources/reference-designs/fieldbusgateway#rs-485) on the Fieldbus Gateway motherboard to enable RS485 6. Power up the Fieldbus Gateway 7. Configure the Fieldbus Gateway for Internet access using BlinkUp™ -## ModbusSerialSlave Class Usage +## ModbusSerialSlave Class Usage ## This is the main library class. -### Constructor: ModbusSerialSlave(*slaveID, uart[, rts][, params]*) +### Constructor: ModbusSerialSlave(*slaveID, uart[, rts][, params]*) ### Instantiates a new ModbusSerialSlave object and configures the UART bus over which it operates. The *slaveID* parameter takes an ID by which the master identifies this slave. The *uart* parameter is an imp UART object. The optional *rts* parameter should be used for RS485 communications when you are using an imp GPIO pin for control flow. The *params* parameter is optional and takes a table containing the following keys: @@ -38,23 +38,23 @@ Instantiates a new ModbusSerialSlave object and configures the UART bus over whi | stopBits | 1 | Number of stop bits (1 or 2) on the UART connection | | debug | `false` | If enabled, the outgoing and incoming ADU will be printed for debugging purpose | -#### Example +#### Example #### ```squirrel modbus <- Modbus485Slave(1, hardware.uart2, hardware.pinL); ``` -### setSlaveID(*slaveID*) +### setSlaveID(*slaveID*) ### This method changes the slave ID. Its single parameter takes the new slave ID. -#### Example +#### Example #### ```squirrel modbus.setSlaveID(2); ``` -### onWrite(*callback*) +### onWrite(*callback*) ### This method sets the callback function that will be triggered when there is a write request. The callback takes the following parameters: @@ -66,7 +66,7 @@ This method sets the callback function that will be triggered when there is a wr | *quantity* | Integer | The quantity of the values | | *values* | Integer, bool, array | The values to be written | -#### Accepted Return Value Types +#### Accepted Return Value Types #### The callback function can return a value, which will be processed and sent back to the Master as a response. @@ -76,38 +76,38 @@ The callback function can return a value, which will be processed and sent back | `null` | If `null` is returned, it is the same as returning `true` | | Integer | Any acceptable Modbus Exception Code can be returned | -#### Example +#### Example #### ```squirrel // Accept this write request modbus.onWrite(function(slaveID, functionCode, startingAddress, quantity, values) { - server.log("slaveID : " + slaveID); - server.log("functionCode : " + functionCode); - server.log("startingAddress : " + startingAddress); - server.log("Quantity : " + quantity); - server.log("Values : \n"); - foreach (index, value in values) { - server.log("\t" + index + " : " + value); - } - return true; + server.log("slaveID : " + slaveID); + server.log("functionCode : " + functionCode); + server.log("startingAddress : " + startingAddress); + server.log("Quantity : " + quantity); + server.log("Values : \n"); + foreach (index, value in values) { + server.log("\t" + index + " : " + value); + } + return true; }.bindenv(this)); // Decline this write request modbus.onWrite(function(slaveID, functionCode, startingAddress, quantity, values) { - server.log("slaveID : " + slaveID); - server.log("functionCode : " + functionCode); - server.log("startingAddress : " + startingAddress); - server.log("Quantity : " + quantity); - server.log("Values : \n"); - foreach (index, value in values) { - server.log("\t" + index + " : " + value); - } - // reject this request with the exception code of 2 - return 2; + server.log("slaveID : " + slaveID); + server.log("functionCode : " + functionCode); + server.log("startingAddress : " + startingAddress); + server.log("Quantity : " + quantity); + server.log("Values : \n"); + foreach (index, value in values) { + server.log("\t" + index + " : " + value); + } + // reject this request with the exception code of 2 + return 2; }.bindenv(this)); ``` -### onRead(*callback*) +### onRead(*callback*) ### This method sets the callback function that will be called when there is a read request. The callback takes the following parameters: @@ -118,7 +118,7 @@ This method sets the callback function that will be called when there is a read | *startingAddress* | Integer | The address at which it starts writing values | | *quantity* | Integer | The quantity of the values | -#### Accepted Return Value Type +#### Accepted Return Value Type #### The callback function can return a value, which will be processed and sent back to the Master as a response. @@ -129,37 +129,37 @@ The callback function can return a value, which will be processed and sent back | Integer | 1 or 0 when it is a coil or discrete input read. Any number when it is a holding register or input register read | | Array | Array of 1, 0, `true`, `false` when it is a coil or discrete input read. Array of integers when it is a holding register or input register read | -#### Example +#### Example #### ```squirrel // A coil read example modbus.onRead(function(slaveID, functionCode, startingAddress, quantity){ - server.log("slaveID : " + slaveID); - server.log("functionCode : " + functionCode); - server.log("startingAddress : " + startingAddress); - server.log("Quantity : " + quantity); - return [true,false,false,true,true]; + server.log("slaveID : " + slaveID); + server.log("functionCode : " + functionCode); + server.log("startingAddress : " + startingAddress); + server.log("Quantity : " + quantity); + return [true,false,false,true,true]; }.bindenv(this)); // A holding register read example modbus.onRead(function(slaveID, functionCode, startingAddress, quantity){ - server.log("slaveID : " + slaveID); - server.log("functionCode : " + functionCode); - server.log("startingAddress : " + startingAddress); - server.log("Quantity : " + quantity); - return [18,29,30, 59, 47]; + server.log("slaveID : " + slaveID); + server.log("functionCode : " + functionCode); + server.log("startingAddress : " + startingAddress); + server.log("Quantity : " + quantity); + return [18,29,30, 59, 47]; }.bindenv(this)); ``` -### onError(*callback*) +### onError(*callback*) ### This method sets the callback function that will be called when there is an error. The callback takes a single parameter into which a description of the error is passed. -#### Example +#### Example #### ```squirrel modbus.onError(function(error){ - server.error(error); + server.error(error); }.bindenv(this)); ``` @@ -178,7 +178,7 @@ The following table lists the function codes that the slave can support and proc | 0x0F | Write Multiple Coils | | 0x10 | Write Multiple Registers | -## Exception Codes +## Exception Codes ## The table below enumerates all the exception codes that can be possibly encountered. Refer to the [Modbus specification](http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf) for more detailed description on Modbus-specific exceptions. @@ -193,6 +193,6 @@ The table below enumerates all the exception codes that can be possibly encounte | 7 | Negative Acknowledge | | 8 | Memory Parity Error | -# License +# License ## The ModbusSerialSlave library is licensed under the [MIT License](../LICENSE). From 6ff9fd47a7490cfece1bf95368d3cde5ffd60bc4 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Wed, 21 Mar 2018 14:24:27 +0000 Subject: [PATCH 12/26] Update README.md - Minor tweak --- ModbusSerialMaster/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModbusSerialMaster/README.md b/ModbusSerialMaster/README.md index 9a09436..2cfeb44 100644 --- a/ModbusSerialMaster/README.md +++ b/ModbusSerialMaster/README.md @@ -1,4 +1,4 @@ -# ModbusSerialMaster +# ModbusSerialMaster # This library allows an imp to communicate with other devices via the Modbus-RS485 or Modbus-RS232 protocol. From ee81e7102568b0ba2ab548129a73897c3c0879df Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Wed, 21 Mar 2018 14:29:11 +0000 Subject: [PATCH 13/26] Update README.md - Update links to new Dev Center URLs --- ModbusTCPMaster/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index d7f9830..1cadc11 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -11,13 +11,13 @@ This library allows an imp to communicate with other devices via TCP/IP. It requ #require "W5500.device.nut:1.0.0" ``` -The following instructions are applicable to Electric Imp’s [impAccelerator™ Fieldbus Gateway](https://electricimp.com/docs/hardware/resources/reference-designs/fieldbusgateway/). +The following instructions are applicable to Electric Imp’s [impAccelerator™ Fieldbus Gateway](https://developer.electricimp.com/hardware/resources/reference-designs/fieldbusgateway). 1. Connect the antenna to the Fieldbus Gateway 2. Wire RS485 A on the Fieldbus Gateway to port A / positive(+) on the other device 3. Wire RS485 B on the Fieldbus Gateway to port B / negative(-) on the other device 4. Wire both devices’ ground ports together -5. Fit [jumper J2](https://electricimp.com/docs/hardware/resources/reference-designs/fieldbusgateway/#rs-485) on the Fieldbus Gateway motherboard to enable RS485 +5. Fit [jumper J2](https://developer.electricimp.com/hardware/resources/reference-designs/fieldbusgateway#rs-485) on the Fieldbus Gateway motherboard to enable RS485 6. Power up the Fieldbus Gateway 7. Configure the Fieldbus Gateway for Internet access using BlinkUp™ From d845bcc68efc8449a08e711d3f76d6fb4ca9dd38 Mon Sep 17 00:00:00 2001 From: Alexey Liubimtsev Date: Thu, 17 Dec 2020 23:49:35 +0400 Subject: [PATCH 14/26] Add Device Address as last parameter --- .../ModbusTCPMaster.device.lib.nut | 112 +++++++++++++++++- ModbusTCPMaster/README.md | 26 ++-- ModbusTCPMaster/example/device.example.nut | 2 +- ModbusTCPMaster/tests/device.test.nut | 46 +++---- 4 files changed, 151 insertions(+), 35 deletions(-) diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index 05d3720..c1adcf8 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusTCPMaster extends ModbusMaster { - static VERSION = "1.0.1"; + static VERSION = "1.0.2"; static MAX_TRANSACTION_COUNT = 65535; _transactions = null; _wiz = null; @@ -33,6 +33,7 @@ class ModbusTCPMaster extends ModbusMaster { _shouldRetry = null; _connectCallback = null; _reconnectCallback = null; + _deviceAddress = null; // // Constructor for ModbusTCPMaster @@ -77,6 +78,113 @@ class ModbusTCPMaster extends ModbusMaster { _connection.close(callback); } + // + // This function performs a combination of one read operation and one write operation in a single MODBUS transaction. The write operation is performed before the read. + // + // @param {integer} readingStartAddress - The address from which it begins reading values + // @param {integer} readQuantity - The number of consecutive addresses values are read from + // @param {integer} writeStartAddress - The address from which it begins writing values + // @param {integer} writeQuantity - The number of consecutive addresses values are written into + // @param {blob} writeValue - The value written into the holding register + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function readWriteMultipleRegisters(readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue, callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.readWriteMultipleRegisters(readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue, callback); + } + + // + // This function modifies the contents of a specified holding register using a combination of an AND mask, an OR mask, and the register's current contents. The function can be used to set or clear individual bits in the register. + // + // @param {integer} referenceAddress - The address of the holding register the value is written into + // @param {integer} AND_mask - The AND mask + // @param {integer} OR_mask - The OR mask + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function maskWriteRegister(referenceAddress, AND_Mask, OR_Mask, callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.maskWriteRegister(referenceAddress, AND_Mask, OR_Mask, callback); + } + + // + // This function reads the description of the type, the current status, and other information specific to a remote device. + // + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function reportSlaveID(callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.reportSlaveID(callback); + } + + // + // This function allows reading the identification and additional information relative to the physical and functional description of a remote device, only. + // + // @param {enum} readDeviceIdCode - read device id code + // @param {enum} objectId - object id + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function readDeviceIdentification(readDeviceIdCode, objectId, callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.readDeviceIdentification(readDeviceIdCode, objectId, callback); + } + + // + // This function provides a series of tests for checking the communication system between a client ( Master) device and a server ( Slave), or for checking various internal error conditions within a server. + // + // @param {integer} subFunctionCode - The address from which it begins reading values + // @param {blob} data - The data field required by Modbus request + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function diagnostics(subFunctionCode, data, callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.diagnostics(subFunctionCode, data, callback); + } + + // + // This function reads the contents of eight Exception Status outputs in a remote device + // + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function readExceptionStatus(callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.readExceptionStatus(callback); + } + + // + // This is the generic function to read values from a single coil ,register or multiple coils , registers . + // + // @param {enum} targetType - The address from which it begins reading values + // @param {integer} startingAddress - The address from which it begins reading values + // @param {integer} quantity - The number of consecutive addresses the values are read from + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function read(targetType, startingAddress, quantity, callback, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.read(targetType, startingAddress, quantity, callback); + } + + // + // This is the generic function to write values into coils or holding registers . + // + // @param {enum} targetType - The address from which it begins reading values + // @param {integer} startingAddress - The address from which it begins writing values + // @param {integer} quantity - The number of consecutive addresses the values are written into + // @param {integer, Array[integer,Bool], Bool, blob} values - The values written into Coils or Registers + // @param {function} callback - The function to be fired when it receives response regarding this request + // @param {integer} deviceAddress - The unique address that identifies a device + // + function write(targetType, startingAddress, quantity, values, callback = null, deviceAddress = 0) { + _deviceAddress = deviceAddress; + base.write(targetType, startingAddress, quantity, values, callback); + } + // // The callback function to be fired when the connection is established // @@ -140,7 +248,7 @@ class ModbusTCPMaster extends ModbusMaster { ADU.writen(swap2(_transactionCount), 'w'); ADU.writen(swap2(0x0000), 'w'); ADU.writen(swap2(PDU.len() + 1), 'w'); - ADU.writen(0x00, 'b'); + ADU.writen(_deviceAddress, 'b'); ADU.writeblob(PDU); return ADU; } diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index 1cadc11..bb35606 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -7,7 +7,7 @@ This library allows an imp to communicate with other devices via TCP/IP. It requ ``` #require "ModbusRTU.device.lib.nut:1.0.1" #require "ModbusMaster.device.lib.nut:1.0.1" -#require "ModbusTCPMaster.device.lib.nut:1.0.1" +#require "ModbusTCPMaster.device.lib.nut:1.0.2" #require "W5500.device.nut:1.0.0" ``` @@ -89,7 +89,7 @@ This method closes the existing TCP connection. It takes one optional parameter: modbus.disconnect(); ``` -### read(*targetType, startingAddress, quantity[, callback]*) +### read(*targetType, startingAddress, quantity[, callback][, deviceAddress]*) Function Code : 01, 02, 03, 04 @@ -101,6 +101,7 @@ This is a generic method used to read values from a single coil, register, or mu | *startingAddress* | Integer | Yes | N/A | The address from which it begins reading values | | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are read from | | *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *deviceAddress* | Integer | No | 0x00 | The unique address that identifies a device | | Target Type | Value | Access | | --- | --- | --- | @@ -133,7 +134,7 @@ modbus.read(MODBUSRTU_TARGET_TYPE.INPUT_REGISTER, 0x01 , 5, function(error, resu }.bindenv(this)); ``` -### write(*targetType, startingAddress, quantity, values[, callback]*) +### write(*targetType, startingAddress, quantity, values[, callback][, deviceAddress]*) Function Code : 05, 06, 15, 16 @@ -146,6 +147,7 @@ This is a generic method used to write values into coils or registers. It has th | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are written into | | *values* | Integer, array, bool, blob | Yes | N/A | The values written into Coils or Registers. Please view ‘Notes’, below | | *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *deviceAddress* | Integer | No | 0x00 | The unique address that identifies a device | #### Notes: @@ -177,7 +179,7 @@ modbus.write(MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER, 0x01, 5, [false, true, fals }.bindenv(this)); ``` -### readExceptionStatus(*[callback]*) +### readExceptionStatus(*[callback][, deviceAddress]*) Function Code : 07 @@ -195,7 +197,7 @@ modbus.readExceptionStatus(function(error, result) { }.bindenv(this)); ``` -### diagnostics(*subFunctionCode, data[, callback]*) +### diagnostics(*subFunctionCode, data[, callback][, deviceAddress]*) Function Code : 08 @@ -206,6 +208,7 @@ This method provides a series of tests for checking the communication system bet | *subFunctionCode* | Constant | Yes | N/A | Refer to the ‘Sub-function Code’ table, below | | *data* | Blob | Yes | N/A | The data field required by Modbus request | | *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *deviceAddress* | Integer | No | 0x00 | The unique address that identifies a device | | Sub-function Code | Value (Hex) | | --- | --- | @@ -241,11 +244,11 @@ modbus.diagnostics(MODBUSRTU_SUB_FUNCTION_CODE.RESTART_COMMUNICATION_OPTION, dat }.bindenv(this)); ``` -### reportSlaveID(*[callback]*) +### reportSlaveID(*[callback][, deviceAddress]*) Function Code : 17 -This method reads the description of the type, the current status, and other information specific to a remote device. The optional callback function will, if supplied, be fired when a response regarding this request is received. The callback takes two parameters, *error* and *result*. +This method reads the description of the type, the current status, and other information specific to a remote device whose address is specified in the method’s last parameter. The optional callback function will, if supplied, be fired when a response regarding this request is received. The callback takes two parameters, *error* and *result*. #### Example @@ -260,7 +263,7 @@ modbus.reportSlaveID(function(error, result) { }.bindenv(this)); ``` -### maskWriteRegister(*referenceAddress, AND_Mask, OR_Mask[, callback]*) +### maskWriteRegister(*referenceAddress, AND_Mask, OR_Mask[, callback][, deviceAddress]*) Function Code : 22 @@ -272,6 +275,7 @@ This method modifies the contents of a specified holding register using a combin | *AND_mask* | Integer | Yes | N/A | The AND mask | | *OR_mask* | Integer | Yes | N/A | The OR mask | | *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *deviceAddress* | Integer | No | 0x00 | The unique address that identifies a device | #### Example @@ -285,7 +289,7 @@ modbus.maskWriteRegister(0x10, 0xFFFF, 0x0000, function(error, result) { }.bindenv(this)); ``` -### readWriteMultipleRegisters(*readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue, [callback]*) +### readWriteMultipleRegisters(*readingStartAddress, readQuantity, writeStartAddress, writeQuantity, writeValue[, callback][, deviceAddress]*) Function Code : 23 @@ -299,6 +303,7 @@ This method performs a combination of one read operation and one write operation | *writeQuantity* | Integer | Yes | N/A | The number of consecutive addresses values are written into | | *writeValue* | Blob | Yes | N/A | The value written into the holding register | | *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *deviceAddress* | Integer | No | 0x00 | The unique address that identifies a device | **Note** The actual order of operation is determined by the implementation of user's device. @@ -317,7 +322,7 @@ modbus.readWriteMultipleRegisters(0x0A, 2, 0x0A, 2, [28, 88], function(error, re ``` -### readDeviceIdentification(*readDeviceIdCode, objectId, [callback]*) +### readDeviceIdentification(*readDeviceIdCode, objectId[, callback][, deviceAddress]*) Function Code : 43/14 @@ -328,6 +333,7 @@ This method lets you read the identification and additional information relative | *readDeviceIdCode* | Constant| Yes | N/A | Refer to the ‘Read Device ID’ table, below | | *objectId* | Constant | Yes | N/A | Refer to the ‘Object ID’ table, below | | *callback* | Function | No | Null | The function to be fired when it receives response regarding this request. It takes two parameters, *error* and *result* | +| *deviceAddress* | Integer | No | 0x00 | The unique address that identifies a device | | Read Device ID Code | Description | | --- | --- | diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index 6651e72..0ffc9d3 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -25,7 +25,7 @@ #require "W5500.device.nut:1.0.0" #require "ModbusRTU.device.lib.nut:1.0.1" #require "ModbusMaster.device.lib.nut:1.0.1" -#require "ModbusTCPMaster.device.lib.nut:1.0.1" +#require "ModbusTCPMaster.device.lib.nut:1.0.2" // this example shows how to use readWriteMultipleRegisters diff --git a/ModbusTCPMaster/tests/device.test.nut b/ModbusTCPMaster/tests/device.test.nut index f561345..eaa36ae 100644 --- a/ModbusTCPMaster/tests/device.test.nut +++ b/ModbusTCPMaster/tests/device.test.nut @@ -43,6 +43,8 @@ function errorMessage(error, resolve, reject) { } } +const DEVICE_ADDRESS = 0x00; + class DeviceTestCase extends ImpTestCase { _wiz = null; @@ -82,7 +84,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result.len() == 2); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -97,7 +99,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue((result == 0 || result == 0xFF) ? true : false); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -114,7 +116,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(data.tostring() == result.tostring()); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -129,7 +131,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -151,7 +153,7 @@ class DeviceTestCase extends ImpTestCase { } resolve(message); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -170,7 +172,7 @@ class DeviceTestCase extends ImpTestCase { } resolve(message); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -188,7 +190,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -206,7 +208,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -224,7 +226,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -242,7 +244,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -260,7 +262,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -278,7 +280,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -296,7 +298,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -316,7 +318,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result); resolve(PASS_MESSAGE); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -337,7 +339,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result.len() == quantity); resolve(message); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -358,7 +360,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result.len() == quantity); resolve(message); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -379,7 +381,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result.len() == quantity); resolve(message); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -400,7 +402,7 @@ class DeviceTestCase extends ImpTestCase { this.assertTrue(result.len() == quantity); resolve(message); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -417,7 +419,7 @@ class DeviceTestCase extends ImpTestCase { } else { reject(error); } - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -435,13 +437,13 @@ class DeviceTestCase extends ImpTestCase { resolve(PASS_MESSAGE); } isSuccess = true; - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); _modbus.write(MODBUSRTU_TARGET_TYPE.COIL, address, quantity, value, function(error, result) { if (isSuccess) { resolve(PASS_MESSAGE); } isSuccess = true; - }.bindenv(this)); + }.bindenv(this), DEVICE_ADDRESS); }.bindenv(this)); }.bindenv(this)); } @@ -451,4 +453,4 @@ class DeviceTestCase extends ImpTestCase { return "Connection closed"; } -} +} \ No newline at end of file From d02fad8fa47ef0bb9c8aaa0d657bacd47d6b96ca Mon Sep 17 00:00:00 2001 From: alexey-nbl Date: Sat, 19 Dec 2020 18:41:28 +0300 Subject: [PATCH 15/26] Update ModbusTCPMaster.device.lib.nut --- .../ModbusTCPMaster.device.lib.nut | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index c1adcf8..faf07f7 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -1,6 +1,6 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-2020 Electric Imp // // SPDX-License-Identifier: MIT // @@ -79,7 +79,8 @@ class ModbusTCPMaster extends ModbusMaster { } // - // This function performs a combination of one read operation and one write operation in a single MODBUS transaction. The write operation is performed before the read. + // This function performs a combination of one read operation and one write operation in a single MODBUS transaction. + // The write operation is performed before the read. // // @param {integer} readingStartAddress - The address from which it begins reading values // @param {integer} readQuantity - The number of consecutive addresses values are read from @@ -95,7 +96,9 @@ class ModbusTCPMaster extends ModbusMaster { } // - // This function modifies the contents of a specified holding register using a combination of an AND mask, an OR mask, and the register's current contents. The function can be used to set or clear individual bits in the register. + // This function modifies the contents of a specified holding register using a combination of an AND mask, + // an OR mask, and the register's current contents. + // The function can be used to set or clear individual bits in the register. // // @param {integer} referenceAddress - The address of the holding register the value is written into // @param {integer} AND_mask - The AND mask @@ -120,7 +123,8 @@ class ModbusTCPMaster extends ModbusMaster { } // - // This function allows reading the identification and additional information relative to the physical and functional description of a remote device, only. + // This function allows reading the identification and additional information relative to the physical + // and functional description of a remote device. // // @param {enum} readDeviceIdCode - read device id code // @param {enum} objectId - object id @@ -133,9 +137,10 @@ class ModbusTCPMaster extends ModbusMaster { } // - // This function provides a series of tests for checking the communication system between a client ( Master) device and a server ( Slave), or for checking various internal error conditions within a server. + // This function provides a series of tests for checking the communication system between a client (Master) device + // and a server (Slave), or for checking various internal error conditions within a server. // - // @param {integer} subFunctionCode - The address from which it begins reading values + // @param {integer} subFunctionCode - The Sub-function Code // @param {blob} data - The data field required by Modbus request // @param {function} callback - The function to be fired when it receives response regarding this request // @param {integer} deviceAddress - The unique address that identifies a device @@ -157,9 +162,9 @@ class ModbusTCPMaster extends ModbusMaster { } // - // This is the generic function to read values from a single coil ,register or multiple coils , registers . + // This is the generic function to read values from a single coil register or multiple coils registers. // - // @param {enum} targetType - The address from which it begins reading values + // @param {enum} targetType - The Target Type // @param {integer} startingAddress - The address from which it begins reading values // @param {integer} quantity - The number of consecutive addresses the values are read from // @param {function} callback - The function to be fired when it receives response regarding this request @@ -171,9 +176,9 @@ class ModbusTCPMaster extends ModbusMaster { } // - // This is the generic function to write values into coils or holding registers . + // This is the generic function to write values into coils or holding registers. // - // @param {enum} targetType - The address from which it begins reading values + // @param {enum} targetType - The Target Type // @param {integer} startingAddress - The address from which it begins writing values // @param {integer} quantity - The number of consecutive addresses the values are written into // @param {integer, Array[integer,Bool], Bool, blob} values - The values written into Coils or Registers From 516e760184236bff57c0c8146b34f8bb6cbf8e0f Mon Sep 17 00:00:00 2001 From: alexey-nbl Date: Sat, 19 Dec 2020 18:46:31 +0300 Subject: [PATCH 16/26] Update device.test.nut --- ModbusTCPMaster/tests/device.test.nut | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ModbusTCPMaster/tests/device.test.nut b/ModbusTCPMaster/tests/device.test.nut index eaa36ae..5ae3834 100644 --- a/ModbusTCPMaster/tests/device.test.nut +++ b/ModbusTCPMaster/tests/device.test.nut @@ -1,6 +1,6 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-2020 Electric Imp // // SPDX-License-Identifier: MIT // @@ -453,4 +453,4 @@ class DeviceTestCase extends ImpTestCase { return "Connection closed"; } -} \ No newline at end of file +} From 9812db14994a032d3b4ae5438d16e8e1bd4c45c1 Mon Sep 17 00:00:00 2001 From: Alexey Liubimtsev Date: Sun, 20 Dec 2020 13:15:43 +0400 Subject: [PATCH 17/26] Increased minor version, added TODO --- ModbusTCPMaster/ModbusTCPMaster.device.lib.nut | 4 +++- ModbusTCPMaster/README.md | 2 +- ModbusTCPMaster/example/device.example.nut | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index faf07f7..92ea87f 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusTCPMaster extends ModbusMaster { - static VERSION = "1.0.2"; + static VERSION = "1.1.0"; static MAX_TRANSACTION_COUNT = 65535; _transactions = null; _wiz = null; @@ -33,6 +33,8 @@ class ModbusTCPMaster extends ModbusMaster { _shouldRetry = null; _connectCallback = null; _reconnectCallback = null; + //TODO Passing methods' parameters via class fields is not a good pattern. + //TODO But the base class ModbusMaster must be redesigned to get rid of this pattern. _deviceAddress = null; // diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index bb35606..2f6edf3 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -7,7 +7,7 @@ This library allows an imp to communicate with other devices via TCP/IP. It requ ``` #require "ModbusRTU.device.lib.nut:1.0.1" #require "ModbusMaster.device.lib.nut:1.0.1" -#require "ModbusTCPMaster.device.lib.nut:1.0.2" +#require "ModbusTCPMaster.device.lib.nut:1.1.0" #require "W5500.device.nut:1.0.0" ``` diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index 0ffc9d3..44f38ab 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -1,6 +1,6 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-2020 Electric Imp // // SPDX-License-Identifier: MIT // @@ -25,7 +25,7 @@ #require "W5500.device.nut:1.0.0" #require "ModbusRTU.device.lib.nut:1.0.1" #require "ModbusMaster.device.lib.nut:1.0.1" -#require "ModbusTCPMaster.device.lib.nut:1.0.2" +#require "ModbusTCPMaster.device.lib.nut:1.1.0" // this example shows how to use readWriteMultipleRegisters From 2faf2ff9430a594eeefb0b3eae022538f9bac98f Mon Sep 17 00:00:00 2001 From: alexey-nbl Date: Sun, 20 Dec 2020 12:29:03 +0300 Subject: [PATCH 18/26] Update ModbusTCPMaster.device.lib.nut --- ModbusTCPMaster/ModbusTCPMaster.device.lib.nut | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index 92ea87f..7b491cc 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -33,8 +33,8 @@ class ModbusTCPMaster extends ModbusMaster { _shouldRetry = null; _connectCallback = null; _reconnectCallback = null; - //TODO Passing methods' parameters via class fields is not a good pattern. - //TODO But the base class ModbusMaster must be redesigned to get rid of this pattern. + // NOTE: Passing methods' parameters via class fields is not a good pattern. + // But the base class ModbusMaster must be redesigned to get rid of this pattern. _deviceAddress = null; // From ab776b92619d089192477a398f31b1e8bf5c8ae3 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Mon, 18 Jul 2022 10:11:23 +1000 Subject: [PATCH 19/26] Add library usage recommendation note --- ModbusRTU/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 6ad0243..2f8ff2f 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -2,6 +2,11 @@ This library creates and parses Modbus Protocol Data Units (PDU). It depends on Electric Imp's [CRC16 library](https://github.com/electricimp/CRC16) to calculate the [CRC-16](https://en.wikipedia.org/wiki/Cyclic_redundancy_check) value of a string or blob. +**Note** You will not usually work with this library directly, but load it as a dependency for one of our other Modbus libraries: + +* [ModbusSerialMaster](../ModbusMaster) +* [ModbusTCPMaster](../ModbusSerialMaster) + **To use this library, add the following statements to the top of your device code:** ``` From c4af39e3cf99c1df8d1eb074fffee34b6b72871b Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Mon, 18 Jul 2022 10:13:51 +1000 Subject: [PATCH 20/26] Ditto --- ModbusRTU/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 2f8ff2f..f3d5e6d 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -2,7 +2,7 @@ This library creates and parses Modbus Protocol Data Units (PDU). It depends on Electric Imp's [CRC16 library](https://github.com/electricimp/CRC16) to calculate the [CRC-16](https://en.wikipedia.org/wiki/Cyclic_redundancy_check) value of a string or blob. -**Note** You will not usually work with this library directly, but load it as a dependency for one of our other Modbus libraries: +**Note** You will not usually work with this library directly, but load it as a dependency for one of our other Modbus libraries, which target specific use cases: * [ModbusSerialMaster](../ModbusMaster) * [ModbusTCPMaster](../ModbusSerialMaster) From 898f436c61eb07443fffbf7d06a03d4b254c254b Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Mon, 18 Jul 2022 10:16:40 +1000 Subject: [PATCH 21/26] Finalize recommendation --- ModbusRTU/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index f3d5e6d..17d9e10 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -7,6 +7,8 @@ This library creates and parses Modbus Protocol Data Units (PDU). It depends on * [ModbusSerialMaster](../ModbusMaster) * [ModbusTCPMaster](../ModbusSerialMaster) +We recommend you work with one of these libraries unless your use case very specifically needs to perform PDU operations not provided by them. + **To use this library, add the following statements to the top of your device code:** ``` From 7477a2c94d82f749e738f91c2007bfcd81e55755 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Tue, 30 Aug 2022 11:19:24 +0100 Subject: [PATCH 22/26] Fix createReadPUD(), createWritePDU() targetTYpe parameter parsing Map input param constant to PDU FUNCTION_CODE entries --- ModbusRTU/ModbusRTU.device.lib.nut | 36 +++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/ModbusRTU/ModbusRTU.device.lib.nut b/ModbusRTU/ModbusRTU.device.lib.nut index 26e03a5..f6a5b4b 100644 --- a/ModbusRTU/ModbusRTU.device.lib.nut +++ b/ModbusRTU/ModbusRTU.device.lib.nut @@ -265,8 +265,26 @@ class ModbusRTU { // function to create PDU for read // static function createReadPDU(targetType, startingAddress, quantity) { - local PDU = blob(targetType.reqLen); - PDU.writen(targetType.fcode, 'b'); + local pduType; + switch() { + case MODBUSRTU_TARGET_TYPE.COIL: + pduType = FUNCTION_CODES.read_coils; + break; + case MODBUSRTU_TARGET_TYPE.DISCRETE_INPUT: + pduType = FUNCTION_CODES.readInputs; + break; + case MODBUSRTU_TARGET_TYPE.INPUT_REGISTER: + pduType = FUNCTION_CODES.readInputRegs; + break; + case MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER: + pduType = FUNCTION_CODES.readHoldingRegs; + break; + default: + throw "Incorrect targetType specified"; + } + + local PDU = blob(pduType.reqLen); + PDU.writen(pduType.fcode, 'b'); PDU.writen(swap2(startingAddress), 'w'); PDU.writen(swap2(quantity), 'w'); return PDU; @@ -276,8 +294,20 @@ class ModbusRTU { // function to create PDU for write // static function createWritePDU(targetType, startingAddress, numBytes, quantity, values) { + local pduType; + switch() { + case MODBUSRTU_TARGET_TYPE.COIL: + pduType = FUNCTION_CODES.writeSingleCoil; + break; + case MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER: + pduType = FUNCTION_CODES.writeSingleReg; + break; + default: + throw "Incorrect targetType specified"; + } + local PDU = blob(); - PDU.writen(targetType.fcode, 'b'); + PDU.writen(pduType.fcode, 'b'); PDU.writen(swap2(startingAddress), 'w'); if (quantity > 1) { PDU.writen(swap2(quantity), 'w'); From 5ee1d01d66819757f46395aedfc82fc34b43ca3c Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Tue, 30 Aug 2022 11:20:37 +0100 Subject: [PATCH 23/26] Correct createReadPDU(), createWritePDU() entries --- ModbusRTU/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 17d9e10..4db4704 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -59,6 +59,11 @@ This method creates a PDU for *writeData* operations. It takes the following par | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are written into | | *values* | Integer, array ([integer, boolean]), boolean, blob | Yes | N/A | The values written into Coils or Registers | +| Type | Value | Access | +| --- | --- | --- | +| Coil | *MODBUSRTU_TARGET_TYPE.COIL* | Read-Write | +| Holding Register | *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER* | Read-Write | + #### Example ```squirrel From e197aa8c251e3b935df9f9b20c772a0481ee5610 Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Tue, 30 Aug 2022 11:21:42 +0100 Subject: [PATCH 24/26] Remove unneeded access value from tables --- ModbusRTU/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ModbusRTU/README.md b/ModbusRTU/README.md index 4db4704..a0b0458 100644 --- a/ModbusRTU/README.md +++ b/ModbusRTU/README.md @@ -30,12 +30,12 @@ This method creates a PDU for *readData* operations. It takes the following para | *startingAddress* | Integer | Yes | N/A | The address from which it begins reading values | | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are read from | -| Type | Value | Access | -| --- | --- | --- | -| Coil | *MODBUSRTU_TARGET_TYPE.COIL* | Read-Write | -| Discrete Input | *MODBUSRTU_TARGET_TYPE.DISCRETE_INPUT* | Read Only | -| Input Register | *MODBUSRTU_TARGET_TYPE.INPUT_REGISTER* | Read Only | -| Holding Register | *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER* | Read-Write | +| Type | Value | +| --- | --- | +| Coil | *MODBUSRTU_TARGET_TYPE.COIL* | +| Discrete Input | *MODBUSRTU_TARGET_TYPE.DISCRETE_INPUT* | +| Input Register | *MODBUSRTU_TARGET_TYPE.INPUT_REGISTER* | +| Holding Register | *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER* | #### Example @@ -59,10 +59,10 @@ This method creates a PDU for *writeData* operations. It takes the following par | *quantity* | Integer | Yes | N/A | The number of consecutive addresses the values are written into | | *values* | Integer, array ([integer, boolean]), boolean, blob | Yes | N/A | The values written into Coils or Registers | -| Type | Value | Access | -| --- | --- | --- | -| Coil | *MODBUSRTU_TARGET_TYPE.COIL* | Read-Write | -| Holding Register | *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER* | Read-Write | +| Type | Value | +| --- | --- | +| Coil | *MODBUSRTU_TARGET_TYPE.COIL* | +| Holding Register | *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER* | #### Example From fb21dc989a7be3ebe2ab7daa9d24b0090b3fd7dd Mon Sep 17 00:00:00 2001 From: Tony Smith Date: Tue, 30 Aug 2022 11:23:23 +0100 Subject: [PATCH 25/26] Correct switch() statements --- ModbusRTU/ModbusRTU.device.lib.nut | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ModbusRTU/ModbusRTU.device.lib.nut b/ModbusRTU/ModbusRTU.device.lib.nut index f6a5b4b..a166636 100644 --- a/ModbusRTU/ModbusRTU.device.lib.nut +++ b/ModbusRTU/ModbusRTU.device.lib.nut @@ -266,7 +266,7 @@ class ModbusRTU { // static function createReadPDU(targetType, startingAddress, quantity) { local pduType; - switch() { + switch(targetType) { case MODBUSRTU_TARGET_TYPE.COIL: pduType = FUNCTION_CODES.read_coils; break; @@ -295,7 +295,7 @@ class ModbusRTU { // static function createWritePDU(targetType, startingAddress, numBytes, quantity, values) { local pduType; - switch() { + switch(targetType) { case MODBUSRTU_TARGET_TYPE.COIL: pduType = FUNCTION_CODES.writeSingleCoil; break; From f4df33676c7224213c5ee177cb93f5eb825c055d Mon Sep 17 00:00:00 2001 From: smittytone Date: Mon, 20 Nov 2023 17:53:47 +0000 Subject: [PATCH 26/26] Update ownership --- ModbusMaster/ModbusMaster.device.lib.nut | 5 +++-- ModbusRTU/ModbusRTU.device.lib.nut | 9 +++++---- .../ModbusSerialMaster.device.lib.nut | 7 ++++--- ModbusSerialMaster/example/example.device.nut | 15 ++++++++------- .../ModbusSerialSlave.device.lib.nut | 5 +++-- ModbusSerialSlave/example/device.example.nut | 11 ++++++----- ModbusSlave/ModbusSlave.device.lib.nut | 5 +++-- ModbusTCPMaster/ModbusTCPMaster.device.lib.nut | 5 +++-- ModbusTCPMaster/example/device.example.nut | 6 +++--- 9 files changed, 38 insertions(+), 30 deletions(-) diff --git a/ModbusMaster/ModbusMaster.device.lib.nut b/ModbusMaster/ModbusMaster.device.lib.nut index 5b2c04a..3dcbec1 100644 --- a/ModbusMaster/ModbusMaster.device.lib.nut +++ b/ModbusMaster/ModbusMaster.device.lib.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -23,7 +24,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusMaster { - static VERSION = "1.0.1"; + static VERSION = "1.0.2"; _debug = null; // diff --git a/ModbusRTU/ModbusRTU.device.lib.nut b/ModbusRTU/ModbusRTU.device.lib.nut index a166636..6c1eb6f 100644 --- a/ModbusRTU/ModbusRTU.device.lib.nut +++ b/ModbusRTU/ModbusRTU.device.lib.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -84,7 +85,7 @@ enum MODBUSRTU_OBJECT_ID { } class ModbusRTU { - static VERSION = "1.0.1"; + static VERSION = "1.0.2"; // resLen and reqLen are the length of the PDU static FUNCTION_CODES = { readCoils = { @@ -282,7 +283,7 @@ class ModbusRTU { default: throw "Incorrect targetType specified"; } - + local PDU = blob(pduType.reqLen); PDU.writen(pduType.fcode, 'b'); PDU.writen(swap2(startingAddress), 'w'); @@ -305,7 +306,7 @@ class ModbusRTU { default: throw "Incorrect targetType specified"; } - + local PDU = blob(); PDU.writen(pduType.fcode, 'b'); PDU.writen(swap2(startingAddress), 'w'); diff --git a/ModbusSerialMaster/ModbusSerialMaster.device.lib.nut b/ModbusSerialMaster/ModbusSerialMaster.device.lib.nut index 7a7a4fc..e108e9b 100644 --- a/ModbusSerialMaster/ModbusSerialMaster.device.lib.nut +++ b/ModbusSerialMaster/ModbusSerialMaster.device.lib.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -24,9 +25,9 @@ class ModbusSerialMaster extends ModbusMaster { - static VERSION = "2.0.0"; + static VERSION = "2.0.1"; static MINIMUM_RESPONSE_LENGTH = 5; - + _uart = null; _rts = null; _timeout = null; diff --git a/ModbusSerialMaster/example/example.device.nut b/ModbusSerialMaster/example/example.device.nut index 4017e3f..ae17722 100644 --- a/ModbusSerialMaster/example/example.device.nut +++ b/ModbusSerialMaster/example/example.device.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -23,15 +24,15 @@ // OTHER DEALINGS IN THE SOFTWARE. #require "CRC16.class.nut:1.0.0" -#require "ModbusRTU.device.lib.nut:1.0.1" -#require "ModbusMaster.device.lib.nut:1.0.1" -#require "ModbusSerialMaster.device.lib.nut:2.0.0" +#require "ModbusRTU.device.lib.nut:1.0.2" +#require "ModbusMaster.device.lib.nut:1.0.2" +#require "ModbusSerialMaster.device.lib.nut:2.0.1" -// Hardware used: Fieldbus Gateway and Kojo +// Hardware used: Fieldbus Gateway and Kojo // Click PLC C0-02DR-D connectied via RS485 ports -// This example demonstrates how to write and read values -// into/from holding registers. +// This example demonstrates how to write and read values +// into/from holding registers. const DEVICE_ADDRESS = 0x01; // instantiate the the Modbus485Master object diff --git a/ModbusSerialSlave/ModbusSerialSlave.device.lib.nut b/ModbusSerialSlave/ModbusSerialSlave.device.lib.nut index ee729b1..c7e9cdd 100644 --- a/ModbusSerialSlave/ModbusSerialSlave.device.lib.nut +++ b/ModbusSerialSlave/ModbusSerialSlave.device.lib.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -23,7 +24,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusSerialSlave extends ModbusSlave { - static VERSION = "2.0.0"; + static VERSION = "2.0.1"; static MIN_REQUEST_LENGTH = 4; _slaveID = null; _uart = null; diff --git a/ModbusSerialSlave/example/device.example.nut b/ModbusSerialSlave/example/device.example.nut index e91573a..8c5bba9 100644 --- a/ModbusSerialSlave/example/device.example.nut +++ b/ModbusSerialSlave/example/device.example.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -23,13 +24,13 @@ // OTHER DEALINGS IN THE SOFTWARE. #require "CRC16.class.nut:1.0.0" -#require "ModbusSlave.device.lib.nut:1.0.1" -#require "ModbusSerialSlave.device.lib.nut:2.0.0" +#require "ModbusSlave.device.lib.nut:1.0.2" +#require "ModbusSerialSlave.device.lib.nut:2.0.1" -// Hardware used: Fieldbus Gateway and Kojo +// Hardware used: Fieldbus Gateway and Kojo // Click PLC C0-02DR-D connectied via RS485 ports -// This example demonstrates a holding register read. +// This example demonstrates a holding register read. const SLAVE_ID = 0x01; diff --git a/ModbusSlave/ModbusSlave.device.lib.nut b/ModbusSlave/ModbusSlave.device.lib.nut index fcbe00f..fdfbc4e 100644 --- a/ModbusSlave/ModbusSlave.device.lib.nut +++ b/ModbusSlave/ModbusSlave.device.lib.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -41,7 +42,7 @@ enum MODBUSSLAVE_EXCEPTION { } class ModbusSlave { - static VERSION = "1.0.1"; + static VERSION = "1.0.2"; static FUNCTION_CODES = { readCoil = { fcode = 0x01, diff --git a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut index 7b491cc..b974edf 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.device.lib.nut @@ -1,6 +1,7 @@ // MIT License // -// Copyright 2017-2020 Electric Imp +// Copyright 2017-19 Electric Imp +// Copyright 2020-23 KORE Wireless // // SPDX-License-Identifier: MIT // @@ -23,7 +24,7 @@ // OTHER DEALINGS IN THE SOFTWARE. class ModbusTCPMaster extends ModbusMaster { - static VERSION = "1.1.0"; + static VERSION = "1.1.1"; static MAX_TRANSACTION_COUNT = 65535; _transactions = null; _wiz = null; diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index 44f38ab..839dd48 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -23,9 +23,9 @@ // OTHER DEALINGS IN THE SOFTWARE. #require "W5500.device.nut:1.0.0" -#require "ModbusRTU.device.lib.nut:1.0.1" -#require "ModbusMaster.device.lib.nut:1.0.1" -#require "ModbusTCPMaster.device.lib.nut:1.1.0" +#require "ModbusRTU.device.lib.nut:1.0.2" +#require "ModbusMaster.device.lib.nut:1.0.2" +#require "ModbusTCPMaster.device.lib.nut:1.1.1" // this example shows how to use readWriteMultipleRegisters