Skip to content

Commit

Permalink
Feature: GetCommEventLog (0x0C) command
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanesik committed Dec 27, 2022
1 parent 7dffdda commit 7ae7352
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Functions:
- Read Exception Status: **readExceptionStatus** = 0x07
- Diagnostic: **diagnostic** = 0x08
- Get Comm Event Counter: **getCommEventCounter** = 0x0B
- Get Comm Event Log: **getCommEventLog** = 0x0C

- Write multiply coil (one bit) registers: **forceMultipleCoils** = 0x0F
- Write multiply holding (16 bit bit) registers: **presetMultipleRegisters**= 0x10
Expand All @@ -107,7 +108,6 @@ Functions:
- Read FIFO Queue - 0x18
- Read File Record - 0x14
- Write File Record - 0x15
- Get Com Event Log - 0x0C
- Report Server ID - 0x11
- Encapsulated Interface Transport - 0x2B
- Presets for diagnostic (0x08) function
Expand Down
5 changes: 5 additions & 0 deletions Sources/ModSwift/ModSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ public class ModSwift {
return createCommand(command: .getCommEventCounter)
}

/// Returns package for "Get Comm Event Log" function (0x0C)
func getCommEventLog() -> Data {
return createCommand(command: .getCommEventLog)
}

/// 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
2 changes: 1 addition & 1 deletion Sources/ModSwift/Model/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum Command: UInt8 {
/** Get Com Event Counter */
case getCommEventCounter = 0x0B
/** Get Com Event Log */
case getComEventLog = 0x0C
case getCommEventLog = 0x0C
/** Report Server ID */
case reportServerId = 0x11

Expand Down
6 changes: 6 additions & 0 deletions Tests/ModSwiftTests/ModSwiftRtuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ final class ModSwiftTests: XCTestCase {
XCTAssertEqual(data, rightData)
}

func testGetCommEventLog() {
let rightData = Data([0x0B, 0x0C, 0x85, 0x06])
let data = modbus.getCommEventLog()
XCTAssertEqual(data, rightData)
}

func testForceMultipleCoils() {
// trans 2, prot 2, len 2, slave 1, func 1, addr 2, count 2, data
let rightData = Data([11, 15, 1, 13, 0, 20, 3, 0x85, 0xA8, 0x05, 0x73, 0xC3])
Expand Down
6 changes: 6 additions & 0 deletions Tests/ModSwiftTests/ModSwiftTcpTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class ModSwiftTcpTest: XCTestCase {
XCTAssertEqual(data, rightData)
}

func testGetCommEventLog() {
let rightData = Data([0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x0B, 0x0C])
let data = modbus.getCommEventLog()
XCTAssertEqual(data, rightData)
}

func testForceMultipleCoils() {
// trans 2, prot 2, len 2, slave 1, func 1, addr 2, count 2, data
let rightData = Data([0x00, 0x01, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0F, 0x01, 0x0D, 0x00, 0x14, 0x03, 0x85, 0xA8, 0x05])
Expand Down

0 comments on commit 7ae7352

Please sign in to comment.