Latest 0.0.2
Homepage https://github.com/iUtvikler/ObjectiveLibModbus
License GNU
Authors

NOTE!

This project has been abandoned, but there is a new Swift fork ktsakaguchi/SwiftLibModbus. I recommend using that instead!

This is an Objective-C wrapper class for the libmodbus library. The wrapper is free to use for anyone (GNU Lesser Public License).

The wrapper only supports TCP for now. It does not wrap all of the libmodbus functions. I recommend reading the libmodbus documentation if you are missing some features. Chances are libmodbus already supports it! If you modify or extend the code, please contribute back!

How To Get Started

The easiest way to get this working is to use CocoaPods

If you dont use CocoaPods do this:

  • Drag all the .c and .h files from the Vendor/libmodbus folder into you’re project.
  • Drag ObjectiveLibModbus.h and ObjectiveLibModbus.m into you’re project from ObjectiveLibModbus folder.

Now that you’re set up, do the following to make modbus calls

  • Import ObjectiveLibModbus where you will be using it:

    #import "ObjectiveLibModbus.h"
  • Now make a new instance of ObjectiveLibModbus and connect:

    //Allocate a new ObjectiveLibModbus instance
    objLibModbus = [[ObjectiveLibModbus alloc] initWithTCP:@"192.168.2.10" port:502 device:1];
    [objLibModbus connect:^{
    //connected and ready to do modbus calls
    } failure:^(NSError *error) {
    //Handle error
    NSLog(@"Error: %@", error.localizedDescription);
    }];
  • Make a modbus call:

    [objLibModbus readRegistersFrom:1000 count:5 success:^(NSArray *array) {
    //Do something with the returned data (NSArray of NSNumber)..
    NSLog(@"Array: %@", array);
    } failure:^(NSError *error) {
    //Handle error
    NSLog(@"Error: %@", error.localizedDescription);
    }];
  • Disconnect when you are finished with you’re modbus calls:
    [objLibModbus disconnect];

Latest podspec

{
    "name": "ObjectiveLibModbus",
    "version": "0.0.2",
    "license": "GNU",
    "summary": "Obj-C wrapper for libmodbus.",
    "homepage": "https://github.com/iUtvikler/ObjectiveLibModbus",
    "authors": {
        "Lars-Ju00f8rgen Kristiansen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/iUtvikler/ObjectiveLibModbus.git",
        "tag": "0.0.2"
    },
    "description": "ObjectiveLibModbus is an Objective-C wrapper class for the libmodbus library.I included tweaked and compiled libmodbus sourcefiles, that work with OS X and iOS in this project.",
    "source_files": [
        "ObjectiveLibModbus/*.{h,m}",
        "Vendor/libmodbus/*.{c,h}"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This