Skip to content

Commit

Permalink
Feature: ReportServerId (0x11) command
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanesik committed Dec 27, 2022
1 parent 7ae7352 commit 5d5e418
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Functions:
- Write multiply coil (one bit) registers: **forceMultipleCoils** = 0x0F
- Write multiply holding (16 bit bit) registers: **presetMultipleRegisters**= 0x10

- Report Server ID: **reportServerId** = 0x11

## TODO

- Split TCP and RTU into 2 classes with extension of base class BaseModbus
Expand All @@ -108,7 +110,6 @@ Functions:
- Read FIFO Queue - 0x18
- Read File Record - 0x14
- Write File Record - 0x15
- Report Server ID - 0x11
- Encapsulated Interface Transport - 0x2B
- Presets for diagnostic (0x08) function
- Modes:
Expand Down
7 changes: 6 additions & 1 deletion Sources/ModSwift/ModSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public class ModSwift {
return createCommand(command: .getCommEventLog)
}

/// Returns package for force (write) multiple coils function (0x0F)
/// Returns package for "Force (write) multiple coils" function (0x0F)
func forceMultipleCoils(startAddress: UInt16, values: [Bool]) -> Data {
var data: [UInt8] = DataHelper.splitIntIntoTwoBytes(values.count)

Expand Down Expand Up @@ -320,4 +320,9 @@ public class ModSwift {
)
}

/// Returns package for "Report Server ID" function (0x11)
func reportServerId() -> Data {
return createCommand(command: .reportServerId)
}

}
17 changes: 9 additions & 8 deletions Sources/ModSwift/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ enum Command: UInt8 {
case getCommEventCounter = 0x0B
/** Get Com Event Log */
case getCommEventLog = 0x0C
/** Report Server ID */
case reportServerId = 0x11

/** Write multiply coil (one bit) registers */
case forceMultipleCoils = 0x0F
/** Write multiply holding (16 bit bit) registers */
case presetMultipleRegisters = 0x10

/** Report Server ID */
case reportServerId = 0x11

/** Read File Record */
case readFileRecord = 0x14
/** Write File Record */
case writeFileRecord = 0x15

/** Mask Write Register */
case maskWriteRegister = 0x16

Expand All @@ -58,12 +64,7 @@ enum Command: UInt8 {

/** Read FIFO Queue */
case readFIFOQueue = 0x18

/** Read File Record */
case readFileRecord = 0x14
/** Write File Record */
case writeFileRecord = 0x15


/** Encapsulated Interface Transport */
case encapsulatedInterfaceTransport = 0x2B
}
7 changes: 7 additions & 0 deletions Tests/ModSwiftTests/ModSwiftRtuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ final class ModSwiftTests: XCTestCase {
let data = modbus.presetMultipleRegisters(startAddress: 0x010D, values: [0xA30D, 0x1501, 0x1127])
XCTAssertEqual(data, rightData)
}

func testReportServerId() {
let rightData = Data([0x0B, 0x11, 0x8c, 0xc6])
let data = modbus.reportServerId()
XCTAssertEqual(data, rightData)
}

}
6 changes: 6 additions & 0 deletions Tests/ModSwiftTests/ModSwiftTcpTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ class ModSwiftTcpTest: XCTestCase {
XCTAssertEqual(data, rightData)
}

func testReportServerId() {
let rightData = Data([0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x0B, 0x11])
let data = modbus.reportServerId()
XCTAssertEqual(data, rightData)
}

}

0 comments on commit 5d5e418

Please sign in to comment.