This repository was archived by the owner on Jul 30, 2021. It is now read-only.
File tree 2 files changed +5
-19
lines changed
2 files changed +5
-19
lines changed Original file line number Diff line number Diff line change 6
6
7
7
- it is working
8
8
- 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)
10
13
- async operation. blocking code is in a seperate task
11
14
- error codes are implemented but untested (somehow my device just tries to answer all the time instead of generating a Modbus error)
12
15
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.
30
16
31
17
# Example hardware:
32
18
Original file line number Diff line number Diff line change @@ -39,6 +39,6 @@ void loop() {
39
39
if (millis () - lastMillis > 30000 ) {
40
40
lastMillis = millis ();
41
41
Serial.print (" sending Modbus request...\n " );
42
- modbus.readInputRegister (0x01 , 52 , 2 );
42
+ modbus.readInputRegisters (0x01 , 52 , 2 );
43
43
}
44
44
}
You can’t perform that action at this time.
0 commit comments