Swiftpack.co -  DimaRU/SwiftyModbus as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
DimaRU/SwiftyModbus
Swift wrapper for the libmodbus library with promises
.package(url: "https://github.com/DimaRU/SwiftyModbus.git", from: "1.0.0")

SwiftyModbus

This is a Swift wrapper class for the libmodbus library. Now support only TCP modbus connection. Support both macOS and Linux.

How To Get Started

  • Add
    .package(url: "https://github.com/DimaRU/SwiftyModbus.git", .upToNextMajor(from: "1.0.0")) to your dependencies.

Documentation

Autogenerated documentation https://dimaru.github.io/SwiftyModbus/

Example

import Foundation
import SwiftyModbus
import PromiseKit

let modbus = SwiftyModbus(address: "127.0.0.1", port: 503)
modbus.responseTimeout = 1.5      // Set timeout for 1.5 sec
print(modbus.responseTimeout)

firstly {
    modbus.connect()
}.then {
    modbus.readRegisters(addr: 102, count: 10)
}.done { registers in
    print(registers)
}.then {
    modbus.writeRegisters(addr: 102, data: [1,2,3,4,5,6,7,8,9,10])
}.then {
    modbus.readInputRegisters(addr: 102, count: 10)
}.done { registers in
    print(registers)
}.then {
    modbus.writeBits(addr: 104, status: [0,1,0,1])
}.then {
    modbus.readBits(addr: 104, count: 4)
}.done { bits in
    print(bits)
}.then {
    modbus.disconnect()
}.catch { error in
    print(error)
}.finally {
    exit(0)
}

RunLoop.main.run()

You may test this example with diagslave

sudo ./diagslave -m tcp -p 503

GitHub

link
Stars: 1
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Dependencies

Release Notes

1.0.0
3 weeks ago

First public release. Support only TCP connection under both macOS and Linux.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics