Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit c5f24ce

Browse files
committed
new FCs
1 parent 3ef5894 commit c5f24ce

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

Diff for: README.md

+4-18
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,13 @@
66

77
- it is working
88
- only RS485 half duplex using a GPIO as RTS (DE/RS) is implemented
9-
- only function code 04 is implemented (others will be there soon)
9+
- function codes implemented:
10+
- read discrete inputs (02)
11+
- read holding registers (03)
12+
- read input registers (04)
1013
- async operation. blocking code is in a seperate task
1114
- error codes are implemented but untested (somehow my device just tries to answer all the time instead of generating a Modbus error)
1215

13-
To add new function codes:
14-
- create class, inherit from `ModbusRequest`
15-
- the constructor needs to get all the needed data as arguments
16-
- in the constructor
17-
- call `ModbusRequest(size_t)` in the initializer list with the needed message length as argument
18-
- create the modbus request by sequentially call `add(uint8_t)` to add a byte to the message buffer
19-
(first byte first, so start with the slave address)
20-
- add a (virtual) method:
21-
22-
```C++
23-
ModbusResponse* ModbusRequestType::makeResponse() {
24-
uint8_t responseLength = 3 + (_byteCount * 2) + 2; // expected length in the response
25-
ModbusResponse* response = new ModbusResponse(responseLength, this);
26-
return response;
27-
}
28-
```
29-
Note: the response will be deleted elsewhere.
3016

3117
# Example hardware:
3218

Diff for: examples/SDM630/SDM630.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ void loop() {
3939
if (millis() - lastMillis > 30000) {
4040
lastMillis = millis();
4141
Serial.print("sending Modbus request...\n");
42-
modbus.readInputRegister(0x01, 52, 2);
42+
modbus.readInputRegisters(0x01, 52, 2);
4343
}
4444
}

0 commit comments

Comments
 (0)