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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

modbus's Issues

Support function code 08?

Hi,

I just found your lib, looks good and planning to use it for my project. It doesn't seem to support FC08 right now, would you be willing to add support or accept PR for it?

I'm working with several hardware that offer that Diagnostic feature so we can use it to "healthcheck" our device. Basically when we send a message like this 01 08 0000 1234 ED7C, we would get the exact same answer back, this helps us knowing that our device is up and running.

Ex: https://infosys.beckhoff.com/english.php?content=../content/1033/fbb-x730/html/Bt_Modbus%20function_8.htm&id=

Modbus TcpRequest

Hi, your libraries looks amazing. ๐Ÿ‘

I cant figure out how to make TcpRequest, can you give me any advice/hint?

Support Modbus ASCII communication

Hi, I've looked the source code of the library, it's structure is easy to understand, and it doesn't look hard when implementing custom function codes.

Now I want to implement Modbus ASCII communcation mode, would you give me some hint or something need to notice when I do the implementation?

I will make a pull request once the implementation is done and tested.

Thanks.

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.