Git Product home page Git Product logo

modbus's Introduction

Modbus

Modbus library supports for Modbus Protocol.

Install

You can clone/download source code from this repository and then add to your project. Or install via Nuget:

Install-Package Modbus

Usage

Easiest way.

// use modbus rtu
var session = ModbusSessionFactory.CreateRtuSession(serialPort);
// arguments are slave id, data address and number of registers
var builder = RequestBuilderFactory.CreateRequest03<RtuRequest>(1, 0, 4);
// send request and wait for response
var response = await session.SendRequestAsync<ResponseFunc03>(builder);

But! wait, where is ResponseFunc03, it's just a use-defined structure. You should define what you want to receive by a strucutre.

[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct ResponseFunc03
{
    public byte numberOfBytes;

    [Endian(Endianness.BigEndian)]
    public short value;

    [Endian(Endianness.BigEndian)]
    public ushort dotPosition;

    public short padding1;
    public short padding2;
    
    //[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U2, SizeConst = 4)]
    //[Endian(Endianness.BigEndian)]
    //public ushort[] bytes;
}

Current version supports function code 01, 02, 03, 04, 05 and 06. Also, the library supports both modbus RTU and modbus TCP. Of couse, you can make your owner request and response types by create Builder from RtuRequest or TcpRequest classes.

 var builder = new RtuRequest.Builder()
    .SetSlaveAddress(0x01)
    .SetFunctionCode(0x09)
    .AddInt16(33)
    .AddInt16(93);
    //.SetObject(requestDataStruct)

modbus's People

Contributors

sontx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.