From a2977eeb349d036e46ebb9a8c709a0d85eab0ae4 Mon Sep 17 00:00:00 2001 From: betsy Date: Mon, 8 May 2017 13:32:26 -0700 Subject: [PATCH 01/10] fixed documentation bugs, deleted examples that were incorrect --- ModbusTCPMaster/README.md | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index c16f1f1..5673bcc 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -25,9 +25,9 @@ The following instructions are applicable to Electric Imp’s [impAccelerator&tr 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: ModbusTCPMaster(*wiz, debug*) +### Constructor: ModbusTCPMaster(*wiz[, debug]*) -Instantiate a new ModbusTCPMaster object. It takes two parameters: *wiz*, the Wiznet W5500 object that is driving the Ethernet link, and *debug* which, if enabled, prints the outgoing and incoming ADU for debugging purposes. +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`. #### Example @@ -55,7 +55,7 @@ This method configures the network and opens a TCP connection with the device. I | *onConnectCallback* | Function | No | Null | The function to be fired when the connection is established | | *onReconnectCallback* | Function | No | Null| The function to be fired when the connection is re-established | -**Note** If an *onReconnectCallback* is not supplied, when the connection is re-established, the *onConnectCallback* will be fired. +**Note:** If an *onReconnectCallback* is not supplied, when the connection is re-established, the *onConnectCallback* will be fired. #### Example @@ -76,9 +76,9 @@ modbus.connect(connectionSettings, function(error, conn){ }); ``` -### disconnect(*callback*) +### disconnect(*[callback]*) -This method closes the existing TCP connection. +This method closes the existing TCP connection. It takes one optional parameter: *callback*, a function that will be executed when the connection has been closed. #### Example @@ -86,7 +86,7 @@ This method closes the existing TCP connection. modbus.disconnect(); ``` -### read(*targetType, startingAddress, quantity, values[, callback]*) +### read(*targetType, startingAddress, quantity[, callback]*) Function Code : 01, 02, 03, 04 @@ -144,7 +144,7 @@ This is a generic method used to write values into coils or registers. It has th | *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* | -#### Notes +#### Notes: 1. Integer, blob and array[integer] are applicable to *MODBUSRTU_TARGET_TYPE.HOLDING_REGISTER*. Use array[integer] only when *quantity* is greater than one. @@ -300,13 +300,6 @@ This method performs a combination of one read operation and one write operation #### Example ```squirrel -modbus.readWriteMultipleRegisters(0x10, 0xFFFF, 0x0000, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } -}.bindenv(this)); ``` ### readDeviceIdentification(*readDeviceIdCode, objectId, [callback]*) From 09c0d4ea02d24751f691ba73ac215b274bf86d47 Mon Sep 17 00:00:00 2001 From: betsy Date: Mon, 8 May 2017 13:42:13 -0700 Subject: [PATCH 02/10] fixed documentation bugs, deleted examples that were incorrect --- Modbus485Master/README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Modbus485Master/README.md b/Modbus485Master/README.md index fd9ffc8..c3cf26a 100644 --- a/Modbus485Master/README.md +++ b/Modbus485Master/README.md @@ -27,7 +27,7 @@ The following instructions are applicable to Electric Imp’s [impAccelerator&tr 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: Modbus485Master(*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: @@ -268,13 +268,6 @@ This method performs a combination of one read operation and one write operation #### Example ```squirrel -modbus.readWriteMultipleRegisters(0x01, 0x10, 0xFFFF, 0x0000, function(error, result) { - if (error) { - server.error(error); - } else { - server.log(result); - } -}.bindenv(this)); ``` ### readDeviceIdentification(*deviceAddress, readDeviceIdCode, objectId[, callback]*) From 7743f0059bc3e7114c3761def58f1837185de29f Mon Sep 17 00:00:00 2001 From: Derrick Cheung Date: Mon, 15 May 2017 10:13:25 +1000 Subject: [PATCH 03/10] 1. fixed the parsing error when requests are made in quick succession . A new test case was written for it 2. Added notes to advise users of the TCP connection dropout after a certain amount of idle time 3. Added notes to inform users that the order of operation in readWriteMultipleRegisters may differ from the modus spec in reality . --- Modbus485Master/README.md | 5 ++++- ModbusTCPMaster/ModbusTCPMaster.class.nut | 3 ++- ModbusTCPMaster/README.md | 9 +++++++-- ModbusTCPMaster/tests/device.test.nut | 24 +++++++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Modbus485Master/README.md b/Modbus485Master/README.md index 7a41cad..ca1acb4 100644 --- a/Modbus485Master/README.md +++ b/Modbus485Master/README.md @@ -254,7 +254,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 | | --- | --- | --- | --- | --- | @@ -266,6 +266,9 @@ This method performs a combination of one read operation and one write operation | *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* | +**Note** The actual order of operation is determined by the implementation of user's device. + + #### Example ```squirrel diff --git a/ModbusTCPMaster/ModbusTCPMaster.class.nut b/ModbusTCPMaster/ModbusTCPMaster.class.nut index 0a98e82..09ad6f2 100644 --- a/ModbusTCPMaster/ModbusTCPMaster.class.nut +++ b/ModbusTCPMaster/ModbusTCPMaster.class.nut @@ -130,11 +130,12 @@ class ModbusTCPMaster extends ModbusMaster { function _send(PDU, properties) { _transactions[_transactionCount] <- properties; local ADU = _createADU(PDU); + // with or without success in transmission of data, the transaction count would be advanced + _transactionCount = (_transactionCount + 1) % MAX_TRANSACTION_COUNT; _connection.transmit(ADU, function(error) { if (error) { _callbackHandler(error, null, properties.callback); } else { - _transactionCount = (_transactionCount + 1) % MAX_TRANSACTION_COUNT; _log(ADU, "Outgoing ADU: "); } }.bindenv(this)); diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index b34e485..3d84d10 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -57,7 +57,10 @@ This method configures the network and opens a TCP connection with the device. I | *onConnectCallback* | Function | No | Null | The function to be fired when the connection is established | | *onReconnectCallback* | Function | No | Null| The function to be fired when the connection is re-established | -**Note** If an *onReconnectCallback* is not supplied, when the connection is re-established, the *onConnectCallback* will be fired. +**Note** + +1. If an *onReconnectCallback* is not supplied, when the connection is re-established, the *onConnectCallback* will be fired. +2. Depending on the configuration of the device, the connection will be severed after a certain amount of time and try to re-establish itself. Users of concern are advised to pass in a *onReconnectCallback* to handle this situation. Please refer to the device spec for more information on how to configure the default idle time. #### Example @@ -288,7 +291,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 | | --- | --- | --- | --- | --- | @@ -299,6 +302,8 @@ This method performs a combination of one read operation and one write operation | *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* | +**Note** The actual order of operation is determined by the implementation of user's device. + #### Example ```squirrel diff --git a/ModbusTCPMaster/tests/device.test.nut b/ModbusTCPMaster/tests/device.test.nut index 47d1311..b1231c9 100644 --- a/ModbusTCPMaster/tests/device.test.nut +++ b/ModbusTCPMaster/tests/device.test.nut @@ -390,6 +390,30 @@ class DeviceTestCase extends ImpTestCase { }.bindenv(this)); } + // this test will timeout when it fails + function testSendRequestsInSuccession() { + return Promise(function(resolve, reject) { + _connection.then(function(value) { + local address = 0x0A; + local value = false; + local quantity = 1; + local isSuccess = false; + _modbus.write(MODBUSRTU_TARGET_TYPE.COIL, address, quantity, value, function(error, result) { + if (isSuccess) { + resolve(PASS_MESSAGE); + } + isSuccess = true; + }.bindenv(this)); + _modbus.write(MODBUSRTU_TARGET_TYPE.COIL, address, quantity, value, function(error, result) { + if (isSuccess) { + resolve(PASS_MESSAGE); + } + isSuccess = true; + }.bindenv(this)); + }.bindenv(this)); + }.bindenv(this)); + } + function tearDown() { _modbus.disconnect(); return "Connection closed"; From 0229b6562ac20c0290723a57fe0fac5837dede3e Mon Sep 17 00:00:00 2001 From: Derrick Cheung Date: Tue, 23 May 2017 12:41:27 +1000 Subject: [PATCH 04/10] addressed more issued stated in pull request --- ModbusTCPMaster/README.md | 14 ++++++++++++-- ModbusTCPMaster/example/device.example.nut | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ModbusTCPMaster/README.md b/ModbusTCPMaster/README.md index b7f2724..93ed972 100644 --- a/ModbusTCPMaster/README.md +++ b/ModbusTCPMaster/README.md @@ -52,8 +52,8 @@ This method configures the network and opens a TCP connection with the device. I | Parameter | Data Type | Required | Default Value | Description | | --- | --- | --- | --- | --- | | *connectionSettings* | Table | Yes | N/A | The device IP address and port. The device IP address can either be a string or an array of four bytes, for example: `[192, 168, 1, 37]` or `"192.168.1.37"`. The port can either be an integer or array of two bytes (the high and low bytes of an unsigned two-byte integer value), for example: `[0x10, 0x92]` or `4242` | -| *onConnectCallback* | Function | No | Null | The function to be fired when the connection is established | -| *onReconnectCallback* | Function | No | Null| The function to be fired when the connection is re-established | +| *onConnectCallback* | Function | No | Null | The function to be fired when the connection is established. The callback takes `error` and `conn` as parameters | +| *onReconnectCallback* | Function | No | Null| The function to be fired when the connection is re-established. The callback takes `error` and `conn` as parameters | **Note** @@ -305,6 +305,16 @@ This method performs a combination of one read operation and one write operation #### Example ```squirrel +modbus.readWriteMultipleRegisters(0x0A, 2, 0x0A, 2, [28, 88], function(error, result) { + if (error) { + server.error(error); + } else { + foreach (index, value in result) { + server.log(format("Index : %d, value : %d", index, value)); + } + } +}); + ``` ### readDeviceIdentification(*readDeviceIdCode, objectId, [callback]*) diff --git a/ModbusTCPMaster/example/device.example.nut b/ModbusTCPMaster/example/device.example.nut index 3273437..7d7ac09 100644 --- a/ModbusTCPMaster/example/device.example.nut +++ b/ModbusTCPMaster/example/device.example.nut @@ -23,7 +23,7 @@ local connectionSettings = { }; // open the connection -modbus.connect(networkSettings, connectionSettings, function(error, conn) { +modbus.connect(connectionSettings, function(error, conn) { if (error) { server.log(error); } else { From c1a59c935ab9025362a203a2fa8e7fa00ee1a8b1 Mon Sep 17 00:00:00 2001 From: Betsy Rhodes Date: Thu, 24 Aug 2017 09:08:19 -0700 Subject: [PATCH 05/10] 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 06/10] 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 07/10] 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 08/10] 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 09/10] 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 10/10] 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